From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E41212F5487 for ; Fri, 10 Apr 2026 08:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775811005; cv=none; b=SSrLIK2dcdyTGZbzU/DlhqG8ObZchife2sR1O/QG1Z0mD31dvgA7NQNM95KBSis4HWgidFU9J8xsJl9laJnOx0dZxiZtKjcY1fnPzAujlhdDvPKXylkStBcHWmPdCzeGvMpVXb0UbRvxe14AmSy+F4Mcb+R4XBz3n1gutfc0AAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775811005; c=relaxed/simple; bh=SHSA3ZqwQFODwu6B6t6DEj5v6z7hQc36yEWBoCEWac8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=fSu1Mvj9QI5/gBVVEWCDq5YbxQsMq40bmtv+NV0twKrUvbulCGmma8ljSIXBn0gx2vEA063JDKFBXqb5eURs+AGW16IMGcmNHAxm6Ncx99DsrBmBbqdpLIg3KQxyoHXBpshxGUWN8uwR9bioH/dBEy+dEaRtIsMD0yxCxEpx+nE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=ur8ZXyZc; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="ur8ZXyZc" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description:In-Reply-To:References; bh=BpNbP+I5UCPF0tDaRbgowsSSN52YsC3BPhs1jFGIgGE=; b=ur8ZXyZchg+vW/j5W7xrGVs8fE eRx6TCI/0wvD2I9nKDloABazQhQfUapHiYhwzlACZffWlTQ/mbbq6WRP21rMAvc4cCADnGc636Ae+ yHD6OJlLlNMSriq9tI4GNTdADCzn/iJkzKDY+/NXM2M2LzirzFGxWTyNuJlPAQyjkdDu41Q0EAuSi MFzDw/KO2mYxUc3nqjMWLffDI52fT5EPxTFPcFPIg6VegwM6I/Hpv094pJAtcbMVSFrIy7QVSDk61 gw1vyjPFHwBmVLzXGN6b4aUWz7JIjdFBucIHrPkMVscuZ7uwMapxA1ieDslkA/1zUVJ0bwLqcydCY oOKkz4zA==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wB7Yr-009rWI-26; Fri, 10 Apr 2026 08:49:58 +0000 From: Breno Leitao Date: Fri, 10 Apr 2026 01:49:50 -0700 Subject: [PATCH] workqueue: validate cpumask_first() result in llc_populate_cpu_shard_id() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260410-workqueue_fix_nios-v1-1-abbb26575b1b@debian.org> X-B4-Tracking: v=1; b=H4sIAK252GkC/yXM0QqCMBQG4FcZ/7WDabJwrxIhZr91CrbacSWI7 x7V5XfzrVBmoSKYFZkvUUkRwdSVwXgd4oVWzggGjWu8a2tn3ynfn4WF/SRLHyWppd/7Xefagex QGTwyJ1l+6eH4t5bTjeP8nbBtHyM3Beh2AAAA X-Change-ID: 20260410-workqueue_fix_nios-e6763904aee9 To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, kernel test robot , Breno Leitao X-Mailer: b4 0.16-dev-453a6 X-Developer-Signature: v=1; a=openpgp-sha256; l=1813; i=leitao@debian.org; h=from:subject:message-id; bh=SHSA3ZqwQFODwu6B6t6DEj5v6z7hQc36yEWBoCEWac8=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBp2Lmy5Zn8lSdtjM0JlPTGNpooqob8HdwCznIXQ qz2E/phTh2JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCadi5sgAKCRA1o5Of/Hh3 bSzXEACg+3KskqyAEFQseyNRRGXPg/dck9rayzGm+SPTCDkQOMiGrinGp5OTOU6uPY8DpdB0KRt EgZG4uwuvJrQ7XMJr2fCZlTUBQz8Q8rbIIucWluAqBsofru0KpzeDMmUGRPjvN0iQpj7Lenp4NZ YY++K+6WoBVORgDGyAsBRoBBv6KCUDYoZstxVmhX5LkVKzX+NAU1CcYxsbx3VHLHknTDwlwotQc OXP8eVrtR7UAF1JeP8YcL2i8nELV0UJVrrtvA0f1lSdoaB39yfGILZTy6a6rxIN4o5eiFl4/KZC 61GIvBrR/ul/U34NUJkCNlJ35OelQoUNana3vqpv8Kkq2dGamB0fFa1BxCZ5D6lZhpv1BwuMbU3 K2zBHR6t0QOdJL8AQp/O7q04TJ0vdEfMMKR6BJ0DowHBO540K5dahlTg+tijHP2tZi7i6TjBasg tblu3nrTYrM2Pg85+x9ZbKbgtgOtfdj1Ccpre6W+iT8BW07bY4qgzyqN8Ho04DAfaFqnyymY9pm AqiceQ+fkiK6oiw87WViKtZrQWjGZqIc4zb/MS9ZnkJLE0M4XV+95t0fqxSEzJeRaZVGNjxUmun LbLPrAOVZOp02QPUHR/sapLG7HvBiacUbfsExj5VWtI1tbk7nGMnJIa1nIFR2Iczu0oDfsPdpgw iQjvsVNCLx6ntsQ== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao 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 Closes: https://lore.kernel.org/oe-kbuild-all/202604022343.GQtkF2vO-lkp@intel.com/ Signed-off-by: Breno Leitao --- 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