Skip to content

Commit 428dc9f

Browse files
committed
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 <[email protected]> Fixes: 650ba21 ("sched_ext: Implement DSQ iterator") Cc: [email protected] # v6.12+ Acked-by: Andrea Righi <[email protected]>
1 parent e38be1c commit 428dc9f

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
@@ -6827,6 +6827,12 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
68276827
BUILD_BUG_ON(__alignof__(struct bpf_iter_scx_dsq_kern) !=
68286828
__alignof__(struct bpf_iter_scx_dsq));
68296829

6830+
/*
6831+
* next() and destroy() will be called regardless of the return value.
6832+
* Always clear $kit->dsq.
6833+
*/
6834+
kit->dsq = NULL;
6835+
68306836
if (flags & ~__SCX_DSQ_ITER_USER_FLAGS)
68316837
return -EINVAL;
68326838

0 commit comments

Comments
 (0)