Skip to contentSkip to conversation

hw/arm/smmuv3: Assert input to oas2bits() is valid

PATCH Applied Mostafa Saleh 4 participants 4 messages Jul 22, 2024 – Jul 25, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/smmuv3: Assert input to oas2bits() is valid

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.

---
 hw/arm/smmuv3-internal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/arm/smmuv3-internal.h +2 -1
index 0ebf2eebcf..b6b7399347 100644
@@ -599,7 +599,8 @@ static inline int oas2bits(int oas_field)
     case 5:
         return 48;
     }
-    return -1;
+
+    g_assert_not_reached();
 }
 
 /* CD fields */
Signature · 1 line
2.45.2.1089.g2a221341d9-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · 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.

Quoted 6 lines
---
  hw/arm/smmuv3-internal.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by on v1 1/1
#2 lore raw
In reply to Mostafa Saleh
Quoted 10 lines · 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.

Eric

Quoted 18 lines
---
 hw/arm/smmuv3-internal.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/arm/smmuv3-internal.h +2 -1
index 0ebf2eebcf..b6b7399347 100644
@@ -599,7 +599,8 @@ static inline int oas2bits(int oas_field)
     case 5:
         return 48;
     }
-    return -1;
+
+    g_assert_not_reached();
 }
 
 /* CD fields */
#3 lore raw
In reply to Mostafa Saleh
Quoted 11 lines · 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.

Applied to target-arm.next, thanks.

-- PMM