hw/net: fix rx_desc_len on migration load
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
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
@@ -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
Re: [PATCH 1/2] hw/net/e1000e: recalculate rx_desc_len on migration load
Quoted 6 lines · Laurent Vivier
rx_desc_lenis migrated as a rawuint8_tfrom 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 setrx_desc_lento an invalid value (e.g. 64), causing a stack buffer overflow ine1000e_write_packet_to_guest()which copiesrx_desc_lenbytes 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_lenfrom the register state inpost_load, ignoring the untrusted value from the stream.Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869Signed-off-by Laurent Vivier <[email protected]>--- hw/net/e1000e_core.c | 2 ++ 1 file changed, 2 insertions(+)hw/net/e1000e_core.c +2
-0@@ -3557,5 +3557,7 @@ e1000e_core_post_load(E1000ECore *core)e1000e_intrmgr_resume (core);e1000e_autoneg_resume (core); +e1000e_calc_rxdesclen (core); +return 0 ; }
Re: [PATCH 1/2] hw/net/e1000e: recalculate rx_desc_len on migration load
In reply to Laurent VivierQuoted 22 lines · Laurent Vivier
rx_desc_lenis migrated as a rawuint8_tfrom 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 setrx_desc_lento an invalid value (e.g. 64), 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.Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3869Signed-off-by Laurent Vivier <[email protected]>--- hw/net/e1000e_core.c | 2 ++ 1 file changed, 2 insertions(+)hw/net/e1000e_core.c +0
-0
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 ; }
PATCH 2/2 hw/net/igb: recalculate rx_desc_len on migration load
In reply to Laurent VivierSame 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
@@ -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
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_lenis migrated from the stream but can be computed from the register state. Recalculate it inpost_loadto 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
Signed-off-by Laurent Vivier <[email protected]>--- 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 ; }
Quoted 12 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
Quoted 7 lines
Laurent Vivier (2):
hw/net/e1000e: recalculaterx_desc_lenon migration load hw/net/igb: recalculaterx_desc_lenon migration loadhw/net/e1000e_core.c | 2 ++ hw/net/igb_core.c | 2 ++ 2 files changed, 4 insertions(+)
Series: