f7153f0
From: Prasad J Pandit <address@hidden>
f7153f0
f7153f0
When processing remote NDIS control message packets,
f7153f0
the USB Net device emulator uses a fixed length(4096) data buffer.
f7153f0
The incoming informationBufferOffset & Length combination could
f7153f0
overflow and cross that range. Check control message buffer
f7153f0
offsets and length to avoid it.
f7153f0
f7153f0
Reported-by: Qinghao Tang <address@hidden>
f7153f0
Signed-off-by: Prasad J Pandit <address@hidden>
f7153f0
---
f7153f0
 hw/usb/dev-network.c | 9 ++++++---
f7153f0
 1 file changed, 6 insertions(+), 3 deletions(-)
f7153f0
f7153f0
Update as per review
f7153f0
  -> https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03475.html
f7153f0
f7153f0
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
f7153f0
index 8a4ff49..180adce 100644
f7153f0
--- a/tools/qemu-xen-traditional/hw/usb-net.c
f7153f0
+++ b/tools/qemu-xen-traditional/hw/usb-net.c
f7153f0
@@ -915,8 +915,9 @@ static int rndis_query_response(USBNetState *s,
f7153f0
 
f7153f0
     bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
f7153f0
     buflen = le32_to_cpu(buf->InformationBufferLength);
f7153f0
-    if (bufoffs + buflen > length)
f7153f0
+    if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
f7153f0
         return USB_RET_STALL;
f7153f0
+    }
f7153f0
 
f7153f0
     infobuflen = ndis_query(s, le32_to_cpu(buf->OID),
f7153f0
                             bufoffs + (uint8_t *) buf, buflen, infobuf,
f7153f0
@@ -961,8 +962,9 @@ static int rndis_set_response(USBNetState *s,
f7153f0
 
f7153f0
     bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8;
f7153f0
     buflen = le32_to_cpu(buf->InformationBufferLength);
f7153f0
-    if (bufoffs + buflen > length)
f7153f0
+    if (buflen > length || bufoffs >= length || bufoffs + buflen > length) {
f7153f0
         return USB_RET_STALL;
f7153f0
+    }
f7153f0
 
f7153f0
     ret = ndis_set(s, le32_to_cpu(buf->OID),
f7153f0
                     bufoffs + (uint8_t *) buf, buflen);
f7153f0
@@ -1212,8 +1214,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p)
f7153f0
     if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) {
f7153f0
         uint32_t offs = 8 + le32_to_cpu(msg->DataOffset);
f7153f0
         uint32_t size = le32_to_cpu(msg->DataLength);
f7153f0
-        if (offs + size <= len)
f7153f0
+        if (offs < len && size < len && offs + size <= len) {
f7153f0
             qemu_send_packet(s->vc, s->out_buf + offs, size);
f7153f0
+        }
f7153f0
     }
f7153f0
     s->out_ptr -= len;
f7153f0
     memmove(s->out_buf, &s->out_buf[len], s->out_ptr);
f7153f0
-- 
f7153f0
2.5.0