Skip to contentSkip to conversation

hw/net/vmxnet3: Fix guest-triggerable assert()

PATCH In review Thomas Huth 3 participants 3 messages Aug 17, 2023 – Sep 7, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/net/vmxnet3: Fix guest-triggerable assert()

The assert() that checks for valid MTU sizes can be triggered by the guest (e.g. with the reproducer code from the bug ticket
https://gitlab.com/qemu-project/qemu/-/issues/517 ). Let's avoid this problem by simply logging the error and refusing to activate the device instead.

Fixes d05dcd94ae ("net: vmxnet3: validate configuration values during activate")
---
 hw/net/vmxnet3.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/net/vmxnet3.c +4 -1
index 5dfacb1098..6674122a7e 100644
@@ -1439,7 +1439,10 @@ static void vmxnet3_activate_device(VMXNET3State *s)
     vmxnet3_setup_rx_filtering(s);
     /* Cache fields from shared memory */
     s->mtu = VMXNET3_READ_DRV_SHARED32(d, s->drv_shmem, devRead.misc.mtu);
-    assert(VMXNET3_MIN_MTU <= s->mtu && s->mtu <= VMXNET3_MAX_MTU);
+    if (s->mtu < VMXNET3_MIN_MTU || s->mtu > VMXNET3_MAX_MTU) {
+        qemu_log_mask(LOG_GUEST_ERROR, "vmxnet3: Bad MTU size: %d\n", s->mtu);
+        return;
+    }
     VMW_CFPRN("MTU is %u", s->mtu);
 
     s->max_rx_frags =
Signature · 1 line
2.39.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Thomas,

Quoted 17 lines · Thomas Huth

The assert() that checks for valid MTU sizes can be triggered by the guest (e.g. with the reproducer code from the bug ticket
https://gitlab.com/qemu-project/qemu/-/issues/517 ). Let's avoid this problem by simply logging the error and refusing to activate the device instead.

Fixes d05dcd94ae ("net: vmxnet3: validate configuration values during activate")
---
  hw/net/vmxnet3.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/net/vmxnet3.c +0 -0
index 5dfacb1098..6674122a7e 100644

hw/net/vmxnet3.c static void vmxnet3_activate_device(VMXNET3State *s) · line 1443

Quoted 6 lines
hw/net/vmxnet3.c +2 -1
@@ -1439,7 +1439,10 @@ static void vmxnet3_activate_device(VMXNET3State *s)
      vmxnet3_setup_rx_filtering(s);
      /* Cache fields from shared memory */
      s->mtu = VMXNET3_READ_DRV_SHARED32(d, s->drv_shmem, devRead.misc.mtu);
-    assert(VMXNET3_MIN_MTU <= s->mtu && s->mtu <= VMXNET3_MAX_MTU);
+    if (s->mtu < VMXNET3_MIN_MTU || s->mtu > VMXNET3_MAX_MTU) {
+        qemu_log_mask(LOG_GUEST_ERROR, "vmxnet3: Bad MTU size: %d\n", s->mtu);

mtu is uint32_t, otherwise:

Quoted 5 lines
hw/net/vmxnet3.c +2 -0
+        return;
+    }
      VMW_CFPRN("MTU is %u", s->mtu);
 
      s->max_rx_frags =
#2 lore raw
In reply to Thomas Huth
Quoted 5 lines · Thomas Huth

The assert() that checks for valid MTU sizes can be triggered by the guest (e.g. with the reproducer code from the bug ticket
https://gitlab.com/qemu-project/qemu/-/issues/517 ). Let's avoid this problem by simply logging the error and refusing to activate the device instead.

I'm applying this to trivial-patches tree with some hesitation :)

Thanks,

/mjt

Quoted 22 lines
Fixes d05dcd94ae ("net: vmxnet3: validate configuration values during activate")
---
  hw/net/vmxnet3.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
hw/net/vmxnet3.c +4 -1
index 5dfacb1098..6674122a7e 100644
@@ -1439,7 +1439,10 @@ static void vmxnet3_activate_device(VMXNET3State *s)
      vmxnet3_setup_rx_filtering(s);
      /* Cache fields from shared memory */
      s->mtu = VMXNET3_READ_DRV_SHARED32(d, s->drv_shmem, devRead.misc.mtu);
-    assert(VMXNET3_MIN_MTU <= s->mtu && s->mtu <= VMXNET3_MAX_MTU);
+    if (s->mtu < VMXNET3_MIN_MTU || s->mtu > VMXNET3_MAX_MTU) {
+        qemu_log_mask(LOG_GUEST_ERROR, "vmxnet3: Bad MTU size: %d\n", s->mtu);
+        return;
+    }
      VMW_CFPRN("MTU is %u", s->mtu);
 
      s->max_rx_frags =