From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795180731; b=uWI9e+DDggnz2XPR8RhWsUwfZ2iaxxl8PzQPdQ8BjytaPMTgnhY/dxMiDbOBrOPhn9ZJ 6+W2fsSb30y9+9AQNB83aOLpAf9a0+nj2tKevqOrpHmZL79sGRihUq160HLg5jkXQIVym GGgjXKEU04JoqFlhLx30YjfoQNJY6CCqucGSu2sEIP1B4fE7+Jn6lyP4cp/2wEYejVIll w1WmdKmSq0p5XKTImZNhiDEf71Lb35xYs9E6XrKaEDH5idftLcKb0bdElGGwV0CNabf7p YObTGmw/ECjZY376ZStE2zBv5MzlAwxzfOKoA/C4nYsscxDYaM/8uy8YWWk752PeFFw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795180731; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=YAQTVNIYZ/0Tbx2obltQhn42YTPBHmmwY733kBIibzM=; b=4xiCP4Q86qakYpxVqydA0bXPrvkw3vua35GD6aY01rFztraBIh7vo0TV1m9oxD+wVkLn 9BB9cWlubI1G5mlxP5vPpl5X2YPCASD7f+6l9RefEIVV7J9HWzCCiZE/WaX3bRiEp7V4R NABWo09pzV7qZ12xhr+nhnqe46yyyDlrSe2IWLqHzhSmDn2WB3XY+c3VtbvlYTj+ji8d8 AxtZfhvmk0Ckd1aIAXeOfC+7NdODN8EM8Uoebz5EXWvImPcYbF44EEeL4nm8zS7wKp+Ws LjQmSVqqjg5fPEcJs9WZF6aNEnVO2MhwOxn7DyyZInsXXFcUaxjc1vTCyFFx1LXwSZg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=amutable.com; spf=pass smtp.mailfrom=amutable.com; dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b="UI/9rv+D"; arc=none smtp.remote-ip=209.85.218.45 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2217C606A326 for ; Fri, 20 Nov 2026 13:18:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2217C606A326 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=amutable.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amutable.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=UI/9rv+D Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-c513a854320so160218766b.0 for ; Fri, 20 Nov 2026 05:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amutable-com.20260707.gappssmtp.com; s=20260707; t=1795180728; x=1795785528; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=YAQTVNIYZ/0Tbx2obltQhn42YTPBHmmwY733kBIibzM=; b=UI/9rv+DZdDezz6z4q5V4bbLRvq2PUwTXKvmGLgkStPFRG3MFzpLEzZUOMicEVzjqv h9WskxL6pQRjVp6LW7wNLul6TdE5DMEMvMtKHVto1kDWUtXl4YZysNnP5izuUm6Wyf00 02kOc+/ogItTG9aLvdGftl8BuwMr3ddEGZP8CscGYWnM7MnxJ1gdPDJRCMKsqAHhAduA 5fYf+0m8yQ6qc78NG4siN795mYwXAc6BQzyhcrtUI3sLGXErAQdCZNzpNCRSgoDhZ53Q BTlXcoGhXILqja8hQmBbLSiQNTaIckFhQCA59sphyqAh5AgpCytcMtf2fggUT1oBCS51 FT4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795180728; x=1795785528; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YAQTVNIYZ/0Tbx2obltQhn42YTPBHmmwY733kBIibzM=; b=RRdTaT0eLIlbQs0uhcyZu36Wa4ljhX4IYBPL/bgGuXwQo0QTir2udjw2rWi2x68uDd GfoDasQZcvr1KVEd6+dWns+URYMByHd/COev5654A21kbSMMS7AzzgHh31pWnacBQKoJ J+uYjpx37h8f+Zba6l0BU0elsdWkgHwCLXuq8gWBWMza4GoXHbigbTD7ibrpZqNq3g1o 7D2sWuNPfKbRdQzOZfYDeeKruoQWhPuN9Uqb+oLn+I/JHZx4rCcnvvPDXkQWTuUKuW8B c7ahvua1X8QcpHNksbvLa2tR9yFQknxBlD/1zTU1Gajt2/3cDqV28eo01rb5BEAUn/6c rszw== X-Forwarded-Encrypted: i=1; AL+hErGWfxykA1IohaOuKK5vE1tpakvsJmf8N9e3j/JadSH+CKMQlHmlgRBbjTy0mpyCUMJtoVb+H+o/jdY3dy9BbV9/hKSoGaI=@vger.kernel.org X-Gm-Message-State: APuU4Z9AntF3iLcFmzcWQ407wgbU7g5s5cYa1DzXRjrLLpaWZl0lDNLw NNYI0VbKwMqZwWI0yGJAqABYHu0dmljvzFwarY8z0muGUgSfmPhXgEa4X2OHMdFU5OZG X-Gm-Gg: AYBFou0qxziiXbinoB1BP/7NlkrO33fcHVHg0h11Igc5k00yWLFhjenwqNc3udCJYxw LSnFSPv8++EjNPsKVT/GRCRMQu6HrLCnHHailQ9IGdu5v2JC1OyztoDrEh07nQFUefnV4plODUS vYvDYhHmluPA3o+vyppKFAXTMmqlPMs1JvM9x3pcAcwKYrRydGnQj6FIA1ykc+Z3qZNbmJ9S8JD j8O9J+QTUKK5rIHX6Dwtr3xK04ywAVkdxEvLor5NR80hFGAfzj0QDYsxOUMgBglpx2ig/dylS6P TIJBNrg/YyOO19NT5yaIEKJt4wzqopWLiVQz+VJ8+SE7E8wXgc6UYxqPox3+DGKFbzBMREJEVOw dbP6uJWOBZur1FYoZfCiUPV2RChItvd6LcN9LW+t96+1Ijr2SpYuFjmgKKinxBBu1UWGeLGTLDg UsD0jm9DO+/DyT9HDGHeqyesEZlZVB9dkShabCmRbNRnm4hONoz/VIa2NP3bek0jpV1c5QqsEmi prmll+HW+9XcDt85/6P8yAUbTcyiB5bFBPuvKT9qBm/J8c7goG5AKHgz204OinWI1I7GSOm1LaM V8Oxbs5ARDBKOC3/5WpwDkFiVS51Euu1fstPWBuRxHaJPv00DI0hVmDxs6qtiDr1Uw== X-Received: by 2002:a17:907:a890:b0:c41:55b4:d88b with SMTP id a640c23a62f3a-c513ab14402mr338807466b.43.1795180728386; Fri, 20 Nov 2026 05:18:48 -0800 (PST) Received: from [10.0.0.233] (tmo-084-188.customers.d1-online.com. [80.187.84.188]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513acfe3b0sm93731066b.8.2026.11.20.05.18.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2026 05:18:47 -0800 (PST) Message-ID: Subject: Re: [RFC PATCH v4 03/14] rootns: Track init lifecycle via copy_process() and pid_namespace From: Alexander Mikhalitsyn To: Jarkko Sakkinen , linux-fsdevel@vger.kernel.org Cc: linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Albert Ou , Alexander Gordeev , Alexander Viro , Alexandre Ghiti , Andreas Larsson , Andrew Morton , Andy Lutomirski , Andy Lutomirski , Anna-Maria Behnsen , Arnd Bergmann , Ben Segall , Borislav Petkov , Casey Schaufler , Catalin Marinas , Christian Borntraeger , Christian Brauner , "Christophe Leroy (CS GROUP)" , Chris Zankel , Dave Hansen , David Hildenbrand , David Howells , Davidlohr Bueso , "David S. Miller" , Dietmar Eggemann , Frederic Weisbecker , Geert Uytterhoeven , "Hallgrimur H. Gunnarsson" , Heiko Carstens , Helge Deller , "H. Peter Anvin" , Ingo Molnar , "James E.J. Bottomley" , Jan Kara , John Johansen , John Paul Adrian Glaubitz , Jonathan Corbet , Josef Bacik , Juri Lelli , Kees Cook , K Prateek Nayak , "Liam R. Howlett" , Lorenzo Stoakes , Madhavan Srinivasan , Magnus Lindholm , Manfred Spraul , Mark Rutland , Matt Turner , Max Filippov , Mel Gorman , Michael Ellerman , Michal Hocko , Michal Simek , Mike Rapoport , Neal Gompa , Nicholas Piggin , Palmer Dabbelt , Paul Moore , Paul Walmsley , Pavel Tikhomirov , Peter Zijlstra , Randy Dunlap , Richard Henderson , Rich Felker , "Ritesh Harjani (IBM)" , Russell King , Serge Hallyn , Shrikanth Hegde , Shuah Khan , Steven Rostedt , Suren Baghdasaryan , Sven Schnelle , Thomas Bogendoerfer , Thomas Gleixner , Valentin Schneider , Vasily Gorbik , Vincent Guittot , Vincenzo Frascino , Vlastimil Babka , Will Deacon , Yoshinori Sato , Zygmunt Krynicki Date: Fri, 20 Nov 2026 14:18:43 +0100 In-Reply-To: <20261119224312.1037966-4-jarkko@kernel.org> References: <20261119224312.1037966-1-jarkko@kernel.org> <20261119224312.1037966-4-jarkko@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-0+deb13u1 X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Fri, 2026-11-20 at 00:43 +0200, Jarkko Sakkinen wrote: > A root namespace needs to record its init thread group's PID when > bootstrapped and capture its exit status once all processes in the > root > namespace have terminated, without serializing normal fork() and > exit() > paths inside the container. >=20 > Commit the bootstrap child reaper, bind pid_ns->rootns, and wake > waiters > in copy_rootns() after attach_pid(PIDTYPE_PID), and invoke > exit_rootns() > from zap_pid_ns_processes() after the root namespace's PID namespace > has > killed and reaped all member tasks. >=20 > Co-developed-by: David Howells > Signed-off-by: David Howells > Signed-off-by: Jarkko Sakkinen > --- > =C2=A0include/linux/pid_namespace.h |=C2=A0 4 ++++ > =C2=A0include/linux/rootns.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | = 15 ++++++++++++++ > =C2=A0kernel/fork.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 3 +++ > =C2=A0kernel/pid_namespace.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= =C2=A0 2 ++ > =C2=A0kernel/rootns.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 38 > +++++++++++++++++++++++++++++++++++ > =C2=A05 files changed, 62 insertions(+) >=20 > diff --git a/include/linux/pid_namespace.h > b/include/linux/pid_namespace.h > index b20baaa7e62b..6fd959f4d0d4 100644 > --- a/include/linux/pid_namespace.h > +++ b/include/linux/pid_namespace.h > @@ -15,6 +15,7 @@ > =C2=A0#define MAX_PID_NS_LEVEL 32 > =C2=A0 > =C2=A0struct fs_pin; > +struct rootns; > =C2=A0 > =C2=A0#if defined(CONFIG_SYSCTL) && defined(CONFIG_MEMFD_CREATE) > =C2=A0/* modes for vm.memfd_noexec sysctl */ > @@ -45,6 +46,9 @@ struct pid_namespace { > =C2=A0 struct user_namespace *user_ns; > =C2=A0 struct ucounts *ucounts; > =C2=A0 int reboot; /* group exit code if this pidns was > rebooted */ > +#ifdef CONFIG_ROOTNS > + struct rootns *rootns; > +#endif > =C2=A0 struct ns_common ns; > =C2=A0 struct work_struct work; > =C2=A0} __randomize_layout; > diff --git a/include/linux/rootns.h b/include/linux/rootns.h > index 3f59415efadb..0557ce75195d 100644 > --- a/include/linux/rootns.h > +++ b/include/linux/rootns.h > @@ -13,6 +13,8 @@ > =C2=A0struct file; > =C2=A0struct nsproxy; > =C2=A0struct pid; > +struct pid_namespace; > +struct task_struct; > =C2=A0struct user_namespace; > =C2=A0 > =C2=A0enum rootns_state { > @@ -41,6 +43,9 @@ struct rootns { > =C2=A0struct rootns *get_rootns(struct rootns *c); > =C2=A0void put_rootns(struct rootns *c); > =C2=A0bool is_rootns_file(struct file *file); > +void copy_rootns(struct task_struct *tsk, struct pid *pid, > + struct rootns *rootns); > +void exit_rootns(struct pid_namespace *pid_ns, struct task_struct > *tsk); > =C2=A0#else > =C2=A0static inline struct rootns *get_rootns(struct rootns *c) > =C2=A0{ > @@ -55,6 +60,16 @@ static inline bool is_rootns_file(struct file > *file) > =C2=A0{ > =C2=A0 return false; > =C2=A0} > + > +static inline void copy_rootns(struct task_struct *tsk, struct pid > *pid, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct rootns *rootns) > +{ > +} > + > +static inline void exit_rootns(struct pid_namespace *pid_ns, > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct task_struct *tsk) > +{ > +} > =C2=A0#endif /* CONFIG_ROOTNS */ > =C2=A0 > =C2=A0#endif /* _LINUX_ROOTNS_H */ > diff --git a/kernel/fork.c b/kernel/fork.c > index 5efceb8d58a7..08fc28ad1eed 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -83,6 +83,7 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > +#include > =C2=A0#include > =C2=A0#include > =C2=A0#include > @@ -2576,6 +2577,8 @@ __latent_entropy struct task_struct > *copy_process( > =C2=A0 =C2=A0 &p->signal->thread_head); > =C2=A0 } > =C2=A0 attach_pid(p, PIDTYPE_PID); > + if (thread_group_leader(p)) > + copy_rootns(p, pid, NULL); > =C2=A0 nr_threads++; > =C2=A0 } > =C2=A0 total_forks++; > diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c > index 127a5fd23e70..081c27aa85bd 100644 > --- a/kernel/pid_namespace.c > +++ b/kernel/pid_namespace.c > @@ -24,6 +24,7 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > +#include > =C2=A0#include > =C2=A0#include "pid_sysctl.h" > =C2=A0 > @@ -280,6 +281,7 @@ void zap_pid_ns_processes(struct pid_namespace > *pid_ns) > =C2=A0 current->signal->group_exit_code =3D pid_ns->reboot; > =C2=A0 Dear Jarkko, > =C2=A0 acct_exit_ns(pid_ns); > + exit_rootns(pid_ns, me); We have a very similar mechanism around pidfd's to track exit information for a task. As far as I can see we already have (struct rootns *)->init_pid reference, so we can get exit information for free (look for PIDFD_INFO_EXIT). Kind regards, Alex > =C2=A0 return; > =C2=A0} > =C2=A0 > diff --git a/kernel/rootns.c b/kernel/rootns.c > index 3bbf7677080e..bde7cf4baebe 100644 > --- a/kernel/rootns.c > +++ b/kernel/rootns.c > @@ -183,3 +183,41 @@ bool is_rootns_file(struct file *file) > =C2=A0{ > =C2=A0 return file->f_op =3D=3D &rootns_fops; > =C2=A0} > + > +void copy_rootns(struct task_struct *tsk, struct pid *pid, struct > rootns *c) > +{ > + if (likely(!c || !is_child_reaper(pid))) > + return; > + > + scoped_guard(spinlock, &c->lock) { > + if (c->state !=3D ROOTNS_FORKING) > + return; > + ns_of_pid(pid)->rootns =3D get_rootns(c); > + WRITE_ONCE(c->init_pid, get_pid(pid)); > + WRITE_ONCE(c->state, ROOTNS_RUNNING); > + } > + wake_up_all(&c->waitq); > +} > + > +void exit_rootns(struct pid_namespace *pid_ns, struct task_struct > *tsk) > +{ > + struct rootns *c =3D pid_ns->rootns; > + struct task_struct *leader; > + int status; > + > + if (!c) > + return; > + > + leader =3D tsk->group_leader; > + status =3D (tsk->signal->flags & SIGNAL_GROUP_EXIT) ? > + tsk->signal->group_exit_code : leader->exit_code; > + > + scoped_guard(spinlock, &c->lock) { > + c->exit_code =3D status; > + WRITE_ONCE(c->state, ROOTNS_DEAD); > + } > + > + pid_ns->rootns =3D NULL; > + wake_up_poll(&c->waitq, EPOLLHUP); > + put_rootns(c); > +}