From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>, Chris Mason <clm@meta.com>,
Andrea Righi <arighi@nvidia.com>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y] sched_ext: Guard scx_dsq_move() against NULL kit->dsq after failed iter_new
Date: Sun, 17 May 2026 22:11:00 -0400 [thread overview]
Message-ID: <20260518021100.535042-1-sashal@kernel.org> (raw)
In-Reply-To: <2026051201-cupping-demotion-047d@gregkh>
From: Tejun Heo <tj@kernel.org>
[ Upstream commit 4fda9f0e7c950da4fe03cedeb2ac818edf5d03e9 ]
bpf_iter_scx_dsq_new() clears kit->dsq on failure and
bpf_iter_scx_dsq_{next,destroy}() guard against that. scx_dsq_move() doesn't -
it dereferences kit->dsq immediately, so a BPF program that calls
scx_bpf_dsq_move[_vtime]() after a failed iter_new oopses the kernel.
Return false if kit->dsq is NULL.
Fixes: 4c30f5ce4f7a ("sched_ext: Implement scx_bpf_dispatch[_vtime]_from_dsq()")
Cc: stable@vger.kernel.org # v6.12+
Reported-by: Chris Mason <clm@meta.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
[ dropped upstream `sch = src_dsq->sched` reordering since stable initializes `sch` from `scx_root` instead ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/sched/ext.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 177bbf31116d0..5e989409c7715 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -5650,6 +5650,14 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit,
bool in_balance;
unsigned long flags;
+ /*
+ * The verifier considers an iterator slot initialized on any
+ * KF_ITER_NEW return, so a BPF program may legally reach here after
+ * bpf_iter_scx_dsq_new() failed and left @kit->dsq NULL.
+ */
+ if (unlikely(!src_dsq))
+ return false;
+
if (!scx_kf_allowed_if_unlocked() &&
!scx_kf_allowed(sch, SCX_KF_DISPATCH))
return false;
--
2.53.0
prev parent reply other threads:[~2026-05-18 2:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 14:18 FAILED: patch "[PATCH] sched_ext: Guard scx_dsq_move() against NULL kit->dsq after" failed to apply to 6.18-stable tree gregkh
2026-05-18 2:11 ` Sasha Levin [this message]
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=20260518021100.535042-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=arighi@nvidia.com \
--cc=clm@meta.com \
--cc=stable@vger.kernel.org \
--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