Skip to content

Commit 255c399

Browse files
htejungregkh
authored andcommitted
sched_ext: Guard scx_dsq_move() against NULL kit->dsq after failed iter_new
[ Upstream commit 4fda9f0 ] 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: 4c30f5c ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a3c44e7 commit 255c399

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

kernel/sched/ext.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5650,6 +5650,14 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit,
56505650
bool in_balance;
56515651
unsigned long flags;
56525652

5653+
/*
5654+
* The verifier considers an iterator slot initialized on any
5655+
* KF_ITER_NEW return, so a BPF program may legally reach here after
5656+
* bpf_iter_scx_dsq_new() failed and left @kit->dsq NULL.
5657+
*/
5658+
if (unlikely(!src_dsq))
5659+
return false;
5660+
56535661
if (!scx_kf_allowed_if_unlocked() &&
56545662
!scx_kf_allowed(sch, SCX_KF_DISPATCH))
56555663
return false;

0 commit comments

Comments
 (0)