]> git.baikalelectronics.ru Git - kernel.git/commit
powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties()
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Thu, 24 Feb 2022 18:23:12 +0000 (15:23 -0300)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 1 Mar 2022 12:41:01 +0000 (23:41 +1100)
commit055b58e2d63054c711fd132e02f739ec360e2bfd
tree176f9a19e4bf1ff4e23179a3f80e1716a2027feb
parent645d693ecbc8cd8cb968223a77fdd2e5595f64a5
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 fba7e7eafe31 ("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.

Fixes: fba7e7eafe31 ("powerpc/numa: Fix a regression on memoryless node 0")
Reported-by: Ping Fang <pifang@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220224182312.1012527-1-danielhb413@gmail.com
arch/powerpc/mm/numa.c