qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/ppc: use MAKE_64BIT_MASK for mcrfs exception clear mask
@ 2025-09-15  8:01 Denis Sergeev
  2025-09-15 14:04 ` Chinmay Rath
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Sergeev @ 2025-09-15  8:01 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-ppc, npiggin, rathc, zeff

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.

Signed-off-by: Denis Sergeev <zeff@altlinux.org>
---
 target/ppc/translate/fp-impl.c.inc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/ppc/translate/fp-impl.c.inc b/target/ppc/translate/fp-impl.c.inc
index a66b83398b..d01c0b5aba 100644
--- a/target/ppc/translate/fp-impl.c.inc
+++ b/target/ppc/translate/fp-impl.c.inc
@@ -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);
-- 
2.50.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] target/ppc: use MAKE_64BIT_MASK for mcrfs exception clear mask
  2025-09-15  8:01 [PATCH] target/ppc: use MAKE_64BIT_MASK for mcrfs exception clear mask Denis Sergeev
@ 2025-09-15 14:04 ` Chinmay Rath
  0 siblings, 0 replies; 2+ messages in thread
From: Chinmay Rath @ 2025-09-15 14:04 UTC (permalink / raw)
  To: Denis Sergeev, qemu-devel; +Cc: qemu-ppc, npiggin, harshpb


On 9/15/25 13:31, Denis Sergeev wrote:
> 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.
>
> Signed-off-by: Denis Sergeev <zeff@altlinux.org>
> ---
>   target/ppc/translate/fp-impl.c.inc | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/ppc/translate/fp-impl.c.inc b/target/ppc/translate/fp-impl.c.inc
> index a66b83398b..d01c0b5aba 100644
> --- a/target/ppc/translate/fp-impl.c.inc
> +++ b/target/ppc/translate/fp-impl.c.inc
> @@ -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);
Reviewed-by: Chinmay Rath <rathc@linux.ibm.com>

Thanks,

Chinmay



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-15 14:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15  8:01 [PATCH] target/ppc: use MAKE_64BIT_MASK for mcrfs exception clear mask Denis Sergeev
2025-09-15 14:04 ` Chinmay Rath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).