[CRIU] [PATCH v1 09/17] user_ns: Load UsernsEntry mappings on restore

Kirill Tkhai ktkhai at virtuozzo.com
Thu Jan 12 09:53:38 PST 2017


Load mapping between NS_OTHER namespaces and their parents.

Also, this commit fixes the problem, which existed before my patchset.
We do not populate userns_entry on restore, though it's need and used
at least by the chain prepare_mnt_ns()->sb_opt_cb()->userns_uid().

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/namespaces.h |    1 +
 criu/namespaces.c         |   29 +++++++++++++++++++++++++++--
 criu/pstree.c             |    5 +++++
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/criu/include/namespaces.h b/criu/include/namespaces.h
index f89ef22ba..e033e55c7 100644
--- a/criu/include/namespaces.h
+++ b/criu/include/namespaces.h
@@ -154,6 +154,7 @@ extern struct ns_id *lookup_ns_by_id(unsigned int id, struct ns_desc *nd);
 extern int populate_ns_hierarhy(void);
 
 extern int collect_user_namespaces(bool for_dump);
+extern int read_user_ns_imgs(void);
 extern int prepare_userns(struct pstree_item *item);
 extern int stop_usernsd(void);
 
diff --git a/criu/namespaces.c b/criu/namespaces.c
index c33746413..24dafe84b 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1560,19 +1560,41 @@ int stop_usernsd(void)
 	return ret;
 }
 
-int prepare_userns(struct pstree_item *item)
+static int do_read_user_ns_img(struct ns_id *ns, void *arg)
 {
 	struct cr_img *img;
 	UsernsEntry *e;
 	int ret;
 
-	img = open_image(CR_FD_USERNS, O_RSTR, item->ids->user_ns_id);
+	img = open_image(CR_FD_USERNS, O_RSTR, ns->id);
 	if (!img)
 		return -1;
 	ret = pb_read_one(img, &e, PB_USERNS);
 	close_image(img);
 	if (ret < 0)
 		return -1;
+	ns->user.e = e;
+	if (ns->type == NS_ROOT)
+		userns_entry = e;
+
+	return 0;
+}
+
+int read_user_ns_imgs(void)
+{
+	int ret;
+
+	if (!(root_ns_mask & CLONE_NEWUSER))
+		return 0;
+
+	ret = walk_namespaces(&user_ns_desc, do_read_user_ns_img, NULL);
+
+	return ret;
+}
+
+int prepare_userns(struct pstree_item *item)
+{
+	UsernsEntry *e = userns_entry;
 
 	if (write_id_map(item->pid.real, e->uid_map, e->n_uid_map, "uid_map"))
 		return -1;
@@ -1792,6 +1814,9 @@ int prepare_namespace_before_tasks(void)
 	if (mntns_maybe_create_roots())
 		goto err_mnt;
 
+	if (read_user_ns_imgs())
+		goto err_img;
+
 	if (read_mnt_ns_img())
 		goto err_img;
 
diff --git a/criu/pstree.c b/criu/pstree.c
index 8eeea947c..bc66a9eff 100644
--- a/criu/pstree.c
+++ b/criu/pstree.c
@@ -471,6 +471,11 @@ static int read_pstree_ids(struct pstree_item *pi)
 			return -1;
 	}
 
+	if (pi->ids->has_user_ns_id) {
+		if (rst_add_ns_id(pi->ids->user_ns_id, pi, &user_ns_desc))
+			return -1;
+	}
+
 	return 0;
 }
 



More information about the CRIU mailing list