hw/net/net_tx_pkt: Fix crash detected by fuzzer
PATCH 1/1 hw/net/net_tx_pkt: Fix crash detected by fuzzer
QEMU currently crashes when it's started like this:
cat << EOF | ./qemu-system-i386 -device vmxnet3 -nodefaults -qtest stdio outl 0xcf8 0x80001014
outl 0xcfc 0xe0001000
outl 0xcf8 0x80001018
outl 0xcf8 0x80001004
outw 0xcfc 0x7
outl 0xcf8 0x80001083
write 0x0 0x1 0xe1
write 0x1 0x1 0xfe
write 0x2 0x1 0xbe
write 0x3 0x1 0xba
writeq 0xe0001020 0xefefff5ecafe0000
writeq 0xe0001020 0xffff5e5ccafe0002
EOF
It hits this assertion:
qemu-system-i386: ../qemu/hw/net/net_tx_pkt.c:453: net_tx_pkt_reset:
Assertion `pkt->raw' failed.
This happens because net_tx_pkt_init() is called with max_frags == 0 and thus the allocation
p->raw = g_new(struct iovec, max_frags);
results in a NULL pointer that cause the
assert(pkt->raw);
in net_tx_pkt_reset() to fail later. To fix this issue we can check that max_raw_frags was not zero before asserting that pkt->raw is a non-NULL pointer.
--- hw/net/net_tx_pkt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/net/net_tx_pkt.c +7 -5
@@ -450,11 +450,13 @@ void net_tx_pkt_reset(struct NetTxPkt *pkt) pkt->payload_len =0 ; pkt->payload_frags =0 ; -assert (pkt->raw); -for (i =0 ; i < pkt->raw_frags; i++) { -assert (pkt->raw[i].iov_base); -pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, pkt->raw[i].iov_len, -DMA_DIRECTION_TO_DEVICE ,0 ); +if (pkt->max_raw_frags >0 ) { +assert (pkt->raw); +for (i =0 ; i < pkt->raw_frags; i++) { +assert (pkt->raw[i].iov_base); +pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, + pkt->raw[i].iov_len,DMA_DIRECTION_TO_DEVICE ,0 ); + } } pkt->raw_frags =0 ;
Signature · 1 line
2.27.0
Quoted 22 lines · Thomas Huth
QEMU currently crashes when it's started like this:
cat << EOF | ./qemu-system-i386 -device vmxnet3 -nodefaults -qtest stdio outl
0xcf80x80001014
outl0xcfc0xe0001000
outl0xcf80x80001018
outl0xcf80x80001004
outw0xcfc0x7
outl0xcf80x80001083
write0x00x10xe1
write0x10x10xfe
write0x20x10xbe
write0x30x10xba
writeq0xe00010200xefefff5ecafe0000
writeq0xe00010200xffff5e5ccafe0002
EOFIt hits this assertion:
qemu-system-i386:
../qemu/hw/net/net_tx_pkt.c:453:net_tx_pkt_reset:
Assertion `pkt->raw' failed.
Quoted 6 lines
This happens because
net_tx_pkt_init()is called withmax_frags== 0 and thus the allocationp->raw = g_new(struct iovec, max_frags);results in a NULL pointer that cause the
"that causes"?
Quoted 37 lines
assert(pkt->raw);in
net_tx_pkt_reset()to fail later. To fix this issue we can check thatmax_raw_fragswas not zero before asserting thatpkt->rawis a non-NULL pointer.Signed-off-by Thomas Huth <[email protected]>--- hw/net/net_tx_pkt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/net/net_tx_pkt.c +7
-5@@ -450,11 +450,13 @@ void net_tx_pkt_reset(struct NetTxPkt *pkt) pkt->payload_len =0 ; pkt->payload_frags =0 ; -assert (pkt->raw); -for (i =0 ; i < pkt->raw_frags; i++) { -assert (pkt->raw[i].iov_base); -pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, pkt->raw[i].iov_len, -DMA_DIRECTION_TO_DEVICE ,0 ); +if (pkt->max_raw_frags >0 ) { +assert (pkt->raw); +for (i =0 ; i < pkt->raw_frags; i++) { +assert (pkt->raw[i].iov_base); +pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, + pkt->raw[i].iov_len,DMA_DIRECTION_TO_DEVICE ,0 ); + } } pkt->raw_frags =0 ;
Quoted 54 lines
QEMU currently crashes when it's started like this:
cat << EOF | ./qemu-system-i386 -device vmxnet3 -nodefaults -qtest stdio outl
0xcf80x80001014
outl0xcfc0xe0001000
outl0xcf80x80001018
outl0xcf80x80001004
outw0xcfc0x7
outl0xcf80x80001083
write0x00x10xe1
write0x10x10xfe
write0x20x10xbe
write0x30x10xba
writeq0xe00010200xefefff5ecafe0000
writeq0xe00010200xffff5e5ccafe0002
EOFIt hits this assertion:
qemu-system-i386:
../qemu/hw/net/net_tx_pkt.c:453:net_tx_pkt_reset:
Assertion `pkt->raw' failed.This happens because
net_tx_pkt_init()is called withmax_frags== 0 and thus the allocationp->raw = g_new(struct iovec, max_frags);results in a NULL pointer that cause the
assert(pkt->raw);in
net_tx_pkt_reset()to fail later. To fix this issue we can check thatmax_raw_fragswas not zero before asserting thatpkt->rawis a non-NULL pointer.Signed-off-by Thomas Huth <[email protected]>--- hw/net/net_tx_pkt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/net/net_tx_pkt.c +0
-5@@ -450,11 +450,13 @@ void net_tx_pkt_reset(struct NetTxPkt *pkt) pkt->payload_len =0 ; pkt->payload_frags =0 ; -assert (pkt->raw); -for (i =0 ; i < pkt->raw_frags; i++) { -assert (pkt->raw[i].iov_base); -pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, pkt->raw[i].iov_len, -DMA_DIRECTION_TO_DEVICE ,0 );
hw/net/net_tx_pkt.c void net_tx_pkt_reset(struct NetTxPkt *pkt) · line 462
Quoted 10 lines
hw/net/net_tx_pkt.c +7
-0+if (pkt->max_raw_frags >0 ) { +assert (pkt->raw); +for (i =0 ; i < pkt->raw_frags; i++) { +assert (pkt->raw[i].iov_base); +pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, + pkt->raw[i].iov_len,DMA_DIRECTION_TO_DEVICE ,0 ); + } } pkt->raw_frags =0 ;
Jason Wang
AppliedQuoted 53 lines · Thomas Huth
QEMU currently crashes when it's started like this:
cat << EOF | ./qemu-system-i386 -device vmxnet3 -nodefaults -qtest stdio outl
0xcf80x80001014
outl0xcfc0xe0001000
outl0xcf80x80001018
outl0xcf80x80001004
outw0xcfc0x7
outl0xcf80x80001083
write0x00x10xe1
write0x10x10xfe
write0x20x10xbe
write0x30x10xba
writeq0xe00010200xefefff5ecafe0000
writeq0xe00010200xffff5e5ccafe0002
EOFIt hits this assertion:
qemu-system-i386:
../qemu/hw/net/net_tx_pkt.c:453:net_tx_pkt_reset:
Assertion `pkt->raw' failed.This happens because
net_tx_pkt_init()is called withmax_frags== 0 and thus the allocationp->raw = g_new(struct iovec, max_frags);results in a NULL pointer that cause the
assert(pkt->raw);in
net_tx_pkt_reset()to fail later. To fix this issue we can check thatmax_raw_fragswas not zero before asserting thatpkt->rawis a non-NULL pointer.Signed-off-by Thomas Huth <[email protected]>--- hw/net/net_tx_pkt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/net/net_tx_pkt.c +0
-4@@ -450,11 +450,13 @@ void net_tx_pkt_reset(struct NetTxPkt *pkt) pkt->payload_len =0 ; pkt->payload_frags =0 ; -assert (pkt->raw); -for (i =0 ; i < pkt->raw_frags; i++) { -assert (pkt->raw[i].iov_base); - pci_dma_unmap(pkt->pci_dev, pkt->raw[i].iov_base, pkt->raw[i].iov_len,
hw/net/net_tx_pkt.c void net_tx_pkt_reset(struct NetTxPkt *pkt) · line 461
Quoted 10 lines
hw/net/net_tx_pkt.c +7
-1- DMA_DIRECTION_TO_DEVICE, 0); +if (pkt->max_raw_frags >0 ) { +assert (pkt->raw); +for (i =0 ; i < pkt->raw_frags; i++) { +assert (pkt->raw[i].iov_base); +pci_dma_unmap (pkt->pci_dev, pkt->raw[i].iov_base, + pkt->raw[i].iov_len,DMA_DIRECTION_TO_DEVICE ,0 ); + } } pkt->raw_frags =0 ;
Applied.
Thanks