Blame 0020-usb-sanity-check-setup_index-setup_len-in-post_load.patch

70114f
From a608c9c4150820ec64f5f25f6ebe244906c015da Mon Sep 17 00:00:00 2001
70114f
From: "Michael S. Tsirkin" <mst@redhat.com>
70114f
Date: Thu, 3 Apr 2014 19:52:25 +0300
70114f
Subject: [PATCH] usb: sanity check setup_index+setup_len in post_load
70114f
70114f
CVE-2013-4541
70114f
70114f
s->setup_len and s->setup_index are fed into usb_packet_copy as
70114f
size/offset into s->data_buf, it's possible for invalid state to exploit
70114f
this to load arbitrary data.
70114f
70114f
setup_len and setup_index should be checked to make sure
70114f
they are not negative.
70114f
70114f
Cc: Gerd Hoffmann <kraxel@redhat.com>
70114f
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
70114f
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
70114f
Signed-off-by: Juan Quintela <quintela@redhat.com>
70114f
(cherry picked from commit 9f8e9895c504149d7048e9fc5eb5cbb34b16e49a)
70114f
---
70114f
 hw/usb/bus.c | 4 +++-
70114f
 1 file changed, 3 insertions(+), 1 deletion(-)
70114f
70114f
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
70114f
index fe70429..e48b19f 100644
70114f
--- a/hw/usb/bus.c
70114f
+++ b/hw/usb/bus.c
70114f
@@ -49,7 +49,9 @@ static int usb_device_post_load(void *opaque, int version_id)
70114f
     } else {
70114f
         dev->attached = 1;
70114f
     }
70114f
-    if (dev->setup_index >= sizeof(dev->data_buf) ||
70114f
+    if (dev->setup_index < 0 ||
70114f
+        dev->setup_len < 0 ||
70114f
+        dev->setup_index >= sizeof(dev->data_buf) ||
70114f
         dev->setup_len >= sizeof(dev->data_buf)) {
70114f
         return -EINVAL;
70114f
     }