Skip to content

Commit 9360dfe

Browse files
arighihtejun
authored andcommitted
sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()
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: f0e1a06 ("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>
1 parent 8fef0a3 commit 9360dfe

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/sched/ext.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6422,6 +6422,9 @@ static bool check_builtin_idle_enabled(void)
64226422
__bpf_kfunc s32 scx_bpf_select_cpu_dfl(struct task_struct *p, s32 prev_cpu,
64236423
u64 wake_flags, bool *is_idle)
64246424
{
6425+
if (!ops_cpu_valid(prev_cpu, NULL))
6426+
goto prev_cpu;
6427+
64256428
if (!check_builtin_idle_enabled())
64266429
goto prev_cpu;
64276430

0 commit comments

Comments
 (0)