All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH sched_ext/for-6.15-fixes] sched_ext: bpf_iter_scx_dsq_new() should always initialize iterator
@ 2025-05-05 21:30 Tejun Heo
  2025-05-06  6:35 ` Andrea Righi
  2025-05-07 16:35 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Tejun Heo @ 2025-05-05 21:30 UTC (permalink / raw)
  To: David Vernet, Andrea Righi, Changwoo Min; +Cc: linux-kernel

From 3ca42b7aea35cbcfb8d1fdde09e10a54edf97b26 Mon Sep 17 00:00:00 2001
From: Tejun Heo <tj@kernel.org>
Date: Mon, 5 May 2025 11:28:21 -1000

BPF programs may call next() and destroy() on BPF iterators even after new()
returns an error value. 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: 650ba21b131e ("sched_ext: Implement DSQ iterator")
Cc: stable@vger.kernel.org # v6.12+
---
 kernel/sched/ext.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 4e37b40ce280..f5133249fd4d 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -6827,6 +6827,12 @@ __bpf_kfunc int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id,
 	BUILD_BUG_ON(__alignof__(struct bpf_iter_scx_dsq_kern) !=
 		     __alignof__(struct bpf_iter_scx_dsq));
 
+	/*
+	 * next() and destroy() will be called regardless of the return value.
+	 * Always clear $kit->dsq.
+	 */
+	kit->dsq = NULL;
+
 	if (flags & ~__SCX_DSQ_ITER_USER_FLAGS)
 		return -EINVAL;
 
-- 
2.49.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-07 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-05 21:30 [PATCH sched_ext/for-6.15-fixes] sched_ext: bpf_iter_scx_dsq_new() should always initialize iterator Tejun Heo
2025-05-06  6:35 ` Andrea Righi
2025-05-07 16:35 ` Tejun Heo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.