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=1796487083; b=FKD+IY02epPLfvMyhtezSPVlRRnaVR1injFi+81nYTPE6+3kDCRoIdFRUiRD7FH9RAoy 0whVSq/eGWKBgg9KFbtxmgw0PvtztfqigjKT7P7Jznm7wZKSv4fRuq61HutA/6gM8tnyn FJFN/GeX/WWN0blpETsselY4YS3cJsHSUQQ9iqK2QrXIwk6H/aUcWlTO62nW8Pp6vg46I YBrmy1aioU6F1RQRXr5GtYqgCNqzT/MjUJOBwcMB2BEP0rZbE16Uex9sMubOC91pF6pTV fHGQEGzFzc3whoPlH7UD7ioWqdvtSRa5vSpcp5sDGi4gGgJ6PpYp6Dzs5VJN8i9zimQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796487083; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=n99iZJi542Q81XAmQSW83VQhFSv1VgLwEJeqiG+kTrs=; b=CmN4a0l3RVF7x/UobprNlKFRD+Y6cpKfN11V/Js20c9f/x8eWgtiUSfX9Ro7g6qFH2Q7 Qo5VVYe52WTX7O6/I+fbe8UTvh+gVpSjIfhWLnMb1ZKxMZdJlxIxpuB6DdPZJnzAoE1KE KaouiYWfTc264Yv4lyRQobKKGP6+iRVwSyQn7VqPjF3f2Ogrs8HrAkj17RTi+LntW7S1s g1nLFxuSwcT0GmwlkyiRxvkgLRpWsSbjbnRxj2ENc5lYolf8EhGIjWnJpY6hLriRQWrsT +xtGH7ze8P0uwQOtWztsLw08WNKnzbffi3Tfxt1oRrA1FQyvmaiqgp8qa1pFHd5GDXA== 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=A6KcGEYc; 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 8FE0D606A31F; Sat, 5 Dec 2026 16:11:23 +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=A6KcGEYc Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3033C1F0092B; Sat, 5 Dec 2026 16:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796487083; bh=n99iZJi542Q81XAmQSW83VQhFSv1VgLwEJeqiG+kTrs=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=A6KcGEYckP24tr8aoujS3lzn96TetdNZrjKJMuqCXvf9K0CGXkHkdfoBAPNWg6LSK MusbSKliVcsD4KkohVNfgwrrJd7YxN0gUgAgejm+6cowTupW5DBT+U2Fc8Ypr5bZaB +5T80a09jt3f5UW2jbyVyLRcXIMXA4yxWEQbrOUI+87uWdSaCIqJfspXJFQsVan2HM Y8OH8lDS/Y0hoA8qcXA81FKMXSu4ERjQXQWCH0JErWr2IJzS7GLvI14Py90ERRQuLA 5ihcXIKBH6wSRuqlLdxbcVUj/8vpW3MrCAphkrv6T7SxjsShWbJyv8nOxDvl0AHhgZ Oaf8jAdLl+O9Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] change next_thread() to use list_next_entry_circular() Reply-To: sashiko-reviews@lists.linux.dev To: "Oleg Nesterov" , "Chris Mason" , "Nickolai Zeldovich" Cc: brauner@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, "Felix Kuehling" , amd-gfx@lists.freedesktop.org, 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: References: <20261204233428.14861-1-mason@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 16:11:21 +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 3 potential issues to consider: - [High] sched: next_thread() breaks RCU safety for check_unsafe_exec() - [Low] sched: stale RCU comment on while_each_thread() and next_thread() contract - [Low] sched: draft commit message omits motivation and leaves unresolved TODO -- commit 5d7200288affdf6e7f5d672b39ae192f8fe342d0 Author: Oleg Nesterov > change next_thread() to use list_next_entry_circular() > > Not for inclusion yet. I need to recheck and write a better changelog. > Plus see TODO below. Just to get a review from sashiko at least ;) > > The only problem is that list_next_entry_circular() expects > signal->thread_head to be not empty, and as Nickolai Zeldovich > pointed out this is not necessarily true in cgroup code if "leader" > was already reaped. So change cgroup.c to use for_each_thread(). > > TODO: we actually need an list_next_entry_circular_rcu() which we > don't have yet. > > Signed-off-by: Oleg Nesterov [Severity: Low] Aside from the draft note and unresolved TODO, the changelog does not explain why next_thread() is being changed from __next_thread(p) ?: p->group_leader to circular traversal of signal->thread_head. Before inclusion, the commit message should describe the motivation for the change and the updated locking and non-empty thread_head requirements. > diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h > index 0adb51ab15428..85c71db615e3e 100644 > --- a/include/linux/sched/signal.h > +++ b/include/linux/sched/signal.h > @@ -764,7 +764,7 @@ static inline struct task_struct *__next_thread(struc= t task_struct *p) > =20 > static inline struct task_struct *next_thread(struct task_struct *p) > { > - return __next_thread(p) ?: p->group_leader; > + return list_next_entry_circular(p, &p->signal->thread_head, thread_node= ); > } > =20 > static inline int thread_group_empty(struct task_struct *p) [Severity: High] Does replacing __next_thread() with list_next_entry_circular() break RCU-only traversal in check_unsafe_exec()? check_unsafe_exec() in fs/exec.c calls for_other_threads(p, t) under rcu_read_lock() alone, without tasklist_lock or sighand->siglock. Unlike list_next_or_null_rcu(), list_next_entry_circular() reads pos->thread_node.next twice with plain loads in list_is_last() and list_next_entry(), and reads head->next plainly in list_first_entry(). If the compiler reloads p->thread_node.next between list_is_last() and list_next_entry() while a tail sibling t2 is concurrently reaped, next_thread() applies container_of() to &sig->thread_head: CPU0 CPU1 check_unsafe_exec() rcu_read_lock() for_other_threads(p, t) next_thread(p) list_is_last(...) reads &t2->thread_node release_task(t2) ... __unhash_process() list_del_rcu(&t2->thread_node) list_next_entry(...) reloads &sig->thread_head <-- bogus task_struct pointer if (t->fs =3D=3D p->fs) <-- out-of-bounds read An unprivileged user running execve() in a multi-threaded process while a sibling exits can hit an out-of-bounds read on t->fs and an Oops or infinite loop on the next next_thread(t). Even without a reload, the plain loads race under KCSAN against list_add_tail_rcu() in copy_process() and list_del_rcu() in __unhash_process(), and drop RCU address-dependency ordering. Adding a single-load list_next_entry_circular_rcu() helper avoids this, or check_unsafe_exec() (the only RCU-only caller) can initialize n_fs =3D 0 and use for_each_thread(p, t) instead. [Severity: Low] Should the comment above while_each_thread() in include/linux/sched/signal.h be updated to match the new contract? It currently states that without tasklist_lock or siglock, while_each_thread(g, t) is RCU-safe as long as g cannot exit or exec, which no longer holds with list_next_entry_circular(). The new requirement that p->signal->thread_head must be non-empty is also undocumented on next_thread() and while_each_thread(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/axQ02FJTsnV-P6jA@re= dhat.com?part=3D1