From: Andrea Righi <arighi@nvidia.com>
To: stable@vger.kernel.org
Subject: [PATCH 6.12.y] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()
Date: Sun, 16 Mar 2025 14:26:26 +0100 [thread overview]
Message-ID: <20250316132626.48526-1-arighi@nvidia.com> (raw)
In-Reply-To: <2025031614-broiler-overgrown-4bd4@gregkh>
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>
Signed-off-by: Tejun Heo <tj@kernel.org>
(cherry picked from commit 9360dfe4cbd62ff1eb8217b815964931523b75b3)
---
kernel/sched/ext.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 325fd5b9d4715..e5cab54dfdd14 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -6052,6 +6052,9 @@ __bpf_kfunc_start_defs();
__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))
+ goto prev_cpu;
+
if (!static_branch_likely(&scx_builtin_idle_enabled)) {
scx_ops_error("built-in idle tracking is disabled");
goto prev_cpu;
--
2.48.1
next prev parent reply other threads:[~2025-03-16 13:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-16 7:17 FAILED: patch "[PATCH] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()" failed to apply to 6.12-stable tree gregkh
2025-03-16 13:26 ` Andrea Righi [this message]
2025-03-17 12:24 ` [PATCH 6.12.y] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl() Sasha Levin
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=20250316132626.48526-1-arighi@nvidia.com \
--to=arighi@nvidia.com \
--cc=stable@vger.kernel.org \
/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