Re: [PATCH v2] arch_numa: Avoid false positive fortify warning in setup_node_to_cpumask_map()
From: Mike Rapoport
Date: Sun Aug 16 2026 - 05:59:17 EST
On Thu, Aug 13, 2026 at 08:12:55PM -0700, Nathan Chancellor wrote:
> When building ARCH=riscv using clang with CONFIG_FORTIFY_SOURCE and
> CONFIG_UBSAN_BOUNDS enabled, CONFIG_NR_CPUS > 64, and the default value
> of 2 for CONFIG_NODES_SHIFT, there is a compiletime warning from the
> fortify routines.
>
> In this configuration, MAX_NUMNODES is 4. clang unrolls the for loop in
> setup_node_to_cpumask_map() past this, which triggers the fortify check
> when accessing node_to_cpumask_map on the theoretical fifth loop
> iteration because it would be an out of bounds write.
>
> Make it clear to clang that nr_node_ids is bounded by MAX_NUMNODES due
> to the logic in setup_nr_node_ids() by early returning in
> setup_node_to_cpumask_map() should that condition be violated.
>
> Cc: stable@xxxxxxxxxxxxxxx # all applicable
> Closes: https://github.com/ClangBuiltLinux/linux/issues/2174
> Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> ---
> mm/arch_numa.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
--
Sincerely yours,
Mike.