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=1796329902; b=eC8TxYfSCZAgYndF1/99veOdibW5DS9kGf/tGAETsyJnrA7qL8idtHL39evC28Dq0i+8 kYsDP3P51KeKGCjUn77x4nfPYuzyAS7cp/KNbZrTA968InlwxmdRq7EnfHZbZMpkNOMLY E7hd/G4RIuwnrCNQiY8QranuHgP0bc6SDEX/EtnC+SNDpHNi4k19M2hecJCJVqsMu5FZ7 2exqq2TQUH9JK9UFscwUmsEvfTJ6j0ufWwWxK0Qs1BGBbeXV9gSi/47HgIhUQI0kPZFMK 252t+tk96AQzQ9r5Un7NrVCduxeCkwfbyedCHhUatIMtoc52hQg0lfw+FFTUATiZs/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796329902; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=f4XJnG+KlzmtBIK48haCYl/dp1rtRRGv68+FLCxbvdk=; b=WHBf+d4OYBA2vn8qbN/DmQhAvzaSoh7AMWU2S8PeQYslT8Fs4+xgrp0627T9nsIpmrFQ O8a1KJp41HMRlypCqCGKbIk9J65t5vXwzS3QRJKS/t8ve0W0Gb7Hd99owtPaEbRQMlkna eC29yag79DRDbZCWnJ9ETabSleU+KgmnQzik4K3esHP9ak43xXT2ciWBhuSBGPrfJDu5n 6HoYN/RKN2I5p6hB5zn7JO3M5icqklRvqqYbR0uAuQh5UAt47YO40LDmmJK9OSGWD/0yo Pn/AChpXPiDX6r7dRmMbqncKveY06pZAYME72A/o0XfxN2KnWr8WurITDNnucWHg/Lw== 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=G8D28skE; 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 33663606A32C; Thu, 3 Dec 2026 20:31:41 +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=G8D28skE Received: by smtp.kernel.org (Postfix) with ESMTPSA id A86401F000CE; Thu, 3 Dec 2026 20:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796329901; bh=f4XJnG+KlzmtBIK48haCYl/dp1rtRRGv68+FLCxbvdk=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=G8D28skEfQHmbwJv8TQCdqZIBlx6XqbDCx2MKtd7k4yE1SUJH7jfAfBAnszYC76ga bApXu6AB3UlsBk4vSs7tkQFbrb4Tj62hqP5CQgrl25lYbZuFXpAdJLueYKMuOLN2Kj Wi+T0NKjKf6Xig+iBKbXguCQLKc3A1sJH98xD1yk906mjEYeffBuj1ZggLefaH+sAR TMscbN61zrgNBgsTfQf++gWySBiS7OuRvU6dp+KzBI8pws8rNX0CzGCVXMdCGeOL8s 6RYmtWUWk9Wl0lVgfvuzqm/KZNt6WpcC9SG8Ny+ofQ65UnT0n8CmwS5dusqYh2KgHM rw0Tq74Ey72zA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/3] exit: don't leave stale parent and leader pointers Reply-To: sashiko-reviews@lists.linux.dev To: "Chris Mason" , bpf@vger.kernel.org Cc: sched-ext@lists.linux.dev In-Reply-To: <20261203200612.26376-3-mason@kernel.org> References: <20261203200612.26376-1-mason@kernel.org> <20261203200612.26376-3-mason@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 20:31:41 +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 4 potential issues to consider: - [Medium] exit: plain store to p->group_leader in release_task() races with RCU readers - [Medium] exit: leader pinning creates refcount cycle with BPF task storage kptr - [Medium] exit: release_task() bounces leader cacheline 0 via usage refcount - [Low] exit: unlocked notify_count read in release_task() races with unmarked writers -- commit 6d90216e0968878272ede88e228cf18f77903929 Author: Chris Mason exit: don't leave stale parent and leader pointers This commit resets real_parent and parent to init_task in release_task() and pins a released sub-thread's group_leader until __put_task_struct() so BPF programs holding a reference to a released task cannot follow dangling pointers. > diff --git a/kernel/exit.c b/kernel/exit.c > index d5e7bc2af804a..74d7a93355cbc 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c [ ... ] > @@ -262,6 +263,17 @@ void release_task(struct task_struct *p) > */ > thread_pid =3D get_pid(task_pid(p)); > =20 > + /* > + * A released thread pins its leader, which lockless next_thread() > + * needs. Until @p is released its leader can neither change nor go > + * away. notify_count < 0 means mt-exec: @p is the old leader, and > + * must not pin the new one, or repeated execs could build a chain. > + */ > + leader =3D p->group_leader; > + pin_leader =3D leader !=3D p && READ_ONCE(p->signal->notify_count) >=3D= 0; > + if (pin_leader) > + get_task_struct(leader); > + [Severity: Low] Does this unlocked READ_ONCE(p->signal->notify_count) race with unmarked writers to sig->notify_count? Because release_task() reads notify_count before taking tasklist_lock and without sighand->siglock, it can run concurrently with plain stores in de_thread() (under siglock or read_lock(&tasklist_lock)) and unmarked decrements in __exit_signal() (under tasklist_lock and siglock). That triggers KCSAN data-race warnings during concurrent multi-threaded execve() and sub-thread exits. Moving the pin_leader check into __exit_signal() under sighand->siglock, or annotating the writers with WRITE_ONCE(), would avoid the data race. [Severity: Medium] Does calling get_task_struct(leader) on every non-leader thread exit introduce unnecessary cacheline 0 false sharing on the thread group leader? Together with put_task_struct(tsk->group_leader) in __put_task_struct(), every exiting sub-thread now performs two atomic updates to leader->usage, even when no BPF programs are loaded. In struct task_struct, usage sits in cacheline 0 alongside thread_info, __state, stack, and flags, so frequent short-lived worker exits (such as thread pools or io-wq workers) bounce the active leader's hottest cacheline across CPUs and contend on leader->usage during mass thread teardown. Only check_unsafe_exec() and cgroup_migrate()/cgroup_attach_task() walk threads with next_thread() locklessly; converting those two sites to for_each_thread() would allow release_task() to set p->group_leader =3D p unconditionally without touching leader->usage. [ ... ] > @@ -288,6 +299,15 @@ void release_task(struct task_struct *p) > leader->exit_state =3D EXIT_DEAD; > } > =20 > + /* > + * @p is off its lists, so nobody can update these pointers any more, > + * but they have to stay valid for whoever holds a reference to @p. > + */ > + RCU_INIT_POINTER(p->real_parent, &init_task); > + RCU_INIT_POINTER(p->parent, &init_task); > + if (!pin_leader) > + p->group_leader =3D p; > + > write_unlock_irq(&tasklist_lock); [Severity: Medium] Can this unmarked store to p->group_leader race with lockless RCU readers? BPF programs (via BTF_TYPE_SAFE_RCU), task_is_descendant(), and next_thread() read group_leader under RCU without holding tasklist_lock. During multi-threaded execve(), de_thread() sets leader->group_leader =3D t= sk and then calls release_task(leader), where pin_leader is false, so this plain assignment mutates p->group_leader concurrently with RCU readers, triggering KCSAN warnings and permitting store tearing. On every normal leader exit, leader =3D=3D p also leaves pin_leader false and performs a redundant plain write even though p->group_leader is already p. Guarding the assignment with if (!pin_leader && leader !=3D p) and using WRITE_ONCE(p->group_leader, p) would eliminate both the data race and the redundant store. > diff --git a/kernel/fork.c b/kernel/fork.c > index 3734aaa717130..fbad2637d89d0 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -793,6 +793,9 @@ void __put_task_struct(struct task_struct *tsk) > exit_creds(tsk); > delayacct_tsk_free(tsk); > put_signal_struct(tsk->signal); > + /* release_task() has pinned the leader of a thread */ > + if (tsk->group_leader !=3D tsk) > + put_task_struct(tsk->group_leader); > sched_core_free(tsk); > free_task(tsk); > } [Severity: Medium] Can pinning the leader until __put_task_struct() form a reference-count cycle with BPF_MAP_TYPE_TASK_STORAGE? BPF task local storage allows BPF_KPTR_REF fields, so a BPF program can store a bpf_task_acquire() reference to a sub-thread T in its thread group leader L's task storage. That kptr keeps T->rcu_users >=3D 1 until free_task(L) calls bpf_task_storage_free(L). With this change, once both T and L exit, T pins L->usage until __put_task_struct(T) runs, while L's task storage prevents __put_task_struct(T) from ever running, leaking both task_structs and their shared signal_struct until the BPF map is destroyed. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203200612.2637= 6-1-mason@kernel.org?part=3D2