All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andrea Righi" <arighi@nvidia.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 2/2] sched_ext: Fix unbounded format string reads in the bstr kfuncs
Date: Mon, 30 Nov 2026 16:41:38 +0000	[thread overview]
Message-ID: <sashiko-outbox-241601@kernel.org> (raw)
In-Reply-To: <20261130161913.1379563-3-arighi@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched_ext: missing re-entrancy guard in scx_bpf_dump_bstr()
  for stable
--

commit 96c34c3723cdfae7a173919614dbc82435b3aff5
Author: Andrea Righi <arighi@nvidia.com>

sched_ext: Fix unbounded format string reads in the bstr kfuncs

This commit copies BPF format strings into a bounded kernel buffer via
strncpy_from_kernel_nofault() before calling bpf_bprintf_prepare() and
bstr_printf().

Link: https://lore.kernel.org/r/20261130054957.570822-1-maghasi@disroot.org

> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 27502dcae0433..7483b10587a90 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c

[ ... ]

> @@ -11303,18 +11326,17 @@ static s32 __bstr_format(struct scx_sched *sch, u64 *data_buf, char *line_buf,
>  		return ret;
>  	}
>  
> -	ret = bpf_bprintf_prepare(fmt, UINT_MAX, data_buf, data__sz / 8,
> -				  &bprintf_data);
> +	ret = bpf_bprintf_prepare(fmt_buf, SCX_BSTR_FMT_LEN, data_buf,
> +				  data__sz / 8, &bprintf_data);
>  	if (ret < 0) {
>  		scx_error(sch, "format preparation failed (%d)", ret);
>  		return ret;
>  	}
>  
> -	ret = bstr_printf(line_buf, line_size, fmt,
> -			  bprintf_data.bin_args);
> +	ret = bstr_printf(line_buf, line_size, fmt_buf, bprintf_data.bin_args);
>  	bpf_bprintf_cleanup(&bprintf_data);
>  	if (ret < 0) {
> -		scx_error(sch, "(\"%s\", %p, %u) failed to format", fmt, data, data__sz);
> +		scx_error(sch, "(\"%s\", %p, %u) failed to format", fmt_buf, data, data__sz);
>  		return ret;
>  	}
>  

[ ... ]

> @@ -11441,11 +11463,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);
>  	if (ret < 0) {
>  		scx_dump_line(dd->s, "%s[!] (\"%s\", %p, %u) failed to format (%d)",
> -			      dd->prefix, fmt, data, data__sz, ret);
> +			      dd->prefix, buf->fmt, data, data__sz, ret);
>  		return;
>  	}

[Severity: Medium]
As reported by Tejun Heo on v1 [1], can re-entering scx_bpf_dump_bstr() on
dd->cpu overwrite the shared buf->fmt and cause a NULL pointer dereference in
bstr_printf()?

scx_bpf_dump_bstr() (fmt="hello", data__sz=0)
  __bstr_format()
    scx_snapshot_fmt(buf->fmt, ..., "hello")
    bpf_bprintf_prepare(buf->fmt, ..., num_args=0, &bprintf_data)
      bprintf_data.bin_args = NULL
    <fexit/bpf_bprintf_prepare or IRQ/NMI tracing prog on dd->cpu>
      scx_bpf_dump_bstr() (fmt="%s", data__sz=8)
        __bstr_format()
          scx_snapshot_fmt(buf->fmt, ..., "%s")
          ...
    bstr_printf(..., buf->fmt, bprintf_data.bin_args)
      <-- dereferences NULL bin_args for "%s"

The earlier commit "sched_ext: Disallow scx_bpf_dump_bstr() from tracing
programs" in this series blocks tracing callers via scx_kfunc_ids_no_tracing,
which was added in the current cycle.  However, this commit is tagged for
v6.12+ stable trees where scx_kfunc_ids_no_tracing does not exist, so
scx_bpf_dump_bstr() still needs an in-function re-entrancy guard around
__bstr_format() (such as a busy flag in scx_dump_data or temporarily clearing
dd->cpu).

[1] https://lore.kernel.org/r/9a62510c0dd0fe29ed5a40e89aa80e83@kernel.org

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130161913.1379563-1-arighi@nvidia.com?part=2

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

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:18 [PATCHSET v2 sched_ext/for-7.4-fixes] sched_ext: Fix unbounded format string reads in the bstr kfuncs Andrea Righi
2026-11-30 16:18 ` [PATCH 1/2] sched_ext: Disallow scx_bpf_dump_bstr() from tracing programs Andrea Righi
2026-11-30 16:18 ` [PATCH 2/2] sched_ext: Fix unbounded format string reads in the bstr kfuncs Andrea Righi
2026-11-30 16:41   ` sashiko-bot [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=sashiko-outbox-241601@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sched-ext@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.