]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
sched_ext: Validate prev_cpu in scx_bpf_select_cpu_dfl()
authorAndrea Righi <arighi@nvidia.com>
Mon, 3 Mar 2025 17:51:59 +0000 (18:51 +0100)
committerTejun Heo <tj@kernel.org>
Mon, 3 Mar 2025 17:55:48 +0000 (07:55 -1000)
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>
kernel/sched/ext.c

index 0f1da199cfc7c7e103d2d01ccd0c818291f01439..7b9dfee858e7988bf130e067f87de240a5b44025 100644 (file)
@@ -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;