The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Andrea Righi <arighi@nvidia.com>
Cc: David Vernet <void@manifault.com>,
	Changwoo Min <changwoo@igalia.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()
Date: Mon, 3 Mar 2025 06:11:15 -1000	[thread overview]
Message-ID: <Z8XUozpR547RFxkx@slm.duckdns.org> (raw)
In-Reply-To: <20250302220903.54001-1-arighi@nvidia.com>

Hello,

On Sun, Mar 02, 2025 at 11:09:03PM +0100, Andrea Righi wrote:
> If a BPF scheduler provides an invalid CPU (outside the nr_cpu_ids
> range) as prev_cpu to scx_bpf_select_cpu_dfl() it can cause a kernel
> crash.
> 
> To prevent this, validate prev_cpu in scx_bpf_select_cpu_dfl() and
> trigger an scx error if an invalid CPU is specified.
> 
> Fixes: f0e1a0643a59b ("sched_ext: Implement BPF extensible scheduler class")
> Cc: stable@vger.kernel.org # v6.12+
> Signed-off-by: Andrea Righi <arighi@nvidia.com>
> ---
>  kernel/sched/ext.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 0f1da199cfc7c..88b2ea58ff942 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
> @@ -6422,6 +6422,11 @@ static bool check_builtin_idle_enabled(void)
>  __bpf_kfunc s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
>  				       u64 wake_flags, bool *is_idle)
>  {
> +	if (!ops_cpu_valid(prev_cpu, NULL)) {
> +		prev_cpu = cpumask_any(p->cpus_ptr);
> +		goto prev_cpu;

I'd just return the invalid prev_cpu. The scheduler is getting aborted
anyway.

Thanks.

-- 
tejun

  reply	other threads:[~2025-03-03 16:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-02 22:09 [PATCH] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl() Andrea Righi
2025-03-03 16:11 ` Tejun Heo [this message]
2025-03-03 17:25   ` Andrea Righi

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=Z8XUozpR547RFxkx@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=arighi@nvidia.com \
    --cc=changwoo@igalia.com \
    --cc=linux-kernel@vger.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