Skip to contentSkip to conversation

target/ppc: fix potential shift overflow by using 64-bit constant

PATCH In review [email protected] 2 participants 2 messages Jul 22, 2025 – Sep 23, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/ppc: fix potential shift overflow by using 64-bit constant

From: Denis Rastyogin <[email protected]>

Change shift operand from 32-bit literal 1 to 64-bit 1ULL to avoid undefined behavior when shifting bits beyond the width of a 32-bit integer.

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

---
 target/ppc/translate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate.c +1 -1
index 27f90c3cc5..8e69c4cb48 100644
@@ -2998,7 +2998,7 @@ static void gen_fetch_inc_conditional(DisasContext *ctx, MemOp memop,
 
     /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
     tcg_gen_movcond_tl(cond, cpu_gpr[rD(ctx->opcode)], t, t2, t,
-                       tcg_constant_tl(1 << (memop_size(memop) * 8 - 1)));
+                       tcg_constant_tl(1ULL << (memop_size(memop) * 8 - 1)));
 }
 
 static void gen_ld_atomic(DisasContext *ctx, MemOp memop)
Signature · 1 line
2.42.2
Tested-by on v1 1/1
#1 lore raw
Quoted 15 lines · Denis Rastyogin

Change shift operand from 32-bit literal 1 to 64-bit 1ULL to avoid undefined behavior when shifting bits beyond the width of a 32-bit integer.

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

---
  target/ppc/translate.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/translate.c +0 -0
index 27f90c3cc5..8e69c4cb48 100644

target/ppc/translate.c static void gen_fetch_inc_conditional(DisasContext *ctx, MemOp memop, · line 3004

Quoted 8 lines
target/ppc/translate.c +1 -1
@@ -2998,7 +2998,7 @@ static void gen_fetch_inc_conditional(DisasContext *ctx, MemOp memop,
 
      /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
      tcg_gen_movcond_tl(cond, cpu_gpr[rD(ctx->opcode)], t, t2, t,
-                       tcg_constant_tl(1 << (memop_size(memop) * 8 - 1)));
+                       tcg_constant_tl(1ULL << (memop_size(memop) * 8 - 1)));
  }
 
  static void gen_ld_atomic(DisasContext *ctx, MemOp memop)

Hi Denis,
 I have tested this by applying the patch and bringing up the guest in tcg mode and it worked perfectly fine.

Qemu commandline used:

./qemu-system-ppc64 -name test -smp 8 -m 10G -vga none -nographic -accel tcg,thread=multi -device virtio-scsi-pci -drive file=/home/anu_new.qcow2,if=none,format=qcow2,id=hd0 -device scsi-hd,drive=hd0 -boot c

Came to the login prompt:

localhost login:

Tried running basic commands too on the guest, everything worked fine.

Thanks,
Anushree Mathur