[CRIU] [PATCH] mount: simplify mnt_build_ids_tree()
Andrei Vagin
avagin at openvz.org
Thu Feb 2 19:13:37 PST 2017
From: Andrei Vagin <avagin at virtuozzo.com>
This patch reworks this function, removes mess and fix
the next coverity issue:
394 m->parent = parent;
CID 175314 (#1 of 1): Dereference after null check (FORWARD_NULL)
27. var_deref_model: Passing null pointer &parent->children to list_add_tail, which dereferences it. [show details]
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
criu/mount.c | 63 ++++++++++++++++++++++++++++--------------------------------
1 file changed, 29 insertions(+), 34 deletions(-)
diff --git a/criu/mount.c b/criu/mount.c
index 4ba6cc2..cbbc154 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -328,7 +328,7 @@ static bool mounts_equal(struct mount_info *a, struct mount_info *b)
*/
static char *mnt_roots;
-static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mount_info *tmp_root_mount)
+static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mount_info *yard_mount)
{
struct mount_info *m, *root = NULL;
@@ -348,47 +348,42 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mou
parent = NULL;
if (!parent) {
- /* This should be / */
- if (root == NULL && (!tmp_root_mount || is_root_mount(m))) {
+ /* Only a root mount can be without parent */
+ if (root == NULL && m->is_ns_root) {
root = m;
- if (!tmp_root_mount)
+ if (!yard_mount)
continue;
}
+ if (!root) {
+ pr_err("No parent found for mountpoint %d (@%s)\n",
+ m->mnt_id, m->mountpoint);
+ return NULL;
+ }
+
pr_debug("Mountpoint %d (@%s) w/o parent %d\n",
m->mnt_id, m->mountpoint, m->parent_mnt_id);
- if (root && m->is_ns_root) {
- if (!mounts_sb_equal(root, m) ||
- strcmp(root->root, m->root)) {
- pr_err("Nested mount namespaces with different "
- "roots %d (@%s %s) %d (@%s %s) are not supported yet\n",
- root->mnt_id, root->mountpoint, root->root,
- m->mnt_id, m->mountpoint, m->root);
- return NULL;
- }
-
- /*
- * A root of a sub mount namespace is
- * mounted in a temporary directory in the
- * root mount namespace, so its parent is
- * the main root.
- */
- parent = tmp_root_mount;
- if (unlikely(!tmp_root_mount)) {
- pr_err("Nested mount %d (@%s %s) w/o root insertion detected\n",
- m->mnt_id, m->mountpoint, m->root);
- return NULL;
- }
+ if (!mounts_sb_equal(root, m) ||
+ strcmp(root->root, m->root)) {
+ pr_err("Nested mount namespaces with different "
+ "roots %d (@%s %s) %d (@%s %s) are not supported yet\n",
+ root->mnt_id, root->mountpoint, root->root,
+ m->mnt_id, m->mountpoint, m->root);
+ return NULL;
+ }
- pr_debug("Mountpoint %d (@%s) get parent %d (@%s)\n",
- m->mnt_id, m->mountpoint,
- parent->mnt_id, parent->mountpoint);
- } else if (root != m) {
- pr_err("No root found for mountpoint %d (@%s)\n",
- m->mnt_id, m->mountpoint);
+ /* Mount all namespace roots into the roots yard. */
+ parent = yard_mount;
+ if (unlikely(!yard_mount)) {
+ pr_err("Nested mount %d (@%s %s) w/o root insertion detected\n",
+ m->mnt_id, m->mountpoint, m->root);
return NULL;
}
+
+ pr_debug("Mountpoint %d (@%s) get parent %d (@%s)\n",
+ m->mnt_id, m->mountpoint,
+ parent->mnt_id, parent->mountpoint);
}
m->parent = parent;
@@ -400,8 +395,8 @@ static struct mount_info *mnt_build_ids_tree(struct mount_info *list, struct mou
return NULL;
}
- if (tmp_root_mount)
- return tmp_root_mount;
+ if (yard_mount)
+ return yard_mount;
return root;
}
--
2.7.4
More information about the CRIU
mailing list