[CRIU] [PATCH] dump: Don't dump file params with on-stack values

Cyrill Gorcunov gorcunov at openvz.org
Mon May 28 07:56:52 EDT 2012


Otherwise I see output like

 | Dumping path for 1536412160 fd via self 27 [/usr/bin/screen]

where fd is taken from stack and what is worse -- we work
with root privilegues, thus dumping _anything_ from stack
is very bad idea.

With explicitly cleared stack data and FD_DESC_INVALID the
log file will have an entry like

 | Dumping path for -3 fd via self 27 [/usr/bin/screen]

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 cr-dump.c          |   11 ++++-------
 include/file-ids.h |    1 +
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index ec22895..57841c6 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -356,7 +356,7 @@ static int dump_reg_file(struct fd_parms *p, int lfd,
 
 static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
 {
-	struct fd_parms params;
+	struct fd_parms params = { };
 	int fd, ret;
 
 	fd = open_proc(pid, "exe");
@@ -368,9 +368,7 @@ static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
 		return -1;
 	}
 
-	params.flags = 0;
-	params.pos = 0;
-	params.fown = (fown_t){ };
+	params.fd = FD_DESC_INVALID;
 	mm->exe_file_id = fd_id_generate_special();
 
 	ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
@@ -600,15 +598,14 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset)
 static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
 		const struct cr_fdset *fdset)
 {
-	struct fd_parms p;
+	struct fd_parms p = { };
 
 	if (fstat(file_fd, &p.stat) < 0) {
 		pr_perror("Can't stat file for vma");
 		return -1;
 	}
 
-	p.pos = 0;
-	p.fown = (fown_t){ };
+	p.fd = FD_DESC_INVALID;
 	if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED))
 		p.flags = O_RDWR;
 	else
diff --git a/include/file-ids.h b/include/file-ids.h
index 8af7863..8b8a41e 100644
--- a/include/file-ids.h
+++ b/include/file-ids.h
@@ -7,6 +7,7 @@
 
 #define FD_ID_INVALID		(-1U)
 #define FD_PID_INVALID		(-2U)
+#define FD_DESC_INVALID		(-3U)
 
 #define MAKE_FD_GENID(dev, ino, pos) \
 	(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
-- 
1.7.7.6



More information about the CRIU mailing list