target/ppc: fix potential shift overflow by using 64-bit constant
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
@@ -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
Quoted 15 lines · Denis Rastyogin
Change shift operand from 32-bit literal
1to 64-bit1ULLto avoid undefined behavior when shifting bits beyond the width of a 32-bit integer.Found by Linux Verification Center (linuxtesting.org) with SVACE.
Signed-off-by Denis Rastyogin <[email protected]>--- target/ppc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/ppc/translate.c +0
-0
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