[CRIU] [PATCH 10/11] mount: prevent dumping mounts, if they can't be restored

Andrey Vagin avagin at openvz.org
Tue Jul 30 12:25:35 EDT 2013


Currently we check that all shared mounts have identical set of
children and that Each non-root mount has a proper root mount.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 mount.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/mount.c b/mount.c
index 6f7fc71..3e75002 100644
--- a/mount.c
+++ b/mount.c
@@ -206,6 +206,45 @@ static void mnt_tree_show(struct mount_info *tree, int off)
 	pr_info("%*s<--\n", off, "");
 }
 
+static int validate_mounts(struct mount_info *info)
+{
+	struct mount_info *m, *t;
+
+	for (m = info; m; m = m->next) {
+		if (m->parent && m->parent->shared_id) {
+			struct mount_info *ct;
+			if (list_empty(&m->parent->mnt_share))
+				continue;
+			t = list_first_entry(&m->parent->mnt_share, struct mount_info, mnt_share);
+
+			list_for_each_entry(ct, &t->children, siblings) {
+				if (mounts_equal(m, ct, false))
+					break;
+			}
+			if (&ct->siblings == &t->children) {
+				pr_err("%d:%s doesn't have a proper point for %d:%s\n",
+					t->mnt_id, t->mountpoint,
+					m->mnt_id, m->mountpoint);
+				return -1;
+			}
+		}
+
+		if (m->parent && !fsroot_mounted(m)) {
+			list_for_each_entry(t, &m->mnt_bind, mnt_bind) {
+				if (fsroot_mounted(t))
+					break;
+			}
+			if (&t->mnt_bind == &m->mnt_bind) {
+				pr_err("%d:%s doesn't have a proper root mount\n",
+					t->mnt_id, t->mountpoint);
+				return -1;
+			}
+		}
+	}
+
+	return 0;
+}
+
 static int collect_shared(struct mount_info *info)
 {
 	struct mount_info *m, *t;
@@ -612,6 +651,9 @@ int dump_mnt_ns(int ns_pid, struct cr_fdset *fdset)
 	if (mnt_build_tree(pm) == NULL)
 		return -1;
 
+	if (validate_mounts(pm))
+		return -1;
+
 	pr_info("Dumping mountpoints\n");
 
 	img_fd = fdset_fd(fdset, CR_FD_MOUNTPOINTS);
-- 
1.8.3.1



More information about the CRIU mailing list