]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tools/sched_ext: scx_central: fix sched_setaffinity() call with the set size
authorDavid Carlier <devnexen@gmail.com>
Wed, 11 Feb 2026 21:30:27 +0000 (21:30 +0000)
committerTejun Heo <tj@kernel.org>
Thu, 12 Feb 2026 17:30:17 +0000 (07:30 -1000)
The cpu set is dynamically allocated for nr_cpu_ids using CPU_ALLOC(),
so the size passed to sched_setaffinity() should be CPU_ALLOC_SIZE()
rather than sizeof(cpu_set_t). Valgrind flagged this as accessing
unaddressable bytes past the allocation.

Signed-off-by: David Carlier <devnexen@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/sched_ext/scx_central.c

index 55931a4cd71c7c9c0eee7d44ddb0f1861f780cfd..a6dfd45de70ce28c845a2118d3b3538ef9945e91 100644 (file)
@@ -50,6 +50,7 @@ int main(int argc, char **argv)
        __u64 seq = 0, ecode;
        __s32 opt;
        cpu_set_t *cpuset;
+       size_t cpuset_size;
 
        libbpf_set_print(libbpf_print_fn);
        signal(SIGINT, sigint_handler);
@@ -106,9 +107,10 @@ restart:
         */
        cpuset = CPU_ALLOC(skel->rodata->nr_cpu_ids);
        SCX_BUG_ON(!cpuset, "Failed to allocate cpuset");
-       CPU_ZERO_S(CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids), cpuset);
+       cpuset_size = CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids);
+       CPU_ZERO_S(cpuset_size, cpuset);
        CPU_SET(skel->rodata->central_cpu, cpuset);
-       SCX_BUG_ON(sched_setaffinity(0, sizeof(*cpuset), cpuset),
+       SCX_BUG_ON(sched_setaffinity(0, cpuset_size, cpuset),
                   "Failed to affinitize to central CPU %d (max %d)",
                   skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1);
        CPU_FREE(cpuset);