[PATCHSET v2 sched_ext/for-7.4-fixes] sched_ext: Fix unbounded format string reads in the bstr kfuncs

From: Andrea Righi

Date: Mon Nov 30 2026 - 11:19:37 EST


The format strings passed to the sched_ext bstr kfuncs are only checked
by the verifier to be readable for a single byte, so an unterminated
format makes bpf_bprintf_prepare() scan past the end of the BPF object
[1].

Annotating them with __str would break compatibility in both directions,
since common.bpf.h places the formats in writable .data. Instead, copy
the format into a private kernel buffer with a bounded, fault-safe read
and use only the copy for both preparation and formatting, leaving the
kfunc prototypes and the BPF-side wrappers unchanged.

[1] https://lore.kernel.org/all/20261130054957.570822-1-maghasi@xxxxxxxxxxx

Changes in v2:
- Add a patch to disallow scx_bpf_dump_bstr() from tracing programs,
preventing a nested call on the dumping CPU from overwriting the
format snapshot of the outer call (Sashiko)
- Link to v1: https://lore.kernel.org/r/20261130075303.1261456-1-arighi@xxxxxxxxxx

Andrea Righi (2):
sched_ext: Disallow scx_bpf_dump_bstr() from tracing programs
sched_ext: Fix unbounded format string reads in the bstr kfuncs

kernel/sched/ext/ext.c | 55 +++++++++++++++++++++++++++----------
kernel/sched/ext/internal.h | 4 +++
kernel/sched/ext/types.h | 1 +
3 files changed, 46 insertions(+), 14 deletions(-)