thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
80b7ec
From d43b55595f9f5a29ad45b6bf1c899646ef623bf9 Mon Sep 17 00:00:00 2001
80b7ec
From: Jon Maloy <jmaloy@redhat.com>
80b7ec
Date: Fri, 4 Sep 2020 16:09:12 -0400
80b7ec
Subject: [PATCH 2/3] usb: check RNDIS message length
80b7ec
80b7ec
RH-Author: Jon Maloy <jmaloy@redhat.com>
80b7ec
Message-id: <20200904160913.87759-2-jmaloy@redhat.com>
80b7ec
Patchwork-id: 98289
80b7ec
O-Subject: [RHEL-7.9 qemu-kvm PATCH 1/2] usb: check RNDIS message length
80b7ec
Bugzilla: 1869693
80b7ec
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
80b7ec
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
80b7ec
RH-Acked-by: Thomas Huth <thuth@redhat.com>
80b7ec
80b7ec
From: Prasad J Pandit <pjp@fedoraproject.org>
80b7ec
80b7ec
When processing remote NDIS control message packets, the USB Net
80b7ec
device emulator uses a fixed length(4096) data buffer. The incoming
80b7ec
packet length could exceed this limit. Add a check to avoid it.
80b7ec
80b7ec
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
80b7ec
Message-id: 1455648821-17340-2-git-send-email-ppandit@redhat.com
80b7ec
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
80b7ec
(cherry picked from commit 64c9bc181fc78275596649f591302d72df2d3071)
80b7ec
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
80b7ec
Signed-off-by: Jon Maloy <jmaloy.redhat.com>
80b7ec
---
80b7ec
 hw/usb/core.c | 18 +++++++++---------
80b7ec
 1 file changed, 9 insertions(+), 9 deletions(-)
80b7ec
80b7ec
diff --git a/hw/usb/core.c b/hw/usb/core.c
80b7ec
index cf34755bba..f0201e30b4 100644
80b7ec
--- a/hw/usb/core.c
80b7ec
+++ b/hw/usb/core.c
80b7ec
@@ -128,9 +128,16 @@ static void do_token_setup(USBDevice *s, USBPacket *p)
80b7ec
     }
80b7ec
 
80b7ec
     usb_packet_copy(p, s->setup_buf, p->iov.size);
80b7ec
+    s->setup_index = 0;
80b7ec
     p->actual_length = 0;
80b7ec
     s->setup_len   = (s->setup_buf[7] << 8) | s->setup_buf[6];
80b7ec
-    s->setup_index = 0;
80b7ec
+    if (s->setup_len > sizeof(s->data_buf)) {
80b7ec
+        fprintf(stderr,
80b7ec
+                "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
80b7ec
+                s->setup_len, sizeof(s->data_buf));
80b7ec
+        p->status = USB_RET_STALL;
80b7ec
+        return;
80b7ec
+    }
80b7ec
 
80b7ec
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
80b7ec
     value   = (s->setup_buf[3] << 8) | s->setup_buf[2];
80b7ec
@@ -151,13 +158,6 @@ static void do_token_setup(USBDevice *s, USBPacket *p)
80b7ec
         }
80b7ec
         s->setup_state = SETUP_STATE_DATA;
80b7ec
     } else {
80b7ec
-        if (s->setup_len > sizeof(s->data_buf)) {
80b7ec
-            fprintf(stderr,
80b7ec
-                "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
80b7ec
-                s->setup_len, sizeof(s->data_buf));
80b7ec
-            p->status = USB_RET_STALL;
80b7ec
-            return;
80b7ec
-        }
80b7ec
         if (s->setup_len == 0)
80b7ec
             s->setup_state = SETUP_STATE_ACK;
80b7ec
         else
80b7ec
@@ -176,7 +176,7 @@ static void do_token_in(USBDevice *s, USBPacket *p)
80b7ec
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
80b7ec
     value   = (s->setup_buf[3] << 8) | s->setup_buf[2];
80b7ec
     index   = (s->setup_buf[5] << 8) | s->setup_buf[4];
80b7ec
- 
80b7ec
+
80b7ec
     switch(s->setup_state) {
80b7ec
     case SETUP_STATE_ACK:
80b7ec
         if (!(s->setup_buf[0] & USB_DIR_IN)) {
80b7ec
-- 
80b7ec
2.18.2
80b7ec