The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Tejun Heo <tj@kernel.org>
Cc: David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>,
	Masoud Aghasi <maghasi@disroot.org>,
	sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix unbounded format string reads in the bstr kfuncs
Date: Mon, 30 Nov 2026 17:28:12 +0100	[thread overview]
Message-ID: <aw2kHAG_cG8uZq4P@gpd4> (raw)
In-Reply-To: <9a62510c0dd0fe29ed5a40e89aa80e83@kernel.org>

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

      reply	other threads:[~2026-11-30 16:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  7:53 [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix unbounded format string reads in the bstr kfuncs Andrea Righi
2026-11-30 10:49 ` Masoud Aghasi
2026-11-30 11:03   ` Andrea Righi
2026-11-30 15:36 ` Tejun Heo
2026-11-30 16:28   ` Andrea Righi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aw2kHAG_cG8uZq4P@gpd4 \
    --to=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maghasi@disroot.org \
    --cc=sched-ext@lists.linux.dev \
    --cc=tj@kernel.org \
    --cc=void@manifault.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox