Re: [PATCH 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:28:35 EST
Hi Tejun,
On Mon, Nov 30, 2026 at 05:36:25AM -1000, Tejun Heo wrote:
> Hello, Andrea.
>
> On Mon, Nov 30, 2026 at 08:53:03AM +0100, Andrea Righi wrote:
> > @@ -11513,11 +11535,11 @@ __bpf_kfunc void scx_bpf_dump_bstr(char *fmt, unsigned long long *data,
> > }
> >
> > /* append the formatted string to the line buf */
> > - ret = __bstr_format(sch, buf->data, buf->line + dd->cursor,
> > + ret = __bstr_format(sch, buf->data, buf->fmt, buf->line + dd->cursor,
> > sizeof(buf->line) - dd->cursor, fmt, data, data__sz);
>
> The reentrancy that sashiko pointed out reproduces. With an fexit program
> on bpf_bprintf_prepare() calling scx_bpf_dump() on the dump CPU and the
> outer call passing no args, bstr_printf() runs the inner format on NULL
> bin_args:
>
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> RIP: 0010:strlen+0x25/0x70
> Call Trace:
> <IRQ>
> bstr_printf+0x182/0x8d0
> __bstr_format+0x12e/0x1b0
> scx_bpf_dump_bstr+0xe2/0x310
> bpf_prog_1088b804fb0352ba_bstr_dump+0x117/0x1ce
> bpf__sched_ext_ops_dump+0x48/0xa4
> scx_dump_state+0x4b9/0xe00
> scx_disable_irq_workfn+0x7b/0xf0
>
> Without the patch, the same test only loses dump lines, so the oops is new
> with the shared buf->fmt. scx_kfunc_ids_no_tracing was added in this cycle
> and this is headed to stable, so can you close it in this patch instead of
> a follow-up?
Meh, I noticed this email after I sent a v2, which disallows
scx_bpf_dump_bstr() from tracing programs, but that doesn't help stable.
I'll send a v3 that detects nested invocations in scx_bpf_dump_bstr()
and bails out before touching the shared buffers, so the fix is
self-contained.
Thanks,
-Andrea