Commit 63000f5b authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

dump: Don't dump file params with on-stack values

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 9b254657
...@@ -354,7 +354,7 @@ static int dump_reg_file(struct fd_parms *p, int lfd, ...@@ -354,7 +354,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) static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
{ {
struct fd_parms params; struct fd_parms params = { };
int fd, ret; int fd, ret;
fd = open_proc(pid, "exe"); fd = open_proc(pid, "exe");
...@@ -366,9 +366,7 @@ static int dump_task_exe_link(pid_t pid, struct mm_entry *mm) ...@@ -366,9 +366,7 @@ static int dump_task_exe_link(pid_t pid, struct mm_entry *mm)
return -1; return -1;
} }
params.flags = 0; params.fd = FD_DESC_INVALID;
params.pos = 0;
params.fown = (fown_t){ };
mm->exe_file_id = fd_id_generate_special(); mm->exe_file_id = fd_id_generate_special();
ret = dump_one_reg_file(fd, mm->exe_file_id, &params); ret = dump_one_reg_file(fd, mm->exe_file_id, &params);
...@@ -593,15 +591,14 @@ static int dump_task_fs(pid_t pid, struct cr_fdset *fdset) ...@@ -593,15 +591,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, static int dump_filemap(pid_t pid, struct vma_entry *vma, int file_fd,
const struct cr_fdset *fdset) const struct cr_fdset *fdset)
{ {
struct fd_parms p; struct fd_parms p = { };
if (fstat(file_fd, &p.stat) < 0) { if (fstat(file_fd, &p.stat) < 0) {
pr_perror("Can't stat file for vma"); pr_perror("Can't stat file for vma");
return -1; return -1;
} }
p.pos = 0; p.fd = FD_DESC_INVALID;
p.fown = (fown_t){ };
if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED)) if ((vma->prot & PROT_WRITE) && vma_entry_is(vma, VMA_FILE_SHARED))
p.flags = O_RDWR; p.flags = O_RDWR;
else else
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#define FD_ID_INVALID (-1U) #define FD_ID_INVALID (-1U)
#define FD_PID_INVALID (-2U) #define FD_PID_INVALID (-2U)
#define FD_DESC_INVALID (-3U)
#define MAKE_FD_GENID(dev, ino, pos) \ #define MAKE_FD_GENID(dev, ino, pos) \
(((u32)(dev) ^ (u32)(ino) ^ (u32)(pos))) (((u32)(dev) ^ (u32)(ino) ^ (u32)(pos)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment