|
|
54cb13 |
From: Prasad J Pandit <pjp@fedoraproject.org>
|
|
|
54cb13 |
Date: Wed, 17 Feb 2016 00:23:41 +0530
|
|
|
54cb13 |
Subject: [PATCH] usb: check RNDIS buffer offsets & length
|
|
|
54cb13 |
|
|
|
54cb13 |
When processing remote NDIS control message packets,
|
|
|
54cb13 |
the USB Net device emulator uses a fixed length(4096) data buffer.
|
|
|
54cb13 |
The incoming informationBufferOffset & Length combination could
|
|
|
54cb13 |
overflow and cross that range. Check control message buffer
|
|
|
54cb13 |
offsets and length to avoid it.
|
|
|
54cb13 |
|
|
|
54cb13 |
Reported-by: Qinghao Tang <luodalongde@gmail.com>
|
|
|
54cb13 |
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
|
|
|
54cb13 |
Message-id: 1455648821-17340-3-git-send-email-ppandit@redhat.com
|
|
|
54cb13 |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
54cb13 |
(cherry picked from commit fe3c546c5ff2a6210f9a4d8561cc64051ca8603e)
|
|
|
54cb13 |
---
|
|
|
54cb13 |
hw/usb/dev-network.c | 9 ++++++---
|
|
|
54cb13 |
1 file changed, 6 insertions(+), 3 deletions(-)
|
|
|
54cb13 |
|
|
|
54cb13 |
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
|
|
|
54cb13 |
index 7800cee..ba3c7a7 100644
|
|
|
54cb13 |
--- a/hw/usb/dev-network.c
|
|
|
54cb13 |
+++ b/hw/usb/dev-network.c
|
|
|
54cb13 |
@@ -914,8 +914,9 @@ static int rndis_query_response(USBNetState *s,
|
|
|
54cb13 |
|
|
|
54cb13 |
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
|
|
|
54cb13 |
buflen = le32_to_cpu(buf->InformationBufferLength);
|
|
|
54cb13 |
- if (bufoffs + buflen > length)
|
|
|
54cb13 |
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
|
|
|
54cb13 |
return USB_RET_STALL;
|
|
|
54cb13 |
+ }
|
|
|
54cb13 |
|
|
|
54cb13 |
infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
|
|
|
54cb13 |
bufoffs + (uint8_t *) buf, buflen, infobuf,
|
|
|
54cb13 |
@@ -960,8 +961,9 @@ static int rndis_set_response(USBNetState *s,
|
|
|
54cb13 |
|
|
|
54cb13 |
bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
|
|
|
54cb13 |
buflen = le32_to_cpu(buf->InformationBufferLength);
|
|
|
54cb13 |
- if (bufoffs + buflen > length)
|
|
|
54cb13 |
+ if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
|
|
|
54cb13 |
return USB_RET_STALL;
|
|
|
54cb13 |
+ }
|
|
|
54cb13 |
|
|
|
54cb13 |
ret = ndis_set(s, le32_to_cpu(buf->OID),
|
|
|
54cb13 |
bufoffs + (uint8_t *) buf, buflen);
|
|
|
54cb13 |
@@ -1211,8 +1213,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
|
|
|
54cb13 |
if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
|
|
|
54cb13 |
uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
|
|
|
54cb13 |
uint32_t size = le32_to_cpu(msg->DataLength);
|
|
|
54cb13 |
- if (offs + size <= len)
|
|
|
54cb13 |
+ if (offs < len && size < len && offs + size <= len) {
|
|
|
54cb13 |
qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size);
|
|
|
54cb13 |
+ }
|
|
|
54cb13 |
}
|
|
|
54cb13 |
s->out_ptr -= len;
|
|
|
54cb13 |
memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
|