From: sashiko-bot@kernel.org
To: "Oleg Nesterov" <oleg@redhat.com>,
"Chris Mason" <mason@kernel.org>,
"Nickolai Zeldovich" <nickolai@csail.mit.edu>
Cc: brauner@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, bpf@vger.kernel.org,
"Felix Kuehling" <Felix.Kuehling@amd.com>,
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
Subject: Re: [PATCH] change next_thread() to use list_next_entry_circular()
Date: Sat, 05 Dec 2026 16:11:21 +0000 [thread overview]
Message-ID: <sashiko-outbox-251739@kernel.org> (raw)
In-Reply-To: <axQ02FJTsnV-P6jA@redhat.com>
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 <oleg@redhat.com>
> 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 <oleg@redhat.com>
[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(struct task_struct *p)
>
> 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);
> }
>
> 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 == 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 = 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().
--
Sashiko AI review · https://sashiko.dev/#/patchset/axQ02FJTsnV-P6jA@redhat.com?part=1
next prev parent reply other threads:[~2026-12-05 16:11 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 13:11 [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Chris Mason
2026-12-05 13:11 ` [PATCH v2 1/8] tsacct: don't dereference a stale group_leader Chris Mason
2026-12-05 13:12 ` [PATCH v2 2/8] exec, cgroup, prlimit: prepare for group_leader resets Chris Mason
2026-12-05 15:35 ` Oleg Nesterov
2026-12-05 13:12 ` [PATCH v2 3/8] exit: reset a released task's parent and leader Chris Mason
2026-12-05 13:36 ` sashiko-bot
2026-12-05 13:54 ` bot+bpf-ci
2026-12-05 13:12 ` [PATCH v2 4/8] fork: don't leave stale parent pointers in a new task Chris Mason
2026-12-05 13:12 ` [PATCH v2 5/8] bpf: Don't start a thread walk at a released task Chris Mason
2026-12-05 13:12 ` [PATCH v2 6/8] drm/amdkfd: fix crashes if a debugged process exits Chris Mason
2026-12-05 13:40 ` sashiko-bot
2026-12-05 13:13 ` [RFC PATCH v2 7/8] signal: add task_group_leader() Chris Mason
2026-12-05 15:29 ` Oleg Nesterov
2026-12-05 13:13 ` [RFC PATCH v2 8/8] signal: move group_leader into signal_struct Chris Mason
2026-12-05 13:54 ` bot+bpf-ci
2026-12-05 15:24 ` Oleg Nesterov
2026-12-05 15:59 ` [PATCH] change next_thread() to use list_next_entry_circular() Oleg Nesterov
2026-12-05 16:11 ` sashiko-bot [this message]
2026-12-05 16:19 ` Oleg Nesterov
2026-12-05 17:46 ` Chris Mason
2026-12-05 18:17 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251739@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Felix.Kuehling@amd.com \
--cc=akpm@linux-foundation.org \
--cc=amd-gfx@lists.freedesktop.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=bsingharora@gmail.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=hannes@cmpxchg.org \
--cc=ihor.solodrai@linux.dev \
--cc=jack@suse.cz \
--cc=jolsa@kernel.org \
--cc=kees@kernel.org \
--cc=linux-mm@kvack.org \
--cc=martin.lau@linux.dev \
--cc=mason@kernel.org \
--cc=memxor@gmail.com \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=nickolai@csail.mit.edu \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.