[04/21] ns: Fix forked task user_ns assignment

Submitted by Kirill Tkhai on May 23, 2017, 12:38 p.m.

Details

Message ID 149554312004.12386.2187448215290205663.stgit@localhost.localdomain
State New
Series "Add /proc/[pid]/ns/pid_for_children ns support (and fixes)"
Headers show

Commit Message

Kirill Tkhai May 23, 2017, 12:38 p.m.
Child reaper of a ns have initial user_ns equal to its pid_ns->user_ns.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 criu/cr-restore.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index 21ba39ec3..fabfb80ce 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1317,15 +1317,18 @@  static inline int fork_with_pid(struct pstree_item *item)
 	pid_t pid = vpid(item);
 	struct ns_id *pid_ns;
 
-	if (item != root_item)
-		item->user_ns = current->user_ns;
-	else
-		item->user_ns = root_user_ns;
-
 	pid_ns = lookup_ns_by_id(item->ids->pid_ns_id, &pid_ns_desc);
 	BUG_ON(!pid_ns);
 	item->pid_for_children_ns = pid_ns;
 
+	if (item != root_item) {
+		if (last_level_pid(item->pid) == INIT_PID)
+			item->user_ns = pid_ns->user_ns;
+		else
+			item->user_ns = current->user_ns;
+	} else
+		item->user_ns = root_user_ns;
+
 	if (item->pid->state != TASK_HELPER) {
 		if (open_core(pid, &ca.core))
 			return -1;