Commit 20d64b43 authored by Pavel Emelyanov's avatar Pavel Emelyanov

dump: Install target ns' proc fd as service fd

Don't carry it around in a static global variable. Would
be useful for pidns leaks (processes entered one) scan.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 670e26b0
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
#include "asm/dump.h" #include "asm/dump.h"
static char loc_buf[PAGE_SIZE]; static char loc_buf[PAGE_SIZE];
static int pidns_proc = -1;
bool privately_dump_vma(struct vma_area *vma) bool privately_dump_vma(struct vma_area *vma)
{ {
...@@ -1245,7 +1244,7 @@ static int dump_zombies(void) ...@@ -1245,7 +1244,7 @@ static int dump_zombies(void)
int ret = -1; int ret = -1;
int pidns = current_ns_mask & CLONE_NEWPID; int pidns = current_ns_mask & CLONE_NEWPID;
if (pidns && set_proc_fd(pidns_proc)) if (pidns && set_proc_fd(get_service_fd(CR_PROC_FD_OFF)))
return -1; return -1;
/* /*
...@@ -1420,11 +1419,18 @@ static int dump_one_task(struct pstree_item *item) ...@@ -1420,11 +1419,18 @@ static int dump_one_task(struct pstree_item *item)
} }
if (current_ns_mask & CLONE_NEWPID && root_item == item) { if (current_ns_mask & CLONE_NEWPID && root_item == item) {
pidns_proc = parasite_get_proc_fd_seized(parasite_ctl); int pfd;
if (pidns_proc < 0) {
pfd = parasite_get_proc_fd_seized(parasite_ctl);
if (pfd < 0) {
pr_err("Can't get proc fd (pid: %d)\n", pid); pr_err("Can't get proc fd (pid: %d)\n", pid);
goto err_cure_fdset; goto err_cure_fdset;
} }
if (install_service_fd(CR_PROC_FD_OFF, pfd) < 0)
goto err_cure_fdset;
close(pfd);
} }
ret = parasite_fixup_vdso(parasite_ctl, pid, &vmas); ret = parasite_fixup_vdso(parasite_ctl, pid, &vmas);
...@@ -1764,7 +1770,7 @@ err: ...@@ -1764,7 +1770,7 @@ err:
free_pstree(root_item); free_pstree(root_item);
free_file_locks(); free_file_locks();
close_safe(&pidns_proc); close_service_fd(CR_PROC_FD_OFF);
if (ret) { if (ret) {
kill_inventory(); kill_inventory();
......
...@@ -54,11 +54,14 @@ enum sfd_type { ...@@ -54,11 +54,14 @@ enum sfd_type {
LOG_FD_OFF, LOG_FD_OFF,
LOG_DIR_FD_OFF, LOG_DIR_FD_OFF,
IMG_FD_OFF, IMG_FD_OFF,
PROC_FD_OFF, /* /proc in the restored pidns */ PROC_FD_OFF, /* fd with /proc for all proc_ calls */
CTL_TTY_OFF, CTL_TTY_OFF,
SELF_STDIN_OFF, SELF_STDIN_OFF,
PARENT_FD_OFF, PARENT_FD_OFF,
CR_PROC_FD_OFF, /* /proc in criu's pidns */ CR_PROC_FD_OFF, /* some other's proc fd.
* For dump -- target ns' proc
* For restore -- CRIU ns' proc
*/
SERVICE_FD_MAX SERVICE_FD_MAX
}; };
......
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