[v2,15/36] user_ns: Name loading UsernsEntry mappings on restore "old format"

Submitted by Kirill Tkhai on Feb. 3, 2017, 4:13 p.m.

Details

Message ID 148613843044.3612.4723721048252312656.stgit@localhost.localdomain
State New
Series "Nested user namespaces support"
Headers show

Commit Message

Kirill Tkhai Feb. 3, 2017, 4:13 p.m.
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@virtuozzo.com>
---
 criu/namespaces.c |   38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/namespaces.c b/criu/namespaces.c
index 935a44c42..b64eb07b1 100644
--- a/criu/namespaces.c
+++ b/criu/namespaces.c
@@ -1637,19 +1637,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;
@@ -1876,6 +1905,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: