* [PATCH v2] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()
@ 2025-03-03 17:51 Andrea Righi
2025-03-03 18:06 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Andrea Righi @ 2025-03-03 17:51 UTC (permalink / raw)
To: Tejun Heo, David Vernet, Changwoo Min; +Cc: linux-kernel
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 | 3 +++
1 file changed, 3 insertions(+)
ChangeLog v1 -> v2:
- return prev_cpu instead of trying to find a valid cpu (since the
scheduler is exiting anyway)
diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index 0f1da199cfc7c..7b9dfee858e79 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -6422,6 +6422,9 @@ 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))
+ goto prev_cpu;
+
if (!check_builtin_idle_enabled())
goto prev_cpu;
--
2.48.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()
2025-03-03 17:51 [PATCH v2] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl() Andrea Righi
@ 2025-03-03 18:06 ` Tejun Heo
0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2025-03-03 18:06 UTC (permalink / raw)
To: Andrea Righi; +Cc: David Vernet, Changwoo Min, linux-kernel
On Mon, Mar 03, 2025 at 06:51:59PM +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>
Applied to sched_ext/for-6.14-fixes.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-03-03 18:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-03 17:51 [PATCH v2] sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl() Andrea Righi
2025-03-03 18:06 ` Tejun Heo
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®