Blame 0103-usb-check-RNDIS-message-length.patch

54cb13
From: Prasad J Pandit <pjp@fedoraproject.org>
54cb13
Date: Wed, 17 Feb 2016 00:23:40 +0530
54cb13
Subject: [PATCH] usb: check RNDIS message length
54cb13
54cb13
When processing remote NDIS control message packets, the USB Net
54cb13
device emulator uses a fixed length(4096) data buffer. The incoming
54cb13
packet length could exceed this limit. Add a check to avoid it.
54cb13
54cb13
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
54cb13
Message-id: 1455648821-17340-2-git-send-email-ppandit@redhat.com
54cb13
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
54cb13
(cherry picked from commit 64c9bc181fc78275596649f591302d72df2d3071)
54cb13
---
54cb13
 hw/usb/core.c | 18 +++++++++---------
54cb13
 1 file changed, 9 insertions(+), 9 deletions(-)
54cb13
54cb13
diff --git a/hw/usb/core.c b/hw/usb/core.c
54cb13
index d0025db..7f46370 100644
54cb13
--- a/hw/usb/core.c
54cb13
+++ b/hw/usb/core.c
54cb13
@@ -128,9 +128,16 @@ static void do_token_setup(USBDevice *s, USBPacket *p)
54cb13
     }
54cb13
 
54cb13
     usb_packet_copy(p, s->setup_buf, p->iov.size);
54cb13
+    s->setup_index = 0;
54cb13
     p->actual_length = 0;
54cb13
     s->setup_len   = (s->setup_buf[7] << 8) | s->setup_buf[6];
54cb13
-    s->setup_index = 0;
54cb13
+    if (s->setup_len > sizeof(s->data_buf)) {
54cb13
+        fprintf(stderr,
54cb13
+                "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
54cb13
+                s->setup_len, sizeof(s->data_buf));
54cb13
+        p->status = USB_RET_STALL;
54cb13
+        return;
54cb13
+    }
54cb13
 
54cb13
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
54cb13
     value   = (s->setup_buf[3] << 8) | s->setup_buf[2];
54cb13
@@ -151,13 +158,6 @@ static void do_token_setup(USBDevice *s, USBPacket *p)
54cb13
         }
54cb13
         s->setup_state = SETUP_STATE_DATA;
54cb13
     } else {
54cb13
-        if (s->setup_len > sizeof(s->data_buf)) {
54cb13
-            fprintf(stderr,
54cb13
-                "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n",
54cb13
-                s->setup_len, sizeof(s->data_buf));
54cb13
-            p->status = USB_RET_STALL;
54cb13
-            return;
54cb13
-        }
54cb13
         if (s->setup_len == 0)
54cb13
             s->setup_state = SETUP_STATE_ACK;
54cb13
         else
54cb13
@@ -176,7 +176,7 @@ static void do_token_in(USBDevice *s, USBPacket *p)
54cb13
     request = (s->setup_buf[0] << 8) | s->setup_buf[1];
54cb13
     value   = (s->setup_buf[3] << 8) | s->setup_buf[2];
54cb13
     index   = (s->setup_buf[5] << 8) | s->setup_buf[4];
54cb13
- 
54cb13
+
54cb13
     switch(s->setup_state) {
54cb13
     case SETUP_STATE_ACK:
54cb13
         if (!(s->setup_buf[0] & USB_DIR_IN)) {