hw/net: fix rx_desc_len on migration load
v2 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
v2:
- extract e1000e_calc_rxconf() to recalculate all derived RX values
- fix commit message to mention both RFCTL and RCTL
- fix commit message to note that igb_rx_use_legacy_descriptor() is currently a stub
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 | 18 +++++++++++++----- hw/net/igb_core.c | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-)
Signature · 1 line
2.54.0
PATCH v2 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[RFCTL] and 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 and other derived values from the register state in post_load, ignoring the untrusted values from the stream.
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869
--- hw/net/e1000e_core.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
hw/net/e1000e_core.c +13 -5
@@ -1948,6 +1948,16 @@ e1000e_calc_rxdesclen(E1000ECore *core)trace_e1000e_rx_desc_len (core->rx_desc_len); } +static void +e1000e_calc_rxconf (E1000ECore *core) +{ +e1000e_parse_rxbufsize (core); +e1000e_calc_rxdesclen (core); + core->rxbuf_min_shift = + ((core->mac[RCTL ] /E1000_RCTL_RDMTS_QUAT ) &3 ) +1 + +E1000_RING_DESC_LEN_SHIFT ; +} +static void e1000e_set_rx_control (E1000ECore *core,int index,uint32_t val) {
@@ -1955,11 +1965,7 @@ e1000e_set_rx_control(E1000ECore *core, int index, uint32_t val)trace_e1000e_rx_set_rctl (core->mac[RCTL ]);if (val &E1000_RCTL_EN ) { -e1000e_parse_rxbufsize (core); -e1000e_calc_rxdesclen (core); - core->rxbuf_min_shift = ((val /E1000_RCTL_RDMTS_QUAT ) &3 ) +1 + -E1000_RING_DESC_LEN_SHIFT ; - +e1000e_calc_rxconf (core);e1000e_start_recv (core); } }
@@ -3557,5 +3563,7 @@ e1000e_core_post_load(E1000ECore *core)e1000e_intrmgr_resume (core);e1000e_autoneg_resume (core); +e1000e_calc_rxconf (core); +return 0 ; }
Signature · 1 line
2.54.0
PATCH v2 2/2 hw/net/igb: recalculate rx_desc_len on migration load
In reply to Laurent Vivierrx_desc_len is migrated as a raw uint8_t from the stream but is a derived value. Currently igb_rx_use_legacy_descriptor() is a stub that always returns false, so rx_desc_len is always set to sizeof(union e1000_adv_rx_desc). 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
@@ -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
Quoted 17 lines · Laurent Vivier
rx_desc_lenis migrated as a rawuint8_tfrom 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 setrx_desc_lento an invalid value, causing a stack buffer overflow ine1000e_write_packet_to_guest()which copiesrx_desc_lenbytes into a 32-byte stack union.Recalculate
rx_desc_lenfrom the register state inpost_load, ignoring the untrusted value from the stream.Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869>
v2:
- extracte1000e_calc_rxconf()to recalculate all derived RX values
- fix commit message to mention both RFCTL and RCTL
- fix commit message to note thatigb_rx_use_legacy_descriptor()is currently a stub
Quoted 8 lines
Laurent Vivier (2):
hw/net/e1000e: recalculaterx_desc_lenon migration load hw/net/igb: recalculaterx_desc_lenon migration loadhw/net/e1000e_core.c | 18 +++++++++++++----- hw/net/igb_core.c | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-)
For the whole series,
Regards,
Akihiko Odaki
Philippe Mathieu-Daudé
AppliedQuoted 7 lines · Laurent Vivier
Laurent Vivier (2):
hw/net/e1000e: recalculaterx_desc_lenon migration load hw/net/igb: recalculaterx_desc_lenon migration loadhw/net/e1000e_core.c | 18 +++++++++++++----- hw/net/igb_core.c | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-)
Queued via hw-misc, thanks.