cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
619821
From 3d6cc57909eca16bd7bc4dc823b5eb71e65baffb Mon Sep 17 00:00:00 2001
619821
From: Gerd Hoffmann <kraxel@redhat.com>
619821
Date: Tue, 14 Mar 2017 08:52:56 +0100
619821
Subject: [PATCH 23/24] usb-ccid: add check message size checks
619821
MIME-Version: 1.0
619821
Content-Type: text/plain; charset=UTF-8
619821
Content-Transfer-Encoding: 8bit
619821
619821
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
619821
Message-id: <1489481576-26911-5-git-send-email-kraxel@redhat.com>
619821
Patchwork-id: 74287
619821
O-Subject: [RHEL-7.4 qemu-kvm PATCH 4/4] usb-ccid: add check message size checks
619821
Bugzilla: 1419818
619821
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
619821
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
619821
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
619821
Check message size too when figuring whenever we should expect more data.
619821
Fix debug message to show useful data, p->iov.size is fixed anyway if we
619821
land there, print how much we got meanwhile instead.
619821
619821
Also check announced message size against actual message size.  That
619821
is a more general fix for CVE-2017-5898 than commit "c7dfbf3 usb: ccid:
619821
check ccid apdu length".
619821
619821
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
619821
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
619821
Message-id: 1487250819-23764-4-git-send-email-kraxel@redhat.com
619821
(cherry picked from commit 31fb4444a485a348f8e2699d7c3dd15e1819ad2c)
619821
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
619821
---
619821
 hw/usb/dev-smartcard-reader.c | 13 ++++++++++---
619821
 1 file changed, 10 insertions(+), 3 deletions(-)
619821
619821
diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
619821
index 07d15ba..5e96a18 100644
619821
--- a/hw/usb/dev-smartcard-reader.c
619821
+++ b/hw/usb/dev-smartcard-reader.c
619821
@@ -1009,12 +1009,19 @@ static void ccid_handle_bulk_out(USBCCIDState *s, USBPacket *p)
619821
     }
619821
 
619821
     ccid_header = (CCID_Header *)s->bulk_out_data;
619821
-    if (p->iov.size == CCID_MAX_PACKET_SIZE) {
619821
+    if ((s->bulk_out_pos - 10 < ccid_header->dwLength) &&
619821
+        (p->iov.size == CCID_MAX_PACKET_SIZE)) {
619821
         DPRINTF(s, D_VERBOSE,
619821
-            "usb-ccid: bulk_in: expecting more packets (%zd/%d)\n",
619821
-            p->iov.size, ccid_header->dwLength);
619821
+                "usb-ccid: bulk_in: expecting more packets (%d/%d)\n",
619821
+                s->bulk_out_pos - 10, ccid_header->dwLength);
619821
         return;
619821
     }
619821
+    if (s->bulk_out_pos - 10 != ccid_header->dwLength) {
619821
+        DPRINTF(s, 1,
619821
+                "usb-ccid: bulk_in: message size mismatch (got %d, expected %d)\n",
619821
+                s->bulk_out_pos - 10, ccid_header->dwLength);
619821
+        goto err;
619821
+    }
619821
 
619821
     DPRINTF(s, D_MORE_INFO, "%s %x %s\n", __func__,
619821
             ccid_header->bMessageType,
619821
-- 
619821
1.8.3.1
619821