[PATCH 1/2] sched_ext: Disallow scx_bpf_dump_bstr() from tracing programs

From: Andrea Righi

Date: Mon Nov 30 2026 - 11:21:46 EST


scx_bpf_dump_bstr() is in scx_kfunc_ids_any, so tracing programs can
call it too. However, it's only meaningful from ops.dump(),
ops.dump_cpu() and ops.dump_task(): called from any other CPU, it just
aborts the scheduler.

Moreover, a tracing program running on the dumping CPU in the middle of
another scx_bpf_dump_bstr() call (e.g., attached to a function invoked
while formatting) can clobber the shared buffers in scx_dump_data that
the outer call is still using, corrupting the dump output.

Add scx_bpf_dump_bstr() to scx_kfunc_ids_no_tracing, so that tracing
programs calling it are rejected at load time.

Fixes: 07814a9439a3 ("sched_ext: Print debug dump after an error exit")
Link: https://lore.kernel.org/r/sashiko-outbox-240675@xxxxxxxxxx
Signed-off-by: Andrea Righi <arighi@xxxxxxxxxx>
---
kernel/sched/ext/ext.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
index a4a93ed97f7b6..928652dbeb1b4 100644
--- a/kernel/sched/ext/ext.c
+++ b/kernel/sched/ext/ext.c
@@ -12267,6 +12267,10 @@ static const struct btf_kfunc_id_set scx_kfunc_set_any = {
* arbitrary tracing context. One that calls scx_bpf_cidperf_set() hits the
* deadlock above.
*
+ * scx_bpf_dump_bstr() is only meaningful from ops.dump*(). A tracing program
+ * can run on the dumping CPU in the middle of another scx_bpf_dump_bstr()
+ * call and clobber its shared format and line buffers.
+ *
* Members must also stay in scx_kfunc_ids_any so that struct_ops and syscall
* programs keep their access.
*/
@@ -12278,6 +12282,7 @@ BTF_ID_FLAGS(func, scx_bpf_sub_revoke, KF_IMPLICIT_ARGS)
BTF_ID_FLAGS(func, scx_bpf_destroy_dsq, KF_IMPLICIT_ARGS)
BTF_ID_FLAGS(func, bpf_iter_scx_dsq_next, KF_ITER_NEXT | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_iter_scx_dsq_destroy, KF_ITER_DESTROY)
+BTF_ID_FLAGS(func, scx_bpf_dump_bstr, KF_IMPLICIT_ARGS)
BTF_KFUNCS_END(scx_kfunc_ids_no_tracing)

/*
--
2.56.1