All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Masoud Aghasi" <maghasi@disroot.org>, sched-ext@lists.linux.dev
Subject: Re: [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix kernel OOB memory read in scx_bpf_x_bstr kfuncs
Date: Sun, 29 Nov 2026 09:50:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-239473@kernel.org> (raw)
In-Reply-To: <20261129093555.3890002-1-maghasi@disroot.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] sched_ext: non-const ___fmt in scx_bpf_bstr_preamble() fails
  __str verifier check
- [Low] sched_ext: kernel-doc @fmt mismatch after fmt__str rename in
  *_bstr() kfuncs
--

commit 2b70c95fa8aff160dd9f3bf21e32e37b0b12fac5
Author: Masoud Aghasi <maghasi@disroot.org>

sched_ext: Fix kernel OOB memory read in scx_bpf_x_bstr kfuncs

This commit adds the __str verifier suffix to the format string parameter
of scx_bpf_exit_bstr(), scx_bpf_error_bstr(), scx_bpf_dump_bstr(), and
scx_bpf_sub_kill_bstr(), and lowers the bpf_bprintf_prepare() length limit
in __bstr_format() from UINT_MAX to INT_MAX.

> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index a9e36b5bb0386..b633d6c5843b2 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
[ ... ]
> @@ -11369,7 +11369,7 @@ __bpf_kfunc_start_defs();
>   * disabling.
>   */
>  __printf(2, 0)
> -__bpf_kfunc void scx_bpf_exit_bstr(s64 exit_code, char *fmt,
> +__bpf_kfunc void scx_bpf_exit_bstr(s64 exit_code, const char *fmt__str,
>  				   unsigned long long *data, u32 data__sz,
>  				   const struct bpf_prog_aux *aux)
>  {

[Severity: Low]
Since the parameter was renamed to fmt__str, the kernel-doc comments for
scx_bpf_exit_bstr(), scx_bpf_error_bstr(), scx_bpf_dump_bstr(), and
scx_bpf_sub_kill_bstr() still document @fmt: instead of @fmt__str:, which
triggers kernel-doc warnings under W=1 builds.

> diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/include/scx/common.bpf.h
> index 6194484d4d9a9..648188ce66066 100644
> --- a/tools/sched_ext/include/scx/common.bpf.h
> +++ b/tools/sched_ext/include/scx/common.bpf.h
> @@ -74,9 +74,9 @@ int bpf_iter_scx_dsq_new(struct bpf_iter_scx_dsq *it, u64 dsq_id, u64 flags) __k
>  struct task_struct *bpf_iter_scx_dsq_next(struct bpf_iter_scx_dsq *it) __ksym __weak;
>  void bpf_iter_scx_dsq_destroy(struct bpf_iter_scx_dsq *it) __ksym __weak;
>  bool scx_bpf_dsq_reenq_task(struct bpf_iter_scx_dsq *it, struct task_struct *p) __ksym __weak;
> -void scx_bpf_exit_bstr(s64 exit_code, char *fmt, unsigned long long *data, u32 data__sz) __ksym __weak;
> -void scx_bpf_error_bstr(char *fmt, unsigned long long *data, u32 data_len) __ksym;
> -void scx_bpf_dump_bstr(char *fmt, unsigned long long *data, u32 data_len) __ksym __weak;
> +void scx_bpf_exit_bstr(s64 exit_code, const char *fmt__str, unsigned long long *data, u32 data__sz) __ksym __weak;
> +void scx_bpf_error_bstr(const char *fmt__str, unsigned long long *data, u32 data_len) __ksym;
> +void scx_bpf_dump_bstr(const char *fmt__str, unsigned long long *data, u32 data_len) __ksym __weak;
>  u32 scx_bpf_cpuperf_cap(s32 cpu) __ksym __weak;
>  u32 scx_bpf_cpuperf_cur(s32 cpu) __ksym __weak;
>  void scx_bpf_cpuperf_set(s32 cpu, u32 perf) __ksym __weak;
> @@ -123,7 +123,7 @@ u32 scx_bpf_cidperf_cur(s32 cid) __ksym __weak;
>  s32 scx_bpf_sub_grant(u64 cgroup_id, u64 caps, const struct scx_cmask __arena *cmask__arena, struct scx_cmask __arena *denied_out__arena__nullable) __ksym __weak;
>  void scx_bpf_sub_revoke(u64 cgroup_id, u64 caps, const struct scx_cmask __arena *cmask__arena) __ksym __weak;
>  s32 scx_bpf_sub_caps(u64 cgroup_id, u64 caps, struct scx_cmask __arena *out__arena) __ksym __weak;
> -s32 scx_bpf_sub_kill_bstr(u64 cgroup_id, char *fmt, unsigned long long *data, u32 data__sz) __ksym __weak;
> +s32 scx_bpf_sub_kill_bstr(u64 cgroup_id, const char *fmt__str, unsigned long long *data, u32 data__sz) __ksym __weak;
>  
>  /*
>   * Use the following as @it__iter when calling scx_bpf_dsq_move[_vtime]() from

[Severity: High]
Does adding the __str suffix without making ___fmt const in
scx_bpf_bstr_preamble() cause the verifier to reject every BPF program
calling scx_bpf_exit(), scx_bpf_error(), scx_bpf_dump(), or
scx_bpf_sub_kill()?

With fmt__str, the verifier classifies the argument as
ARG_PTR_TO_CONST_STR and checks bpf_map_is_rdonly() in
check_arg_const_str(), requiring the format string to live in a frozen
read-only map (.rodata).  However, scx_bpf_bstr_preamble() in the same
header still declares ___fmt without const:

tools/sched_ext/include/scx/common.bpf.h:
#define scx_bpf_bstr_preamble(fmt, args...)					\
	static char ___fmt[] = fmt;						\

Because ___fmt is non-const, the compiler places it in the writable .data
map instead of .rodata, causing check_arg_const_str() to fail verification
with -EACCES ("fmt__str does not point to a readonly map").  In addition,
existing pre-compiled sched_ext BPF binaries built with non-const ___fmt
will also fail verification at load time.

Declaring static const char ___fmt[] = fmt; in scx_bpf_bstr_preamble()
places the format string in .rodata for newly compiled programs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129093555.3890002-1-maghasi@disroot.org?part=1

  reply	other threads:[~2026-11-29  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29  9:35 [PATCH sched_ext/for-7.4-fixes] sched_ext: Fix kernel OOB memory read in scx_bpf_x_bstr kfuncs Masoud Aghasi
2026-11-29  9:50 ` sashiko-bot [this message]
2026-11-29  9:54 ` Masoud Aghasi
2026-11-29 14:11 ` Andrea Righi
2026-11-29 15:33   ` Masoud Aghasi

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-239473@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=maghasi@disroot.org \
    --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.