mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pid_ns: support pidns switching between sibling
@ 2023-10-11  6:54 Yunhui Cui
  2023-10-11 17:22 ` Andrew Morton
  2023-10-12  3:30 ` Eric W. Biederman
  0 siblings, 2 replies; 8+ messages in thread
From: Yunhui Cui @ 2023-10-11  6:54 UTC (permalink / raw)
  To: akpm, keescook, brauner, jeffxu, frederic, mcgrof, cyphar,
	cuiyunhui, rongtao, linux-kernel

In the scenario of container acceleration, when a target pstree
is cloned from a temp pstree, we hope that the cloned process is
inherently in the target's pid namespace.
Examples of what we expected:

/* switch to target ns first. */
setns(target_ns, CLONE_NEWPID);
if(!fork()) {
/* Child */
...
}
/* switch back */
setns(temp_ns, CLONE_NEWPID);

However, it is limited by the existing implementation, CAP_SYS_ADMIN
has been checked in pidns_install(), so remove the limitation that only
by traversing parent can switch pidns.

Signed-off-by: Yunhui Cui <cuiyunhui@bytedance.com>
---
 kernel/pid_namespace.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 3028b2218aa4..774db1f268f1 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -389,7 +389,7 @@ static int pidns_install(struct nsset *nsset, struct ns_common *ns)
 {
 	struct nsproxy *nsproxy = nsset->nsproxy;
 	struct pid_namespace *active = task_active_pid_ns(current);
-	struct pid_namespace *ancestor, *new = to_pid_ns(ns);
+	struct pid_namespace *new = to_pid_ns(ns);
 
 	if (!ns_capable(new->user_ns, CAP_SYS_ADMIN) ||
 	    !ns_capable(nsset->cred->user_ns, CAP_SYS_ADMIN))
@@ -406,12 +406,6 @@ static int pidns_install(struct nsset *nsset, struct ns_common *ns)
 	if (new->level < active->level)
 		return -EINVAL;
 
-	ancestor = new;
-	while (ancestor->level > active->level)
-		ancestor = ancestor->parent;
-	if (ancestor != active)
-		return -EINVAL;
-
 	put_pid_ns(nsproxy->pid_ns_for_children);
 	nsproxy->pid_ns_for_children = get_pid_ns(new);
 	return 0;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-10-14  4:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-11  6:54 [PATCH] pid_ns: support pidns switching between sibling Yunhui Cui
2023-10-11 17:22 ` Andrew Morton
2023-10-12  3:30 ` Eric W. Biederman
2023-10-13  2:44   ` [External] " yunhui cui
2023-10-13  8:55     ` yunhui cui
2023-10-13 13:03     ` Eric W. Biederman
2023-10-14  3:41       ` yunhui cui
2023-10-14  4:21         ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®