Skip to contentSkip to conversation

hw/i3c: Fix array bounds and storage in i3c_addr_is_rsvd()

PATCH In review Cédric Le Goater 3 participants 3 messages Mar 2 – Mar 3

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/i3c: Fix array bounds and storage in i3c_addr_is_rsvd()

The size of the is_rsvd lookup table in i3c_addr_is_rsvd() is 255 but should be 256 to cover all possible uint8_t address values and avoid potential out-of-bounds access.

The array should be static too as it's a constant lookup table.

---
 hw/i3c/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i3c/core.c +1 -1
index 8a37099ce3ff..0a266e00a279 100644
@@ -525,7 +525,7 @@ int i3c_target_ibi_finish(I3CTarget *t, uint8_t data)
 
 static bool i3c_addr_is_rsvd(uint8_t addr)
 {
-    const bool is_rsvd[255] = {
+    static const bool is_rsvd[256] = {
         [0x00] = true,
         [0x01] = true,
         [0x02] = true,
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Cédric Le Goater

The size of the is_rsvd lookup table in i3c_addr_is_rsvd() is 255 but should be 256 to cover all possible uint8_t address values and avoid potential out-of-bounds access.

The array should be static too as it's a constant lookup table.

---
 hw/i3c/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i3c/core.c +0 -0
index 8a37099ce3ff..0a266e00a279 100644

hw/i3c/core.c int i3c_target_ibi_finish(I3CTarget *t, uint8_t data) · line 528

Quoted 5 lines
hw/i3c/core.c +1 -1
@@ -525,7 +525,7 @@ int i3c_target_ibi_finish(I3CTarget *t, uint8_t data)
 
 static bool i3c_addr_is_rsvd(uint8_t addr)
 {
-    const bool is_rsvd[255] = {
+    static const bool is_rsvd[256] = {

Given that we're using hex addressing for the values in is_rsvd, could we make the size 0xff so it maintains the same formatting? Otherwise, it looks good to me.

Quoted 6 lines
hw/i3c/core.c +0 -1
         [0x00] = true,
         [0x01] = true,
         [0x02] = true,
--

2.53.0

Reviewed-by on v1 1/1
#2 lore raw
In reply to Cédric Le Goater
Quoted 26 lines

Subject: [PATCH] hw/i3c: Fix array bounds and storage in i3c_addr_is_rsvd()

The size of the is_rsvd lookup table in i3c_addr_is_rsvd() is 255 but should be 256 to cover all possible uint8_t address values and avoid potential out-of-bounds access.

The array should be static too as it's a constant lookup table.

---
 hw/i3c/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i3c/core.c index 8a37099ce3ff..0a266e00a279 renamed from hw/i3c/core.c +0 -0

100644

hw/i3c/core.c +1 -2
@@ -525,7 +525,7 @@ int i3c_target_ibi_finish(I3CTarget *t, uint8_t data)
 
 static bool i3c_addr_is_rsvd(uint8_t addr)  {
-    const bool is_rsvd[255] = {
+    static const bool is_rsvd[256] = {
         [0x00] = true,
         [0x01] = true,
         [0x02] = true,
--
Quoted 1 line

2.53.0

Thanks,
Jamin