Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/sched_ext: scx_central: fix CPU_SET and skeleton leak on early exit

Use CPU_SET_S() instead of CPU_SET() on the dynamically allocated
cpuset to avoid a potential out-of-bounds write when nr_cpu_ids
exceeds CPU_SETSIZE.

Also destroy the skeleton before returning on invalid central CPU ID
to prevent a resource leak.

Signed-off-by: David Carlier <devnexen@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

David Carlier and committed by
Tejun Heo
55a24d92 07676846

+2 -1
+2 -1
tools/sched_ext/scx_central.c
··· 74 74 u32 central_cpu = strtoul(optarg, NULL, 0); 75 75 if (central_cpu >= skel->rodata->nr_cpu_ids) { 76 76 fprintf(stderr, "invalid central CPU id value, %u given (%u max)\n", central_cpu, skel->rodata->nr_cpu_ids); 77 + scx_central__destroy(skel); 77 78 return -1; 78 79 } 79 80 skel->rodata->central_cpu = (s32)central_cpu; ··· 110 109 SCX_BUG_ON(!cpuset, "Failed to allocate cpuset"); 111 110 cpuset_size = CPU_ALLOC_SIZE(skel->rodata->nr_cpu_ids); 112 111 CPU_ZERO_S(cpuset_size, cpuset); 113 - CPU_SET(skel->rodata->central_cpu, cpuset); 112 + CPU_SET_S(skel->rodata->central_cpu, cpuset_size, cpuset); 114 113 SCX_BUG_ON(sched_setaffinity(0, cpuset_size, cpuset), 115 114 "Failed to affinitize to central CPU %d (max %d)", 116 115 skel->rodata->central_cpu, skel->rodata->nr_cpu_ids - 1);