From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477769; b=dA6QaIVKTBUcAIPHZErp7qqs4x+ARscx2SEFflegWLFwC4fEpVIpkAcwxfCqGT0IDmWD 9ak8Lp07JOoSKuQgUe/qY6WAknYeWYQPK8snKg8Ooa8dSKwSrNd3aVSQfvubfOro0jFAy N9zMlf6wVCktjIfaEw/fW65khAmF0l2tNMHa7KTJFeVT+Pux4t2qyKjfyZC37wTWLRrKe Ougs0L97UC4TIc3rqfhePNW7BJ3VDhps00o7pLDn0KES87PAGtD6za+BWkCLPATp5iN34 pte/T/5jx2sebfebBTPi5xovm/SpgzyeonBYAphDccwyfRH4GAY6FjkZ6rSC4g3Qq7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796477769; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Qs82HjsEYfci6HYU4slJh62ZTQbj/ed1ofApjW0SQoc=; b=BWzpAFB67qsVUexeHHsDPlrvTCadwHX6tox9pnFxd++XSYf2xL84g6fLa8B5/fbNBSTZ K7d7gydzMLceO+vcFsF6nAM+rKITkCY54LIGHgpt8wNbenlqe4cLxLDTKZVIm66oklMXx G5159+lasGa33CpDIf3ni5x1d/HhwG5nmlkgc5RxoZ5bMZ8XDdPpw2DzI/qxC+2cZmPca Hf67QwO8O4HXdd6TrPieEg58rc/tOJOcZATgUrbYjMoWqtIa7ITG8gbv+wc27ATuTMWQ+ BXUPB82JKucJSA2LiMCNttUD5BtMZUisC7ATwd36fEaRF4T/Nt7WllVz2OK9KIf8POQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CSL3lAe8; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0DF49606A322; Sat, 5 Dec 2026 13:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CSL3lAe8 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B78A11F00936; Sat, 5 Dec 2026 13:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796477768; bh=Qs82HjsEYfci6HYU4slJh62ZTQbj/ed1ofApjW0SQoc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=CSL3lAe8MRrv5Jn/vP5pCa8Ax5912uIIZ8aYhZL9bavaEOYAE9zQH17g3TyqeQAOy zeWPk3PwQ+BhuHJClhA6ZotvRHzSBeckqJ1ROp1ldhY09PGbe0sxmDfXvjEo3zVYXV zXUzgOylOsR9E0VfPQvfKy04MRErEH5gLIsLG+UQwHtWNo7+RhIhHVotIhR+lqCm4L 8ERXf5aQ51QnhHSylhyIqXbBM5gpqkFrrIakazXKZKJY/Hl3sn179Z6BF/qtLh1whS QEPyEVSNgFBp5nwX/11PHIkJ+upPNMLRKmRH10GpcvEMNw9dkTOvG9X3xz5PE2vUJ1 5GMq4OBCN9oLQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 3/8] exit: reset a released task's parent and leader Reply-To: sashiko-reviews@lists.linux.dev To: "Chris Mason" , brauner@kernel.org, oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org Cc: akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, kees@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, bsingharora@gmail.com, eddyz87@gmail.com, memxor@gmail.com, yonghong.song@linux.dev, martin.lau@linux.dev, song@kernel.org, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, sched-ext@lists.linux.dev, linux-mm@kvack.org In-Reply-To: <20261204233428.14861-4-mason@kernel.org> References: <20261204233428.14861-1-mason@kernel.org> <20261204233428.14861-4-mason@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 13:36:07 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] exit: reset_parent_and_leader() breaks lockless RCU real_parent walks -- commit 4d9f47097374975327e6ccb2ac8993c54f45179d Author: Chris Mason exit: reset a released task's parent and leader This commit resets real_parent and parent to init_task and group_leader to the task itself in release_task() so BPF programs holding a task reference cannot follow stale pointers after the parent or group leader is freed. > diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h > index 90ed5bc3c7afe..b30a66748af2c 100644 > --- a/include/linux/sched/task.h > +++ b/include/linux/sched/task.h > @@ -80,6 +80,17 @@ extern void fork_init(void); > =20 > extern void release_task(struct task_struct * p); > =20 > +/* > + * Nobody updates these pointers if @p isn't in the process tree, but BPF > + * programs can still follow them. So don't leave any that can go stale. > + */ > +static inline void reset_parent_and_leader(struct task_struct *p) > +{ > + RCU_INIT_POINTER(p->real_parent, &init_task); > + RCU_INIT_POINTER(p->parent, &init_task); > + WRITE_ONCE(p->group_leader, p); > +} > + > extern int copy_thread(struct task_struct *, const struct kernel_clone_a= rgs *); > =20 > extern void flush_thread(void); > diff --git a/kernel/exit.c b/kernel/exit.c > index d5e7bc2af804a..8a5985821e17d 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -288,6 +288,7 @@ void release_task(struct task_struct *p) > leader->exit_state =3D EXIT_DEAD; > } > =20 > + reset_parent_and_leader(p); > write_unlock_irq(&tasklist_lock); > proc_flush_pid(thread_pid); > put_pid(thread_pid); [Severity: High] Can resetting p->real_parent to &init_task in release_task() before an RCU grace period elapses break concurrent lockless RCU ancestor walks? CPU0 (task M exiting) CPU1 (RCU walk from child C) rcu_read_lock() t =3D rcu_dereference(C->real_parent) exit_notify() forget_original_parent(M) release_task(M) reset_parent_and_leader(M) M->real_parent =3D &init_task t =3D rcu_dereference(M->real_parent) <-- jumps to init_task, skips A When M is autoreaped (for example with SIG_IGN on SIGCHLD), exit_notify() reparents C to ancestor A via forget_original_parent() and immediately calls release_task(M). A concurrent RCU reader that already loaded M then jumps to init_task and skips A and all higher ancestors. An unprivileged process inside a monitored subtree can repeatedly trigger this fork/exit race to bypass a BPF LSM ancestor-deny policy. In-tree, task_is_descendant() in security/yama/yama_lsm.c terminates early at init_task and spuriously fails PTRACE_ATTACH with -EPERM. The commit message also misses nfs_access_login_time() in fs/nfs/dir.c, which walks real_parent locklessly under RCU: fs/nfs/dir.c:nfs_access_login_time() { for (;;) { parent =3D rcu_dereference(task->real_parent); pcred =3D __task_cred(parent); if (parent =3D=3D task || cred_fscmp(pcred, cred) !=3D 0) break; task =3D parent; } ret =3D task->start_time; Jumping to init_task stops the walk early for non-root credentials (spurious cache invalidation). For root credentials under a non-root ancestor, it matches init_cred and returns init_task.start_time (0), allowing stale pre-session cached access entries to be reused. In-tree walkers could detect stepping onto init_task from a !pid_alive() task and restart from the live starting task, whose real_parent was already reparented before release_task() ran. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204233428.1486= 1-1-mason@kernel.org?part=3D3