assertion failure in net_tx_pkt_add_raw_fragment() in hw/net/net_tx_pkt.c
cover assertion failure in net_tx_pkt_add_raw_fragment() in hw/net/net_tx_pkt.c
An assertion failure issue was reported by Mr. Ziming Zhang (CC'd). It occurs in the code that processes network packets while adding data fragments into packet context. This flaw could potentially be abused by a malicious guest to abort the QEMU process on the host. This two patch series does a couple of things:
- introduces a new function in net_tx_pkt.{c,h} to check the maximum number of data fragments
- adds a check in both e1000e and vmxnet3 devices to skip the packet if the current data fragment exceeds max_raw_frags, preventing net_tx_pkt_add_raw_fragment() to be called with an invalid raw_frags
Mauro Matteo Cascella (2):
hw/net/net_tx_pkt: add function to check pkt->max_raw_frags hw/net: check max_raw_frags in e1000e and vmxnet3 devices
hw/net/e1000e_core.c | 3 ++- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ hw/net/vmxnet3.c | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/2 hw/net/net_tx_pkt: add function to check pkt->max_raw_frags
This patch introduces a new function in hw/net/net_tx_pkt.{c,h} to check the current data fragment against the maximum number of data fragments.
--- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ 2 files changed, 13 insertions(+)
hw/net/net_tx_pkt.c +5 -0
@@ -400,6 +400,11 @@ bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, } } +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt) +{ +return pkt->raw_frags >= pkt->max_raw_frags; +} +bool net_tx_pkt_has_fragments (struct NetTxPkt *pkt) {return pkt->raw_frags >0 ;
hw/net/net_tx_pkt.h +8 -0
@@ -179,6 +179,14 @@ bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);*/ bool net_tx_pkt_parse (struct NetTxPkt *pkt); +/** +* indicates if the current data fragment exceeds max_raw_frags +* +* @pkt: packet +* +*/ +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt); +/** * indicates if there are data fragments held by this packet object. *
Signature · 1 line
2.26.2
Re: [PATCH 1/2] hw/net/net_tx_pkt: add function to check pkt->max_raw_frags
Quoted 2 lines · Mauro Matteo Cascella
This patch introduces a new function in hw/net/net_tx_pkt.{c,h} to check the current data fragment against the maximum number of data fragments.
I wonder whether it's better to do the check in net_tx_pkt_add_raw_fragment() and fail there.
Btw, I find net_tx_pkt_add_raw_fragment() does not unmap dma when returning to true, is this a bug?
Thanks
Quoted 43 lines
Reported-by Ziming Zhang <[email protected]>Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ 2 files changed, 13 insertions(+)hw/net/net_tx_pkt.c +5
-0@@ -400,6 +400,11 @@ bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, } } +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt) +{ +return pkt->raw_frags >= pkt->max_raw_frags; +} +bool net_tx_pkt_has_fragments (struct NetTxPkt *pkt) {return pkt->raw_frags >0 ;hw/net/net_tx_pkt.h +8
-0@@ -179,6 +179,14 @@ bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);*/ bool net_tx_pkt_parse (struct NetTxPkt *pkt); +/** +* indicates if the current data fragment exceeds max_raw_frags +* +* @pkt: packet +* +*/ +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt); +/** * indicates if there are data fragments held by this packet object. *
Re: [PATCH 1/2] hw/net/net_tx_pkt: add function to check pkt->max_raw_frags
Quoted 9 lines · Jason Wang
Quoted 2 lines · Mauro Matteo Cascella
This patch introduces a new function in hw/net/net_tx_pkt.{c,h} to check the current data fragment against the maximum number of data fragments.
I wonder whether it's better to do the check in
net_tx_pkt_add_raw_fragment()and fail there.
Given the assertion, I assumed the caller is responsible for the check, but moving the check in net_tx_pkt_add_raw_fragment() totally makes sense to me.
Quoted 2 lines
Btw, I find
net_tx_pkt_add_raw_fragment()does not unmap dma when returning to true, is this a bug?
Isn't it unmapped in net_tx_pkt_reset()?
Quoted 47 lines
Thanks
Quoted 43 lines
Reported-by Ziming Zhang <[email protected]>Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ 2 files changed, 13 insertions(+)hw/net/net_tx_pkt.c +5
-0@@ -400,6 +400,11 @@ bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, } } +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt) +{ +return pkt->raw_frags >= pkt->max_raw_frags; +} +bool net_tx_pkt_has_fragments (struct NetTxPkt *pkt) {return pkt->raw_frags >0 ;hw/net/net_tx_pkt.h +8
-0@@ -179,6 +179,14 @@ bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);*/ bool net_tx_pkt_parse (struct NetTxPkt *pkt); +/** +* indicates if the current data fragment exceeds max_raw_frags +* +* @pkt: packet +* +*/ +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt); +/** * indicates if there are data fragments held by this packet object. *
Signature · 2 lines
Mauro Matteo Cascella, Red Hat Product Security 6F78 E20B 5935 928C F0A8 1A9D 4E55 23B8 BB34 10B0
Re: [PATCH 1/2] hw/net/net_tx_pkt: add function to check pkt->max_raw_frags
Quoted 11 lines · Mauro Matteo Cascella
Quoted 7 lines · Jason Wang
Quoted 2 lines · Mauro Matteo Cascella
This patch introduces a new function in hw/net/net_tx_pkt.{c,h} to check the current data fragment against the maximum number of data fragments.
I wonder whether it's better to do the check in
net_tx_pkt_add_raw_fragment()and fail there.Given the assertion, I assumed the caller is responsible for the check, but moving the check in
net_tx_pkt_add_raw_fragment()totally makes sense to me.
Want to send a new version for this?
Quoted 4 lines
Quoted 3 lines
Btw, I find
net_tx_pkt_add_raw_fragment()does not unmap dma when returning to true, is this a bug?Isn't it unmapped in
net_tx_pkt_reset()?
Probably but see how it was used in e1000e, the net_tx_pkt_reset() is only called when eop is set. Is this a bug?
Thanks
Quoted 46 lines
Quoted 46 lines
Thanks
Quoted 42 lines
Reported-by Ziming Zhang <[email protected]>Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ 2 files changed, 13 insertions(+)hw/net/net_tx_pkt.c +5
-0@@ -400,6 +400,11 @@ bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, } } +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt) +{ +return pkt->raw_frags >= pkt->max_raw_frags; +} +bool net_tx_pkt_has_fragments (struct NetTxPkt *pkt) {return pkt->raw_frags >0 ;hw/net/net_tx_pkt.h +8
-0@@ -179,6 +179,14 @@ bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);*/ bool net_tx_pkt_parse (struct NetTxPkt *pkt); +/** +* indicates if the current data fragment exceeds max_raw_frags +* +* @pkt: packet +* +*/ +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt); +/** * indicates if there are data fragments held by this packet object. *
Re: [PATCH 1/2] hw/net/net_tx_pkt: add function to check pkt->max_raw_frags
Quoted 9 lines · Jason Wang
Quoted 6 lines · Mauro Matteo Cascella
Quoted 5 lines · Jason Wang
Quoted 2 lines · Mauro Matteo Cascella
This patch introduces a new function in hw/net/net_tx_pkt.{c,h} to check the current data fragment against the maximum number of data fragments.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I wonder whether it's better to do the check in
net_tx_pkt_add_raw_fragment()and fail there.Given the assertion, I assumed the caller is responsible for the check, but moving the check in
net_tx_pkt_add_raw_fragment()totally makes sense to me.Want to send a new version for this?
Sure, I'll send a new version. Thank you.
Quoted 9 lines
Quoted 5 lines
Quoted 4 lines
Btw, I find
net_tx_pkt_add_raw_fragment()does not unmap dma when returning to true, is this a bug?Isn't it unmapped in
net_tx_pkt_reset()?Probably but see how it was used in e1000e, the
net_tx_pkt_reset()is only called when eop is set. Is this a bug?
Yeah it all depends on E1000_TXD_CMD_EOP. Besides, if not set, e1000e_tx_pkt_send() would never be called. Honestly, I don't know if this is a reasonable scenario or not.
Quoted 37 lines
Thanks
Quoted 35 lines
Quoted 35 lines
Thanks
Quoted 31 lines
Reported-by Ziming Zhang <[email protected]>Signed-off-by Mauro Matteo Cascella <[email protected]>--- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ 2 files changed, 13 insertions(+)hw/net/net_tx_pkt.c +5
-0@@ -400,6 +400,11 @@ bool net_tx_pkt_add_raw_fragment(struct NetTxPkt *pkt, hwaddr pa, } } +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt) +{ +return pkt->raw_frags >= pkt->max_raw_frags; +} +bool net_tx_pkt_has_fragments (struct NetTxPkt *pkt) {return pkt->raw_frags >0 ;hw/net/net_tx_pkt.h +0
-0@@ -179,6 +179,14 @@ bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc);*/ bool net_tx_pkt_parse (struct NetTxPkt *pkt);
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
hw/net/net_tx_pkt.h bool net_tx_pkt_send_loopback(struct NetTxPkt *pkt, NetClientState *nc); · line 192
Quoted 11 lines
hw/net/net_tx_pkt.h +8
-0+/** +* indicates if the current data fragment exceeds max_raw_frags +* +* @pkt: packet +* +*/ +bool net_tx_pkt_exceed_max_fragments (struct NetTxPkt *pkt); +/** * indicates if there are data fragments held by this packet object. *
--
Mauro Matteo Cascella, Red Hat Product Security 6F78 E20B 5935 928C F0A8 1A9D 4E55 23B8 BB34 10B0
Re: [PATCH 1/2] hw/net/net_tx_pkt: add function to check pkt->max_raw_frags
Quoted 14 lines · Mauro Matteo Cascella
Quoted 11 lines · Jason Wang
Quoted 9 lines · Mauro Matteo Cascella
Quoted 5 lines · Jason Wang
Quoted 2 lines · Mauro Matteo Cascella
This patch introduces a new function in hw/net/net_tx_pkt.{c,h} to check the current data fragment against the maximum number of data fragments.
I wonder whether it's better to do the check in
net_tx_pkt_add_raw_fragment()and fail there.Given the assertion, I assumed the caller is responsible for the check, but moving the check in
net_tx_pkt_add_raw_fragment()totally makes sense to me.Want to send a new version for this?
Sure, I'll send a new version. Thank you.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Btw, I find
net_tx_pkt_add_raw_fragment()does not unmap dma when returning to true, is this a bug?Isn't it unmapped in
net_tx_pkt_reset()?Probably but see how it was used in e1000e, the
net_tx_pkt_reset()is only called when eop is set. Is this a bug?Yeah it all depends on
E1000_TXD_CMD_EOP. Besides, if not set,e1000e_tx_pkt_send()would never be called. Honestly, I don't know if this is a reasonable scenario or not.
It's probably fine since anyway e1000e_core_reset() will call net_tx_pkt_reset().
Thanks
Quoted 3 lines
Quoted 3 lines
Thanks
PATCH 2/2 hw/net: check max_raw_frags in e1000e and vmxnet3 devices
In reply to Mauro Matteo CascellaThis patch adds a check in both e1000e and vmxnet3 devices to skip the packet if the current data fragment exceeds max_raw_frags, preventing net_tx_pkt_add_raw_fragment() to be called with an invalid raw_frags.
--- hw/net/e1000e_core.c | 3 ++- hw/net/vmxnet3.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
hw/net/e1000e_core.c +2 -1
@@ -728,7 +728,8 @@ e1000e_process_tx_desc(E1000ECore *core, addr =le64_to_cpu (dp->buffer_addr);if (!tx->skip_cp) { -if (!net_tx_pkt_add_raw_fragment (tx->tx_pkt, addr, split_size)) { +if (net_tx_pkt_exceed_max_fragments (tx->tx_pkt) || + !net_tx_pkt_add_raw_fragment (tx->tx_pkt, addr, split_size)) { tx->skip_cp = true; } }
hw/net/vmxnet3.c +2 -1
@@ -650,7 +650,8 @@ static void vmxnet3_process_tx_queue(VMXNET3State *s, int qidx) data_len = (txd.len >0 ) ? txd.len :VMXNET3_MAX_TX_BUF_SIZE ; data_pa = txd.addr; -if (!net_tx_pkt_add_raw_fragment (s->tx_pkt, +if (net_tx_pkt_exceed_max_fragments (s->tx_pkt) || + !net_tx_pkt_add_raw_fragment (s->tx_pkt, data_pa, data_len)) { s->skip_current_tx_pkt = true;
Signature · 1 line
2.26.2
I sent a reproducer for the to the list some time ago, but never created a Launchpad bug...
https://www.mail-archive.com/[email protected]/msg701930.html
Anyways.. I can confirm that I can't reproduce the issue with these patches.
Minimized Reproducer:
cat << EOF | ./i386-softmmu/qemu-system-i386 -M pc-q35-5.0 -nographic \
-display none -serial none -monitor none -qtest stdio
outl 0xcf8 0x80001010
outl 0xcfc 0xe1020000
outl 0xcf8 0x80001004
outw 0xcfc 0x7
write 0xe10207e8 0x4 0x25ff13ff
write 0xe10200b8 0x7 0xe3055e411b0202
write 0xe1020100 0x5 0x5e411b0202
write 0xe1020110 0x4 0x1b0202e1
write 0xe1020118 0x4 0x06fff105
write 0xe1020128 0x7 0xf3055e411b0202
write 0xe1020402 0x2 0x5e41
write 0xe1020420 0x4 0x1b0202e1
write 0xe1020428 0x4 0x06ff6105
write 0xe1020438 0x1 0x63
write 0xe1020439 0x1 0x05
EOF
-Alex
Quoted 26 lines · Mauro Matteo Cascella
An assertion failure issue was reported by Mr. Ziming Zhang (CC'd). It occurs in the code that processes network packets while adding data fragments into packet context. This flaw could potentially be abused by a malicious guest to abort the QEMU process on the host. This two patch series does a couple of things:
- introduces a new function in net_tx_pkt.{c,h} to check the maximum number of data fragments
- adds a check in both e1000e and vmxnet3 devices to skip the packet if the current data fragment exceedsmax_raw_frags, preventingnet_tx_pkt_add_raw_fragment()to be called with an invalidraw_fragsMauro Matteo Cascella (2):
hw/net/net_tx_pkt: add function to checkpkt->max_raw_fragshw/net: checkmax_raw_fragsin e1000e and vmxnet3 deviceshw/net/e1000e_core.c | 3 ++- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ hw/net/vmxnet3.c | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-)Signature · 1 line
2.26.2
Thank you Alexander for testing the patch and providing the reproducer. I think you should be credited, along with Ziming, for independently reporting the same issue.
Quoted 58 lines · Alexander Bulekov
I sent a reproducer for the to the list some time ago, but never created a Launchpad bug...
https://www.mail-archive.com/[email protected]/msg701930.htmlAnyways.. I can confirm that I can't reproduce the issue with these patches.
Minimized Reproducer:
cat << EOF | ./i386-softmmu/qemu-system-i386 -M pc-q35-5.0 -nographic \
-display none -serial none -monitor none -qtest stdio
outl0xcf80x80001010
outl0xcfc0xe1020000
outl0xcf80x80001004
outw0xcfc0x7
write0xe10207e80x40x25ff13ff
write0xe10200b80x70xe3055e411b0202
write0xe10201000x50x5e411b0202
write0xe10201100x40x1b0202e1
write0xe10201180x40x06fff105
write0xe10201280x70xf3055e411b0202
write0xe10204020x20x5e41
write0xe10204200x40x1b0202e1
write0xe10204280x40x06ff6105
write0xe10204380x10x63
write0xe10204390x10x05
EOF-Alex
Quoted 26 lines · Mauro Matteo Cascella
An assertion failure issue was reported by Mr. Ziming Zhang (CC'd). It occurs in the code that processes network packets while adding data fragments into packet context. This flaw could potentially be abused by a malicious guest to abort the QEMU process on the host. This two patch series does a couple of things:
- introduces a new function in net_tx_pkt.{c,h} to check the maximum number of data fragments
- adds a check in both e1000e and vmxnet3 devices to skip the packet if the current data fragment exceedsmax_raw_frags, preventingnet_tx_pkt_add_raw_fragment()to be called with an invalidraw_fragsMauro Matteo Cascella (2):
hw/net/net_tx_pkt: add function to checkpkt->max_raw_fragshw/net: checkmax_raw_fragsin e1000e and vmxnet3 deviceshw/net/e1000e_core.c | 3 ++- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ hw/net/vmxnet3.c | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-)--
2.26.2
Signature · 2 lines
Mauro Matteo Cascella, Red Hat Product Security 6F78 E20B 5935 928C F0A8 1A9D 4E55 23B8 BB34 10B0
Dmitry Fleytman
Reviewed-byThe idea looks good to me. I believe it makes sense to do the check in net_tx_pkt_add_raw_fragment() as suggested by Jason.
Quoted 58 lines · Alexander Bulekov
I sent a reproducer for the to the list some time ago, but never created a Launchpad bug...
https://www.mail-archive.com/[email protected]/msg701930.htmlAnyways.. I can confirm that I can't reproduce the issue with these patches.
Minimized Reproducer:
cat << EOF | ./i386-softmmu/qemu-system-i386 -M pc-q35-5.0 -nographic \
-display none -serial none -monitor none -qtest stdio
outl0xcf80x80001010
outl0xcfc0xe1020000
outl0xcf80x80001004
outw0xcfc0x7
write0xe10207e80x40x25ff13ff
write0xe10200b80x70xe3055e411b0202
write0xe10201000x50x5e411b0202
write0xe10201100x40x1b0202e1
write0xe10201180x40x06fff105
write0xe10201280x70xf3055e411b0202
write0xe10204020x20x5e41
write0xe10204200x40x1b0202e1
write0xe10204280x40x06ff6105
write0xe10204380x10x63
write0xe10204390x10x05
EOF-Alex
Quoted 26 lines · Mauro Matteo Cascella
An assertion failure issue was reported by Mr. Ziming Zhang (CC'd). It occurs in the code that processes network packets while adding data fragments into packet context. This flaw could potentially be abused by a malicious guest to abort the QEMU process on the host. This two patch series does a couple of things:
- introduces a new function in net_tx_pkt.{c,h} to check the maximum number of data fragments
- adds a check in both e1000e and vmxnet3 devices to skip the packet if the current data fragment exceedsmax_raw_frags, preventingnet_tx_pkt_add_raw_fragment()to be called with an invalidraw_fragsMauro Matteo Cascella (2):
hw/net/net_tx_pkt: add function to checkpkt->max_raw_fragshw/net: checkmax_raw_fragsin e1000e and vmxnet3 deviceshw/net/e1000e_core.c | 3 ++- hw/net/net_tx_pkt.c | 5 +++++ hw/net/net_tx_pkt.h | 8 ++++++++ hw/net/vmxnet3.c | 3 ++- 4 files changed, 17 insertions(+), 2 deletions(-)Signature · 1 line
2.26.2