From a40231a0cea4ee5b84aaca1491cd6a3fca1b0c38 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Wed, 10 Jan 2018 17:01:33 +0300 Subject: [PATCH] mnt: Populate ROOT_FD_OFF This patch populates and occupies ROOT_FD_OFF fd, which guarantees it won't be reused by ordinary fds. v4: New Signed-off-by: Kirill Tkhai --- criu/cr-restore.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/criu/cr-restore.c b/criu/cr-restore.c index f9889099f..49d367e4c 100644 --- a/criu/cr-restore.c +++ b/criu/cr-restore.c @@ -512,6 +512,23 @@ static int setup_child_task_namespaces(struct pstree_item *item, struct ns_id ** return 0; } +/* This actually populates and occupies ROOT_FD_OFF sfd */ +static int populate_root_fd_off(void) +{ + struct ns_id *mntns = NULL; + int ret; + + if (root_ns_mask & CLONE_NEWNS) { + mntns = lookup_ns_by_id(root_item->ids->mnt_ns_id, &mnt_ns_desc); + BUG_ON(!mntns); + } + + ret = mntns_get_root_fd(mntns); + if (ret < 0) + pr_err("Can't get root fd\n"); + return ret >= 0 ? 0 : -1; +} + static rt_sigaction_t sigchld_act; /* * If parent's sigaction has blocked SIGKILL (which is non-sence), @@ -1863,6 +1880,9 @@ static int restore_task_with_children(void *_arg) if (root_prepare_shared()) goto err; + + if (populate_root_fd_off()) + goto err; } if ((ca->clone_flags & CLONE_NEWPID) && setup_current_pid_ns())