[CRIU] [PATCH v4 11/31] user_ns: Name loading UsernsEntry mappings on restore "old format"

Kirill Tkhai ktkhai at virtuozzo.com
Wed Feb 22 03:32:08 PST 2017


Split prepare_userns() in two functions.

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/namespaces.c |   38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 6f4bf01d4..9769383b7 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1651,19 +1651,48 @@ int stop_usernsd(void)
 	return ret;
 }
 
-int prepare_userns(struct pstree_item *item)
+static int do_read_old_user_ns_img(struct ns_id *ns, void *arg)
 {
+	int ret, *count = arg;
 	struct cr_img *img;
 	UsernsEntry *e;
-	int ret;
 
-	img = open_image(CR_FD_USERNS, O_RSTR, item->ids->user_ns_id);
+	if (++*count > 1) {
+		pr_err("More then one user_ns, img format can't be old\n");
+		return -1;
+	}
+
+	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;
+	userns_entry = e;
+	root_user_ns = ns;
+	return 0;
+}
+
+static int read_old_user_ns_img(void)
+{
+	int ret, count = 0;
+
+	if (!(root_ns_mask & CLONE_NEWUSER))
+		return 0;
+	/* If new format img has already been read */
+	if (root_user_ns)
+		return 0;
+	/* Old format img is only for root_user_ns. More or less is error */
+	ret = walk_namespaces(&user_ns_desc, do_read_old_user_ns_img, &count);
+
+	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;
@@ -1890,6 +1919,9 @@ int prepare_namespace_before_tasks(void)
 	if (read_mnt_ns_img())
 		goto err_img;
 
+	if (read_old_user_ns_img())
+		goto err_img;
+
 	return 0;
 
 err_img:



More information about the CRIU mailing list