Re: [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix kernel OOB memory read in scx_bpf_x_bstr kfuncs
From: Masoud Aghasi
Date: Sun Nov 29 2026 - 10:34:14 EST
On 29/11/2026 14:11, Andrea Righi wrote:
> Hi Masoud,
>
> On Sun, Nov 29, 2026 at 09:35:55AM +0000, Masoud Aghasi wrote:
>> For scx_bpf_exit_bstr(), scx_bpf_error_bstr(), scx_bpf_dump_bstr()
>> and scx_bpf_sub_kill_bstr() kfuncs, fmt parameter is defined as a
>> dynamic string pointer which could be of any length. This causes a
>> kernel out-of-bound memory read inside the bpf_bprintf_prepare()
>> for loop, when passing strings with lengths higher than INT_MAX.
>
> Actually I think the OOB doesn't require a string longer than INT_MAX,
> the verifier only checks one byte of fmt, so an unterminated buffer can
> also overrun in the initial strnchr(), before reaching the loop. We
> should probably clarify this in the description.
>
> And, as reported by Sashiko, ___fmt needs to be const, otherwise the
> existing wrappers fail verification. Please also fix the kernel-doc
> parameter names.
>
> Thanks,
> -Andrea
>
Hi Andrea, thanks for the review.
Yes, you are right about the OOB read of strings shorter than INT_MAX,
without __str suffix.
I will add these changes to the V2.