From: Breno Leitao <leitao@debian.org>
To: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
kernel test robot <lkp@intel.com>,
Breno Leitao <leitao@debian.org>
Subject: [PATCH] workqueue: validate cpumask_first() result in llc_populate_cpu_shard_id()
Date: Fri, 10 Apr 2026 01:49:50 -0700 [thread overview]
Message-ID: <20260410-workqueue_fix_nios-v1-1-abbb26575b1b@debian.org> (raw)
In llc_populate_cpu_shard_id(), cpumask_first(sibling_cpus) is used to
find the leader CPU, and the result is then used to index into
cpu_shard_id[]. Add a bounds check with WARN_ON_ONCE to guard against
unexpected values before using it as an array index.
Store the result in a local variable to make the code clearer, as also
to avoid calling cpumask_first() twice.
Fixes: 5920d046f7ae3 ("workqueue: add WQ_AFFN_CACHE_SHARD affinity scope")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202604022343.GQtkF2vO-lkp@intel.com/
Signed-off-by: Breno Leitao <leitao@debian.org>
---
kernel/workqueue.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 083d8fe301f46..3cb4376a248b0 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -8300,6 +8300,7 @@ static void __init llc_populate_cpu_shard_id(const struct cpumask *pod_cpus,
int cores_in_shard = 0;
/* This is a cursor for the shards. Go from zero to nr_shards - 1*/
int shard_id = 0;
+ int leader;
int c;
/* Iterate at every CPU for a given LLC pod, and assign it a shard */
@@ -8318,7 +8319,11 @@ static void __init llc_populate_cpu_shard_id(const struct cpumask *pod_cpus,
* The siblings' shard MUST be the same as the leader.
* never split threads in the same core.
*/
- cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)];
+ leader = cpumask_first(sibling_cpus);
+
+ if (WARN_ON_ONCE(leader >= nr_cpu_ids))
+ continue;
+ cpu_shard_id[c] = cpu_shard_id[leader];
}
}
---
base-commit: 3fa7d958829eb9bc3b469ed07f11de3d2804ef71
change-id: 20260410-workqueue_fix_nios-e6763904aee9
Best regards,
--
Breno Leitao <leitao@debian.org>
next reply other threads:[~2026-04-10 8:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-10 8:49 Breno Leitao [this message]
2026-04-10 9:00 ` [PATCH] workqueue: validate cpumask_first() result in llc_populate_cpu_shard_id() Tejun Heo
2026-04-10 10:42 ` Breno Leitao
2026-04-10 17:36 ` Tejun Heo
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=20260410-workqueue_fix_nios-v1-1-abbb26575b1b@debian.org \
--to=leitao@debian.org \
--cc=jiangshanlai@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=tj@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox