[PATCH v1] powerpc: Fix off-by-one in AT_HWCAP4 loop in _dl_procinfo

Florian Weimer fweimer@redhat.com
Mon Oct 12 14:48:01 GMT 2026


* Sachin Monga:

> The AT_HWCAP4 case loops "i <= _DL_HWCAP_SIZE" instead of
> "i < _DL_HWCAP_SIZE" like the other three HWCAP cases, so at i == 32
> it evaluates the UB expression "1 << 32" and would index one past
> the end of _dl_powerpc_cap_flags.  LD_SHOW_AUXV=1 on POWER10/POWER11
> unconditionally runs this path, so the UB fires on any such system
> regardless of the actual hwcap value.  No AT_HWCAP4 bit is currently
> assigned, so the out-of-bounds read itself is never reached.
>
> Fixes: 3ab9b88e2a ("powerpc: Add HWCAP3/HWCAP4 data to TCB for Power Architecture.")
> ---
> Stable-only: release/2.39, 2.40, 2.41. Trunk removed this code in
> 8a995670a8 (table-driven dl-hwcap-info.c), hence no trunk commit.
>
> i <= _DL_HWCAP_SIZE should be <; at i==32, "1 << 32" is UB and indexes
> past _dl_powerpc_cap_flags[128]. Latent: no PPC_FEATURE4_* bit exists,
> and LD_SHOW_AUXV=1 on POWER10 hw shows no AT_HWCAP3/4 line yet. Fires
> unconditionally once the kernel emits an AT_HWCAP4 entry.
>
> Reg test isn't needed here but still I did a round at 2.41.
> Let me know if it is ok to proceed and push it across 2.41, 2.40 and
> 2.39
>
>  sysdeps/powerpc/dl-procinfo.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/powerpc/dl-procinfo.h b/sysdeps/powerpc/dl-procinfo.h
> index 585ce41226..abbf1b1fd0 100644
> --- a/sysdeps/powerpc/dl-procinfo.h
> +++ b/sysdeps/powerpc/dl-procinfo.h
> @@ -219,7 +219,7 @@ _dl_procinfo (unsigned int type, unsigned long int word)
>  
>         /* We have to go through them all because the kernel added the
>  	  AT_HWCAP4 features starting with the high bits.  */
> -       for (int i = 0; i <= _DL_HWCAP_SIZE; ++i)
> +       for (int i = 0; i < _DL_HWCAP_SIZE; ++i)
>  	 if (word & (1 << i))
>  	   _dl_printf (" %s", _dl_hwcap_string (_DL_HWCAP4_OFFSET + i));
>         break;

This looks lokay to me, thanks.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Florian



More information about the Libc-stable mailing list