[CRIU] [PATCH 2/2] ns: Do not reuse PROC_SELF after CLONE_VM child
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Mar 22 03:26:27 PDT 2017
Child opens PROC_SELF, populates open_proc_self_pid and exits. If parent creates
one more child with the same pid later, the new child will try to reuse PROC_SELF,
set by exited child. So, close PROC_SELF after the first child has finished.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
criu/namespaces.c | 7 +++++++
criu/net.c | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/criu/namespaces.c b/criu/namespaces.c
index 77308ccb6..819c75dd5 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1039,8 +1039,15 @@ int collect_user_ns(struct ns_id *ns, void *oarg)
}
if (waitpid(pid, &status, 0) != pid) {
pr_perror("Unable to wait the %d process", pid);
+ close_pid_proc();
return -1;
}
+ /*
+ * Child opened PROC_SELF for pid. If we create one more child
+ * with the same pid later, it will try to reuse this /proc/self.
+ */
+ close_pid_proc();
+
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
pr_err("Can't dump nested user_ns: %x\n", status);
return -1;
diff --git a/criu/net.c b/criu/net.c
index ae07ff247..3afdd5a90 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -1788,14 +1788,18 @@ int prepare_net_namespaces()
errno = 0;
if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status) || WEXITSTATUS(status)) {
pr_err("Child waiting: errno=%d, status=%d\n", errno, status);
+ close_pid_proc();
goto err;
}
+ /*
+ * Child opened PROC_SELF for pid. If we create one more child
+ * with the same pid later, it will try to reuse this PROC_SELF.
+ */
+ close_pid_proc();
} else {
if (do_create_net_ns(nsid))
goto err;
-
}
-
}
close_service_fd(NS_FD_OFF);
More information about the CRIU
mailing list