Skip to contentSkip to conversation

target/ppc: use MAKE_64BIT_MASK for mcrfs exception clear mask

PATCH In review Denis Sergeev 2 participants 2 messages Sep 15, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc: use MAKE_64BIT_MASK for mcrfs exception clear mask

In gen_mcrfs() the FPSCR nibble mask is computed as:

      `~((0xF << shift) & FP_EX_CLEAR_BITS)`

Here, 0xF is of type int, so the left shift is performed in 32-bit signed arithmetic. For bfa=0 we get shift=28,
and (0xF << 28) = 0xF0000000, which is not representable as a 32-bit signed int. Static analyzers flag this as a potential integer overflow.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 target/ppc/translate/fp-impl.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/fp-impl.c.inc +1 -1
index a66b83398b..d01c0b5aba 100644
@@ -479,7 +479,7 @@ static void gen_mcrfs(DisasContext *ctx)
     tcg_gen_extu_tl_i64(tnew_fpscr, cpu_fpscr);
     /* Only the exception bits (including FX) should be cleared if read */
     tcg_gen_andi_i64(tnew_fpscr, tnew_fpscr,
-                     ~((0xF << shift) & FP_EX_CLEAR_BITS));
+                     ~(MAKE_64BIT_MASK(shift, 4) & FP_EX_CLEAR_BITS));
     /* FEX and VX need to be updated, so don't set fpscr directly */
     tmask = tcg_constant_i32(1 << nibble);
     gen_helper_store_fpscr(tcg_env, tnew_fpscr, tmask);
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 21 lines · Denis Sergeev

In gen_mcrfs() the FPSCR nibble mask is computed as:

       `~((0xF << shift) & FP_EX_CLEAR_BITS)`

Here, 0xF is of type int, so the left shift is performed in 32-bit signed arithmetic. For bfa=0 we get shift=28,
and (0xF << 28) = 0xF0000000, which is not representable as a 32-bit signed int. Static analyzers flag this as a potential integer overflow.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  target/ppc/translate/fp-impl.c.inc | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate/fp-impl.c.inc +0 -0
index a66b83398b..d01c0b5aba 100644

target/ppc/translate/fp-impl.c.inc static void gen_mcrfs(DisasContext *ctx) · line 485

Quoted 8 lines
target/ppc/translate/fp-impl.c.inc +1 -1
@@ -479,7 +479,7 @@ static void gen_mcrfs(DisasContext *ctx)
      tcg_gen_extu_tl_i64(tnew_fpscr, cpu_fpscr);
      /* Only the exception bits (including FX) should be cleared if read */
      tcg_gen_andi_i64(tnew_fpscr, tnew_fpscr,
-                     ~((0xF << shift) & FP_EX_CLEAR_BITS));
+                     ~(MAKE_64BIT_MASK(shift, 4) & FP_EX_CLEAR_BITS));
      /* FEX and VX need to be updated, so don't set fpscr directly */
      tmask = tcg_constant_i32(1 << nibble);
      gen_helper_store_fpscr(tcg_env, tnew_fpscr, tmask);

Thanks,

Chinmay