From: Andrea Righi <arighi@nvidia.com>
To: Sechang Lim <rhkrqnwk98@gmail.com>
Cc: sched-ext@lists.linux.dev, tj@kernel.org, void@manifault.com,
changwoo@igalia.com, mingo@redhat.com, peterz@infradead.org,
juri.lelli@redhat.com, vincent.guittot@linaro.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, haoluo@google.com, brho@google.com,
joshdon@google.com, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH v2] sched_ext: reject oversized dispatch_max_batch
Date: Fri, 20 Nov 2026 09:12:08 +0100 [thread overview]
Message-ID: <awAA2OSJnYDBURqo@gpd4> (raw)
In-Reply-To: <20261120065559.3979434-1-rhkrqnwk98@gmail.com>
On Fri, Nov 20, 2026 at 06:55:54AM +0000, Sechang Lim wrote:
> bpf_scx_init_member() accepts dispatch_max_batch values up to INT_MAX.
> The value determines the size of the per-CPU dispatch buffer, but
> __alloc_percpu() rejects allocations larger than PCPU_MIN_UNIT_SIZE.
> With BPF_F_LINK, an oversized value passes the struct_ops map update
> and triggers an illegal-size warning during link creation before the
> allocation fails with -ENOMEM.
>
> Calculate the buffer size using the effective batch count, including
> the default used when dispatch_max_batch is zero. Reject values above
> the per-CPU allocation limit with -E2BIG during the map update, before
> the allocator is called. This also covers registration without a link.
>
> Fixes: f0e1a0643a59 ("sched_ext: Implement BPF extensible scheduler class")
> Signed-off-by: Sechang Lim <rhkrqnwk98@gmail.com>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
> ---
> v2:
> - add braces (Andrea Righi)
>
> v1:
> - https://lore.kernel.org/sched-ext/20261120054913.3795562-1-rhkrqnwk98@gmail.com/T/#u
>
>
> kernel/sched/ext/ext.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c
> index 10de6bd865e8..56d75d179822 100644
> --- a/kernel/sched/ext/ext.c
> +++ b/kernel/sched/ext/ext.c
> @@ -9196,11 +9196,17 @@ static int bpf_scx_init_member(const struct btf_type *t,
> int ret;
>
> switch (moff) {
> - case offsetof(struct sched_ext_ops, dispatch_max_batch):
> - if (*(u32 *)(udata + moff) > INT_MAX)
> + case offsetof(struct sched_ext_ops, dispatch_max_batch): {
> + u32 batch = *(u32 *)(udata + moff);
> + u32 nr = batch ?: SCX_DSP_DFL_MAX_BATCH;
> +
> + if (struct_size_t(struct scx_sched_pcpu, dsp_ctx.buf, nr) >
> + PCPU_MIN_UNIT_SIZE)
> return -E2BIG;
> - ops->dispatch_max_batch = *(u32 *)(udata + moff);
> +
> + ops->dispatch_max_batch = batch;
> return 1;
> + }
> case offsetof(struct sched_ext_ops, flags):
> if (*(u64 *)(udata + moff) & ~SCX_OPS_ALL_FLAGS)
> return -EINVAL;
> --
> 2.56.1
>
prev parent reply other threads:[~2026-11-20 8:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 6:55 Sechang Lim
2026-11-20 8:12 ` 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=awAA2OSJnYDBURqo@gpd4 \
--to=arighi@nvidia.com \
--cc=bpf@vger.kernel.org \
--cc=brho@google.com \
--cc=bsegall@google.com \
--cc=changwoo@igalia.com \
--cc=dietmar.eggemann@arm.com \
--cc=haoluo@google.com \
--cc=joshdon@google.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rhkrqnwk98@gmail.com \
--cc=rostedt@goodmis.org \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=void@manifault.com \
--cc=vschneid@redhat.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
all inboxes | Powered by JetHome®