Skip to contentSkip to conversation

hw/display: refine upper limit for offset value in assert check

PATCH Superseded [email protected] 2 participants 2 messages Dec 12, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/display: refine upper limit for offset value in assert check

From: Denis Rastyogin <[email protected]>

Accessing an element of the s->core_registers array with a size of 236 (0x3AC) may lead to a buffer overflow, as the index 'offset' can exceed the valid range and reach values up to 5139 (0x504C >> 2). This change addresses
a potential vulnerability when writing data.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 hw/display/xlnx_dp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/xlnx_dp.c +1 -1
index 6ab2335499..69ccc7ccc2 100644
@@ -743,6 +743,7 @@ static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value,
     DPRINTF("core write @%" PRIx64 " = 0x%8.8" PRIX64 "\n", offset, value);
 
     offset = offset >> 2;
+    assert(offset <= (0x3AC >> 2));
 
     switch (offset) {
     /*
@@ -896,7 +897,6 @@ static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value,
         xlnx_dp_update_irq(s);
         break;
     default:
-        assert(offset <= (0x504C >> 2));
         s->core_registers[offset] = value;
         break;
     }
Signature · 1 line
2.42.2
#1 lore raw
Quoted 29 lines · On 12/12/24 05:45, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

Accessing an element of the s->core_registers array with a size of 236 (0x3AC) may lead to a buffer overflow, as the index 'offset' can exceed the valid range and reach values up to 5139 (0x504C >> 2). This change addresses
a potential vulnerability when writing data.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  hw/display/xlnx_dp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/display/xlnx_dp.c +1 -0
index 6ab2335499..69ccc7ccc2 100644
@@ -743,6 +743,7 @@ static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value,
      DPRINTF("core write @%" PRIx64 " = 0x%8.8" PRIX64 "\n", offset, value);
 
      offset = offset >> 2;
+    assert(offset <= (0x3AC >> 2));
 
      switch (offset) {
      /*

hw/display/xlnx_dp.c static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value, · line 902

Quoted 7 lines
hw/display/xlnx_dp.c +0 -1
@@ -896,7 +897,6 @@ static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value,
          xlnx_dp_update_irq(s);
          break;
      default:
-        assert(offset <= (0x504C >> 2));
          s->core_registers[offset] = value;
          break;
      }

Why are you moving the assert? The switch statement takes care of sorting non-default values of offset.

More correct would be to use DP_CORE_REG_ARRAY_SIZE in the assert, along with a comment that the io region has been sized exactly to fit core_registers[].

r~