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