Skip to contentSkip to conversation

hw/net: fix rx_desc_len on migration load

PATCH Superseded Laurent Vivier 3 participants 7 messages Jul 21

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hw/net: fix rx_desc_len on migration load

rx_desc_len is migrated as a raw uint8_t from the stream in both e1000e and igb, but it is a derived value that can be computed from the register state. A crafted migration stream can set rx_desc_len to an invalid value, causing a stack buffer overflow in e1000e_write_packet_to_guest() which copies rx_desc_len bytes into a 32-byte stack union.

Recalculate rx_desc_len from the register state in post_load, ignoring the untrusted value from the stream.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869

Laurent Vivier (2):
hw/net/e1000e: recalculate rx_desc_len on migration load hw/net/igb: recalculate rx_desc_len on migration load

 hw/net/e1000e_core.c | 2 ++
 hw/net/igb_core.c    | 2 ++
 2 files changed, 4 insertions(+)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 hw/net/e1000e: recalculate rx_desc_len on migration load

rx_desc_len is migrated as a raw uint8_t from the stream, but it is a derived value that can be computed from the register state in core.mac[RCTL]. A crafted migration stream can set rx_desc_len to an invalid value (e.g. 64), causing a stack buffer overflow in e1000e_write_packet_to_guest() which copies rx_desc_len bytes into a 32-byte stack union.

Recalculate rx_desc_len from the register state in post_load, ignoring the untrusted value from the stream.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869

---
 hw/net/e1000e_core.c | 2 ++
 1 file changed, 2 insertions(+)
hw/net/e1000e_core.c +2 -0
index 46e156a5ddc2..31eb39e4aa40 100644
@@ -3557,5 +3557,7 @@ e1000e_core_post_load(E1000ECore *core)
     e1000e_intrmgr_resume(core);
     e1000e_autoneg_resume(core);
 
+    e1000e_calc_rxdesclen(core);
+
     return 0;
 }
Signature · 1 line
2.54.0
#2 lore raw

Re: [PATCH 1/2] hw/net/e1000e: recalculate rx_desc_len on migration load

Quoted 6 lines · Laurent Vivier

rx_desc_len is migrated as a raw uint8_t from the stream, but it is a derived value that can be computed from the register state in core.mac[RCTL]. A crafted migration stream can set rx_desc_len to an invalid value (e.g. 64), causing a stack buffer overflow in e1000e_write_packet_to_guest() which copies rx_desc_len bytes into a 32-byte stack union.

The value is derived from core.mac[RFCTL] and core.mac[RCTL], not solely core.mac[RCTL].

The change itself looks good to me.

Regards,
Akihiko Odaki

Quoted 23 lines

Recalculate rx_desc_len from the register state in post_load, ignoring the untrusted value from the stream.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869

---
  hw/net/e1000e_core.c | 2 ++
  1 file changed, 2 insertions(+)
hw/net/e1000e_core.c +2 -0
index 46e156a5ddc2..31eb39e4aa40 100644
@@ -3557,5 +3557,7 @@ e1000e_core_post_load(E1000ECore *core)
      e1000e_intrmgr_resume(core);
      e1000e_autoneg_resume(core);
 
+    e1000e_calc_rxdesclen(core);
+
      return 0;
  }
#3 lore raw

Re: [PATCH 1/2] hw/net/e1000e: recalculate rx_desc_len on migration load

In reply to Laurent Vivier
Quoted 22 lines · Laurent Vivier

rx_desc_len is migrated as a raw uint8_t from the stream, but it is a derived value that can be computed from the register state in core.mac[RCTL]. A crafted migration stream can set rx_desc_len to an invalid value (e.g. 64), causing a stack buffer overflow in e1000e_write_packet_to_guest() which copies rx_desc_len bytes into a 32-byte stack union.

Recalculate rx_desc_len from the register state in post_load, ignoring the untrusted value from the stream.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869

---
  hw/net/e1000e_core.c | 2 ++
  1 file changed, 2 insertions(+)
hw/net/e1000e_core.c +0 -0
index 46e156a5ddc2..31eb39e4aa40 100644

hw/net/e1000e_core.c e1000e_core_post_load(E1000ECore *core) · line 3560

Quoted 4 lines
hw/net/e1000e_core.c +1 -0
@@ -3557,5 +3557,7 @@ e1000e_core_post_load(E1000ECore *core)
      e1000e_intrmgr_resume(core);
      e1000e_autoneg_resume(core);
 
+    e1000e_calc_rxdesclen(core);

e1000e_set_rx_control()
e1000e has similar derived values in rxbuf_min_shift, rxbuf_sizes[], and rx_desc_buf_size, and e1000e_set_rx_control() computes it in sequence:

    e1000e_parse_rxbufsize(core);
    e1000e_calc_rxdesclen(core);
    core->rxbuf_min_shift = ((val / E1000_RCTL_RDMTS_QUAT) & 3) + 1 +
                                E1000_RING_DESC_LEN_SHIFT;

I suggest creating a function to replicate this sequence for e1000e_core_post_load() instead of only calling e1000e_calc_rxdesclen().

Regards,
Akihiko Odaki

Quoted 3 lines
hw/net/e1000e_core.c +1 -0
+
      return 0;
  }
#4 lore raw

PATCH 2/2 hw/net/igb: recalculate rx_desc_len on migration load

In reply to Laurent Vivier

Same issue as e1000e: rx_desc_len is migrated from the stream but can be computed from the register state. Recalculate it in post_load to prevent a crafted migration stream from setting an invalid value.

---
 hw/net/igb_core.c | 2 ++
 1 file changed, 2 insertions(+)
hw/net/igb_core.c +2 -0
index 45d8fd795b84..2a4883907353 100644
@@ -4548,5 +4548,7 @@ igb_core_post_load(IGBCore *core)
     igb_intrmgr_resume(core);
     igb_autoneg_resume(core);
 
+    igb_calc_rxdesclen(core);
+
     return 0;
 }
Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH 2/2] hw/net/igb: recalculate rx_desc_len on migration load

Quoted 3 lines · Laurent Vivier

Same issue as e1000e: rx_desc_len is migrated from the stream but can be computed from the register state. Recalculate it in post_load to prevent a crafted migration stream from setting an invalid value.

igb actually doesn't use the register state. igb_calc_rxdesclen() calls igb_rx_use_legacy_descriptor() to determine the value, but igb_rx_use_legacy_descriptor() is currently a stub and returns false.

The change itself is fine.

Regards,
Akihiko Odaki

Quoted 19 lines
---
  hw/net/igb_core.c | 2 ++
  1 file changed, 2 insertions(+)
hw/net/igb_core.c +2 -0
index 45d8fd795b84..2a4883907353 100644
@@ -4548,5 +4548,7 @@ igb_core_post_load(IGBCore *core)
      igb_intrmgr_resume(core);
      igb_autoneg_resume(core);
 
+    igb_calc_rxdesclen(core);
+
      return 0;
  }
Reviewed-by on the v1 series
#6 lore raw
In reply to Laurent Vivier
Quoted 12 lines · Laurent Vivier

rx_desc_len is migrated as a raw uint8_t from the stream in both e1000e and igb, but it is a derived value that can be computed from the register state. A crafted migration stream can set rx_desc_len to an invalid value, causing a stack buffer overflow in e1000e_write_packet_to_guest() which copies rx_desc_len bytes into a 32-byte stack union.

Recalculate rx_desc_len from the register state in post_load, ignoring the untrusted value from the stream.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869

Quoted 7 lines

Laurent Vivier (2):
hw/net/e1000e: recalculate rx_desc_len on migration load hw/net/igb: recalculate rx_desc_len on migration load

  hw/net/e1000e_core.c | 2 ++
  hw/net/igb_core.c    | 2 ++
  2 files changed, 4 insertions(+)

Series: