Skip to content

Commit 3cbe8b8

Browse files
committed
sched_ext: bpf_iter_scx_dsq_new() should always initialize iterator
JIRA: https://issues.redhat.com/browse/RHEL-92921 commit 428dc9f Author: Tejun Heo <tj@kernel.org> Date: Mon May 5 11:30:39 2025 -1000 sched_ext: bpf_iter_scx_dsq_new() should always initialize iterator BPF programs may call next() and destroy() on BPF iterators even after new() returns an error value (e.g. bpf_for_each() macro ignores error returns from new()). bpf_iter_scx_dsq_new() could leave the iterator in an uninitialized state after an error return causing bpf_iter_scx_dsq_next() to dereference garbage data. Make bpf_iter_scx_dsq_new() always clear $kit->dsq so that next() and destroy() become noops. Signed-off-by: Tejun Heo <tj@kernel.org> Fixes: 650ba21 ("sched_ext: Implement DSQ iterator") Cc: stable@vger.kernel.org # v6.12+ Acked-by: Andrea Righi <arighi@nvidia.com> Signed-off-by: Phil Auld <pauld@redhat.com>
1 parent 8c63e08 commit 3cbe8b8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernel/sched/ext.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7170,6 +7170,12 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
71707170
BUILD_BUG_ON(__alignof__(struct bpf_iter_scx_dsq_kern) !=
71717171
__alignof__(struct bpf_iter_scx_dsq));
71727172

7173+
/*
7174+
* next() and destroy() will be called regardless of the return value.
7175+
* Always clear $kit->dsq.
7176+
*/
7177+
kit->dsq = NULL;
7178+
71737179
if (flags & ~__SCX_DSQ_ITER_USER_FLAGS)
71747180
return -EINVAL;
71757181

0 commit comments

Comments
 (0)