powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties()
PATCH 1/1 powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties()
Executing node_set_online() when nid = NUMA_NO_NODE results in an undefined behavior. node_set_online() will call node_set_state(), into __node_set(), into set_bit(), and since NUMA_NO_NODE is -1 we'll end up doing a negative shift operation inside arch/powerpc/include/asm/bitops.h. This potential UB was detected running a kernel with CONFIG_UBSAN.
The behavior was introduced by commit 10f78fd0dabb ("powerpc/numa: Fix a regression on memoryless node 0"), where the check for nid > 0 was removed to fix a problem that was happening with nid = 0, but the result is that now we're trying to online NUMA_NO_NODE nids as well.
Checking for nid >= 0 will allow node 0 to be onlined while avoiding this UB with NUMA_NO_NODE.
--- arch/powerpc/mm/numa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/mm/numa.c +3 -1
@@ -956,7 +956,9 @@ static int __init parse_numa_properties(void)of_node_put (cpu); } -node_set_online (nid); +/* node_set_online() is an UB if 'nid' is negative */ +if (likely (nid >=0 )) +node_set_online (nid); }get_n_mem_cells (&n_mem_addr_cells, &n_mem_size_cells);
Signature · 1 line
2.35.1
Michael Ellerman
AppliedQuoted 8 lines · Daniel Henrique Barboza
Executing
node_set_online()when nid =NUMA_NO_NODEresults in an undefined behavior.node_set_online()will callnode_set_state(), into__node_set(), intoset_bit(), and sinceNUMA_NO_NODEis -1 we'll end up doing a negative shift operation insidearch/powerpc/include/asm/bitops.h. This potential UB was detected running a kernel withCONFIG_UBSAN.[...]
Applied to powerpc/next.
[1/1] powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties()
https://git.kernel.org/powerpc/c/749ed4a20657bcea66a6e082ca3dc0d228cbec80
cheers