Skip to content

Commit 2a06426

Browse files
devnexenhtejun
authored andcommitted
sched_ext: Fix out-of-bounds access in scx_idle_init_masks()
scx_idle_node_masks is allocated with num_possible_nodes() elements but indexed by NUMA node IDs via for_each_node(). On systems with non-contiguous NUMA node numbering (e.g. nodes 0 and 4), node IDs can exceed the array size, causing out-of-bounds memory corruption. Use nr_node_ids instead, which represents the maximum node ID range and is the correct size for arrays indexed by node ID. Fixes: 7c60329e3521 ("sched_ext: Add NUMA-awareness to the default idle selection policy") Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 83236b2 commit 2a06426

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/sched/ext_idle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,8 +663,8 @@ void scx_idle_init_masks(void)
663663
BUG_ON(!alloc_cpumask_var(&scx_idle_global_masks.cpu, GFP_KERNEL));
664664
BUG_ON(!alloc_cpumask_var(&scx_idle_global_masks.smt, GFP_KERNEL));
665665

666-
/* Allocate per-node idle cpumasks */
667-
scx_idle_node_masks = kcalloc(num_possible_nodes(),
666+
/* Allocate per-node idle cpumasks (use nr_node_ids for non-contiguous NUMA nodes) */
667+
scx_idle_node_masks = kcalloc(nr_node_ids,
668668
sizeof(*scx_idle_node_masks), GFP_KERNEL);
669669
BUG_ON(!scx_idle_node_masks);
670670

0 commit comments

Comments
 (0)