From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gaoning Pan <gaoning.pgn@antgroup.com>,
Mauro Matteo Cascella <mcascell@redhat.com>,
Xingwei Lin <linyi.lxw@antfin.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Paul Zimmerman <pauldzim@gmail.com>
Subject: [PULL 3/3] hw/usb/hcd-dwc2: fix divide-by-zero in dwc2_handle_packet()
Date: Mon, 19 Oct 2020 14:33:26 +0200 [thread overview]
Message-ID: <20201019123326.9973-4-kraxel@redhat.com> (raw)
In-Reply-To: <20201019123326.9973-1-kraxel@redhat.com>
From: Mauro Matteo Cascella <mcascell@redhat.com>
Check the value of mps to avoid potential divide-by-zero later in the function.
Since HCCHAR_MPS is guest controllable, this prevents a malicious/buggy guest
from crashing the QEMU process on the host.
Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
Reviewed-by: Paul Zimmerman <pauldzim@gmail.com>
Reported-by: Gaoning Pan <gaoning.pgn@antgroup.com>
Reported-by: Xingwei Lin <linyi.lxw@antfin.com>
Message-id: 20201015075957.268823-1-mcascell@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb/hcd-dwc2.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c
index 64c23c1ed084..e1d96acf7ecf 100644
--- a/hw/usb/hcd-dwc2.c
+++ b/hw/usb/hcd-dwc2.c
@@ -250,6 +250,12 @@ static void dwc2_handle_packet(DWC2State *s, uint32_t devadr, USBDevice *dev,
trace_usb_dwc2_handle_packet(chan, dev, &p->packet, epnum, types[eptype],
dirs[epdir], mps, len, pcnt);
+ if (mps == 0) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: Bad HCCHAR_MPS set to zero\n", __func__);
+ return;
+ }
+
if (eptype == USB_ENDPOINT_XFER_CONTROL && pid == TSIZ_SC_MC_PID_SETUP) {
pid = USB_TOKEN_SETUP;
} else {
--
2.27.0
next prev parent reply other threads:[~2020-10-19 12:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-19 12:33 [PULL 0/3] Usb 20201019 patches Gerd Hoffmann
2020-10-19 12:33 ` [PULL 1/3] usb: hcd-dwc2: change assert()s to qemu_log_mask(LOG_GUEST_ERROR...) Gerd Hoffmann
2020-10-19 12:33 ` [PULL 2/3] usb/hcd-ehci: Fix error handling on missing device for iTD Gerd Hoffmann
2020-10-19 12:33 ` Gerd Hoffmann [this message]
2020-10-19 13:39 ` [PULL 0/3] Usb 20201019 patches Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2020-10-16 5:24 [PULL 0/3] Usb 20201016 patches Gerd Hoffmann
2020-10-16 5:24 ` [PULL 3/3] hw/usb/hcd-dwc2: fix divide-by-zero in dwc2_handle_packet() Gerd Hoffmann
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=20201019123326.9973-4-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=gaoning.pgn@antgroup.com \
--cc=linyi.lxw@antfin.com \
--cc=mcascell@redhat.com \
--cc=pauldzim@gmail.com \
--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).