From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Dmitry Fleytman <dmitry.fleytman@gmail.com>
Subject: [PULL 4/5] hw/net/net_tx_pkt: Fix crash detected by fuzzer
Date: Mon, 19 Jul 2021 12:26:39 +0200 [thread overview]
Message-ID: <20210719102640.2610368-5-thuth@redhat.com> (raw)
In-Reply-To: <20210719102640.2610368-1-thuth@redhat.com>
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 causes 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.
Buglink: https://bugs.launchpad.net/qemu/+bug/1890157
Message-Id: <20210715193219.1132571-1-thuth@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/net/net_tx_pkt.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c
index 1f9aa59eca..1cb1125d9f 100644
--- a/hw/net/net_tx_pkt.c
+++ b/hw/net/net_tx_pkt.c
@@ -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;
--
2.27.0
next prev parent reply other threads:[~2021-07-19 10:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-19 10:26 [PULL 0/5] Misc fixes for 6.1 Thomas Huth
2021-07-19 10:26 ` [PULL 1/5] ci: build & store windows installer Thomas Huth
2021-07-19 10:26 ` [PULL 2/5] configure: Fix endianess test with LTO Thomas Huth
2021-07-19 10:26 ` [PULL 3/5] hw/net/vmxnet3: Do not abort if the guest is trying to use an invalid TX queue Thomas Huth
2021-07-19 10:26 ` Thomas Huth [this message]
2021-07-19 10:26 ` [PULL 5/5] hw/ide: Fix crash when plugging a piix3-ide device into the x-remote machine Thomas Huth
2021-07-19 13:13 ` [PULL 0/5] Misc fixes for 6.1 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210719102640.2610368-5-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=dmitry.fleytman@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).