From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DBD0606A31F for ; Sat, 5 Dec 2026 16:11:28 +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 kanga.kvack.org (Postfix) id CC15D6B00EF; Sat, 5 Dec 2026 11:11:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C725D6B05B1; Sat, 5 Dec 2026 11:11:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B87B26B05B2; Sat, 5 Dec 2026 11:11:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8DA2C6B00EF for ; Sat, 5 Dec 2026 11:11:26 -0500 (EST) Received: from smtpin09.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 11AC81605F1 for ; Sat, 5 Dec 2026 16:11:26 +0000 (UTC) X-FDA: 85510419372.09.37483B1 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf19.hostedemail.com (Postfix) with ESMTP id 5F0B41A000D for ; Sat, 5 Dec 2026 16:11:24 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=A6KcGEYc; spf=pass (imf19.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796487084; b=0t/RPlUFVgTfnS10BGb0K0qr6GloWBVRAZi4CikpUDvLdsaHezrAuJK7iYCQSQbyMWbWGG H8ioOOL1dCoWblzqJnuYfbOSa5ryP/aWHAZKsecZaRtkOTiCoCSl7JL8voyJvlaoQDiL7w hRvbfqfun8/RaFuN/Q8uc+pArgjKSSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796487084; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n99iZJi542Q81XAmQSW83VQhFSv1VgLwEJeqiG+kTrs=; b=ZZcl9ezLL4FyhJPPLcDPXvwl9yUIsIgTNGQOHRpbWo0/4zP54+MMHy+FoHAStWVoMXZRDY Mjie3hR4aIsN2uKxMMp5v6gO88L+I2evhuorIAAeivfdUTBeZDaAb+73KxKQPsHXbbfn65 z++sR8BkPmoIK5hhHTD7SGb2gne6cac= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=A6KcGEYc; spf=pass (imf19.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B39E7605F4; Sat, 5 Dec 2026 16:11:23 +0000 (UTC) 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-Stat-Signature: s6jpszbmkeg8zqnuahekppfjryd7anjc X-Rspam-User: X-Rspamd-Queue-Id: 5F0B41A000D X-Rspamd-Server: rspam09 X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST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YWSDeODPOMTY9Rds+lauXg7k4ZAkrvB+8ozOMp6Aji2aZTPEHundc2/sWVywWPZCGshh/XO4IZv3VGphScLkoON5X81YATYBtXjlq1qX9nflZ7anzaFpZ32T8Dka2lIHSuMAs2nFNNdJ536PZllHN6jVmnXjh952p/OojG6HVfbwWCLY0ByGsG7urkp4OvC7h7sBla7cL3rAw2IwfQdGcs+i3HnuW2Q3R2TC96BSHhr7wbkBxM27J92dB6XHsahcvM/KpYH+WCY65DtMvZtgZpJ9IwU2/y8KLD36Qm9YM8HGKt2dmSs5z+kQ9hW1aX2JBu3zV8tm9VDn44iyxhd4CJOfcrr/qISZebmQwAmh6G+tM5QbKBZSBnS0sZ4eNkVEXInSDbQBYRnek3nYYR4Yeu0WhuYKwVk2ZKJLpev+g15IN0SI8Dstuq8E/Q+c7RO+9CsNkL9CMN9etQZnRwLOj/s5uZTuAIjJu6GIxvg3DGqi2u371rQRjIRjFg4jk2Q44iDMIeb0rzreDnKmw5dajoXbkYZG3hTlxdtQZFlHDESIiPCRr0mbGF7Fcl4P9seVsvArhl8kW5SMchryg9jrBgKfEtmzG8qOnWSLrQxaikLzEb+i+J/T5A37QG3N9ZpdFzSiEwDhrWIGBp6uqZmb3B8zK9BVU+DOlP/KcT/vhXxrx2rlffGGLzWm6rEPJCXx2m+V8HFpf1EMdXiD4aaCK0ph2F4SCTA8tq1PmqgXrRIUCVWr6EM+KCnhlzJ5GAf0t2ctn72vaTnps/iyCGC7R/ppQj+MnCtv9PK0BZt22rZjfrJBIok64kB7sF4pXUVUjBuyHLWqk6q8bFuvMmEeiSTVel28vqduqDke6JnUMzC24/1reQR11c/ Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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