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

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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, which has a size of 236 (0x3AC), may lead to a buffer overflow if the 'offset' index exceeds the valid range, potentially reaching values up to 5139 (0x504C >> 2). Therefore, the bounds check has been extended to DP_CORE_REG_ARRAY_SIZE (0x3B0 >> 2). This change addresses a potential vulnerability by ensuring the offset stays within the valid range before writing data.

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

---
 hw/display/xlnx_dp.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/display/xlnx_dp.c +5 -1
index 6ab2335499..3f1f5d81bd 100644
@@ -896,7 +896,11 @@ static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value,
         xlnx_dp_update_irq(s);
         break;
     default:
-        assert(offset <= (0x504C >> 2));
+        /*
+         * Check to ensure the offset is within the bounds of
+         * the core_registers[] array.
+        */
+        assert(offset < DP_CORE_REG_ARRAY_SIZE);
         s->core_registers[offset] = value;
         break;
     }
Signature · 1 line
2.42.2
#1 lore raw
Quoted 23 lines · On 12/12/24 10:01, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

Accessing an element of the s->core_registers array, which has a size of 236 (0x3AC), may lead to a buffer overflow if the 'offset' index exceeds the valid range, potentially reaching values up to 5139 (0x504C >> 2). Therefore, the bounds check has been extended to DP_CORE_REG_ARRAY_SIZE (0x3B0 >> 2). This change addresses a potential vulnerability by ensuring the offset stays within the valid range before writing data.

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

---
  hw/display/xlnx_dp.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/display/xlnx_dp.c +0 -0
index 6ab2335499..3f1f5d81bd 100644

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

Quoted 9 lines
hw/display/xlnx_dp.c +5 -1
@@ -896,7 +896,11 @@ static void xlnx_dp_write(void *opaque, hwaddr offset, uint64_t value,
          xlnx_dp_update_irq(s);
          break;
      default:
-        assert(offset <= (0x504C >> 2));
+        /*
+         * Check to ensure the offset is within the bounds of
+         * the core_registers[] array.
+        */
+        assert(offset < DP_CORE_REG_ARRAY_SIZE);

More accurately,

The memory region is registered to match the size of the core_registers array. The guest cannot issue an out-of-bounds write.

And that's why this can be an assertion instead of needing to issue an error to the guest.

r~