[CRIU] [PATCH] restore: use /proc/self/mountinfo for collecting mounts fo the root task

Andrey Vagin avagin at openvz.org
Fri Aug 8 03:33:01 PDT 2014


If the root task is forked in a new pidns, it can't use its pid for
accessing /proc, because this proc belongs to the source pidns.

v2: don't copy a static string.

Reported-by: Tycho Andersen <tycho.andersen at canonical.com>
Cc: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c      | 2 +-
 proc_parse.c | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/mount.c b/mount.c
index e0e88ea..3287282 100644
--- a/mount.c
+++ b/mount.c
@@ -1911,7 +1911,7 @@ int prepare_mnt_ns(void)
 {
 	int ret = -1;
 	struct mount_info *mis, *old;
-	struct ns_id ns = { .pid = getpid(), .nd = &mnt_ns_desc };
+	struct ns_id ns = { .pid = PROC_SELF, .nd = &mnt_ns_desc };
 
 	if (!(root_ns_mask & CLONE_NEWNS))
 		return rst_collect_local_mntns();
diff --git a/proc_parse.c b/proc_parse.c
index 66a1e12..efd7119 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -944,8 +944,12 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
 	FILE *f;
 	char str[1024];
 
-	snprintf(str, sizeof(str), "/proc/%d/mountinfo", pid);
-	f = fopen(str, "r");
+	if (pid == PROC_SELF)
+		f = fopen("/proc/self/mountinfo", "r");
+	else {
+		snprintf(str, sizeof(str), "/proc/%d/mountinfo", pid);
+		f = fopen(str, "r");
+	}
 	if (!f) {
 		pr_perror("Can't open %d mountinfo", pid);
 		return NULL;
-- 
1.9.3



More information about the CRIU mailing list