[CRIU] [PATCH] mnt: tune the root mount before mounting a root yard

Andrey Vagin avagin at openvz.org
Thu Jun 11 05:40:37 PDT 2015


Otherwise the root yard can be propagated into the host mount namespace
and remain there and criu will fail, because it will not be able to
remove the roots yard.

It occures if we give a shared mount as root to "criu restore" and
criu converts it into a slave mount.

Reported-by: Cyrill Gorcunov <gorcunov at openvz.org>
Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/mount.c b/mount.c
index be00daf..a111ffd 100644
--- a/mount.c
+++ b/mount.c
@@ -1984,8 +1984,6 @@ static int do_mount_root(struct mount_info *mi)
 						mi->shared_id, mi->master_id))
 		return -1;
 
-	mi->mounted = true;
-
 	return 0;
 }
 
@@ -2003,9 +2001,11 @@ static int do_mount_one(struct mount_info *mi)
 
 	pr_debug("\tMounting %s @%s (%d)\n", mi->fstype->name, mi->mountpoint, mi->need_plugin);
 
-	if (!mi->parent)
-		ret = do_mount_root(mi);
-	else if (!mi->bind && !mi->need_plugin && !mi->external)
+	if (!mi->parent) {
+		/* do_mount_root() is called from populate_mnt_ns() */
+		mi->mounted = true;
+		ret = 0;
+	} else if (!mi->bind && !mi->need_plugin && !mi->external)
 		ret = do_new_mount(mi);
 	else
 		ret = do_bind_mount(mi);
@@ -2481,9 +2481,6 @@ static int populate_mnt_ns(struct mount_info *mis)
 	struct mount_info *pms;
 	struct ns_id *nsid;
 
-	if (prepare_roots_yard())
-		return -1;
-
 	pms = mnt_build_tree(mis);
 	if (!pms)
 		return -1;
@@ -2506,6 +2503,17 @@ static int populate_mnt_ns(struct mount_info *mis)
 	if (validate_mounts(mis, false))
 		return -1;
 
+	/*
+	 * Set properties for the root before mounting a root yard,
+	 * otherwise the root yard can be propagated into the host
+	 * mntns and remain there.
+	 */
+	if (do_mount_root(pms))
+		return -1;
+
+	if (prepare_roots_yard())
+		return -1;
+
 	return mnt_tree_for_each(pms, do_mount_one);
 }
 
-- 
2.1.0



More information about the CRIU mailing list