qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid
@ 2024-07-22 10:35 Mostafa Saleh
  2024-07-22 10:50 ` Philippe Mathieu-Daudé
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mostafa Saleh @ 2024-07-22 10:35 UTC (permalink / raw)
  To: qemu-arm, eric.auger, peter.maydell, qemu-devel
  Cc: jean-philippe, Mostafa Saleh

Coverity has spotted a possible problem with the OAS handling
(CID 1558464), where the error return of oas2bits() -1 is not
checked, which can cause an overflow in oas value.

oas2bits() is only called with valid inputs, harden the function
to assert that.

Reported-By: Peter Maydell <peter.maydell@linaro.org>
Link: https://lore.kernel.org/qemu-devel/CAFEAcA-H=n-3mHC+eL6YjfL1m+x+b+Fk3mkgZbN74WNxifFVow@mail.gmail.com/
Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
 hw/arm/smmuv3-internal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h
index 0ebf2eebcf..b6b7399347 100644
--- a/hw/arm/smmuv3-internal.h
+++ b/hw/arm/smmuv3-internal.h
@@ -599,7 +599,8 @@ static inline int oas2bits(int oas_field)
     case 5:
         return 48;
     }
-    return -1;
+
+    g_assert_not_reached();
 }
 
 /* CD fields */
-- 
2.45.2.1089.g2a221341d9-goog



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

* Re: [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid
  2024-07-22 10:35 [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid Mostafa Saleh
@ 2024-07-22 10:50 ` Philippe Mathieu-Daudé
  2024-07-22 10:58 ` Eric Auger
  2024-07-25 14:40 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-07-22 10:50 UTC (permalink / raw)
  To: Mostafa Saleh, qemu-arm, eric.auger, peter.maydell, qemu-devel
  Cc: jean-philippe

On 22/7/24 12:35, Mostafa Saleh wrote:
> Coverity has spotted a possible problem with the OAS handling
> (CID 1558464), where the error return of oas2bits() -1 is not
> checked, which can cause an overflow in oas value.
> 
> oas2bits() is only called with valid inputs, harden the function
> to assert that.
> 
> Reported-By: Peter Maydell <peter.maydell@linaro.org>
> Link: https://lore.kernel.org/qemu-devel/CAFEAcA-H=n-3mHC+eL6YjfL1m+x+b+Fk3mkgZbN74WNxifFVow@mail.gmail.com/
> Signed-off-by: Mostafa Saleh <smostafa@google.com>
> ---
>   hw/arm/smmuv3-internal.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



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

* Re: [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid
  2024-07-22 10:35 [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid Mostafa Saleh
  2024-07-22 10:50 ` Philippe Mathieu-Daudé
@ 2024-07-22 10:58 ` Eric Auger
  2024-07-25 14:40 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Auger @ 2024-07-22 10:58 UTC (permalink / raw)
  To: Mostafa Saleh, qemu-arm, peter.maydell, qemu-devel; +Cc: jean-philippe



On 7/22/24 12:35, Mostafa Saleh wrote:
> Coverity has spotted a possible problem with the OAS handling
> (CID 1558464), where the error return of oas2bits() -1 is not
> checked, which can cause an overflow in oas value.
>
> oas2bits() is only called with valid inputs, harden the function
> to assert that.
>
> Reported-By: Peter Maydell <peter.maydell@linaro.org>
> Link: https://lore.kernel.org/qemu-devel/CAFEAcA-H=n-3mHC+eL6YjfL1m+x+b+Fk3mkgZbN74WNxifFVow@mail.gmail.com/
> Signed-off-by: Mostafa Saleh <smostafa@google.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  hw/arm/smmuv3-internal.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/arm/smmuv3-internal.h b/hw/arm/smmuv3-internal.h
> index 0ebf2eebcf..b6b7399347 100644
> --- a/hw/arm/smmuv3-internal.h
> +++ b/hw/arm/smmuv3-internal.h
> @@ -599,7 +599,8 @@ static inline int oas2bits(int oas_field)
>      case 5:
>          return 48;
>      }
> -    return -1;
> +
> +    g_assert_not_reached();
>  }
>  
>  /* CD fields */



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

* Re: [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid
  2024-07-22 10:35 [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid Mostafa Saleh
  2024-07-22 10:50 ` Philippe Mathieu-Daudé
  2024-07-22 10:58 ` Eric Auger
@ 2024-07-25 14:40 ` Peter Maydell
  2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2024-07-25 14:40 UTC (permalink / raw)
  To: Mostafa Saleh; +Cc: qemu-arm, eric.auger, qemu-devel, jean-philippe

On Mon, 22 Jul 2024 at 11:35, Mostafa Saleh <smostafa@google.com> wrote:
>
> Coverity has spotted a possible problem with the OAS handling
> (CID 1558464), where the error return of oas2bits() -1 is not
> checked, which can cause an overflow in oas value.
>
> oas2bits() is only called with valid inputs, harden the function
> to assert that.
>
> Reported-By: Peter Maydell <peter.maydell@linaro.org>
> Link: https://lore.kernel.org/qemu-devel/CAFEAcA-H=n-3mHC+eL6YjfL1m+x+b+Fk3mkgZbN74WNxifFVow@mail.gmail.com/
> Signed-off-by: Mostafa Saleh <smostafa@google.com>



Applied to target-arm.next, thanks.

-- PMM


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

end of thread, other threads:[~2024-07-25 14:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-22 10:35 [PATCH] hw/arm/smmuv3: Assert input to oas2bits() is valid Mostafa Saleh
2024-07-22 10:50 ` Philippe Mathieu-Daudé
2024-07-22 10:58 ` Eric Auger
2024-07-25 14:40 ` Peter Maydell

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).