diff mbox series

powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties()

Message ID 20220224182312.1012527-1-danielhb413@gmail.com (mailing list archive)
State Accepted
Headers show
Series powerpc/mm/numa: skip NUMA_NO_NODE onlining in parse_numa_properties() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_kernel_qemu success Successfully ran 24 jobs.
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 7 jobs.

Commit Message

Daniel Henrique Barboza Feb. 24, 2022, 6:23 p.m. UTC
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.

Reported-by: Ping Fang <pifang@redhat.com>
Cc: Diego Domingos <diegodo@linux.vnet.ibm.com>
Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Fixes: 10f78fd0dabb ("powerpc/numa: Fix a regression on memoryless node 0")
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
 arch/powerpc/mm/numa.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michael Ellerman March 2, 2022, 12:41 p.m. UTC | #1
On Thu, 24 Feb 2022 15:23:12 -0300, Daniel Henrique Barboza wrote:
> 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.
> 
> [...]

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
diff mbox series

Patch

diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 9d5f710d2c20..b9b7fefbb64b 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -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);