From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVkl1-0004Rp-Gw for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:53:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVkl0-0007Cq-Kz for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:53:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35230) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVkl0-0007Cm-GC for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:53:54 -0500 From: P J P Date: Wed, 17 Feb 2016 00:23:41 +0530 Message-Id: <1455648821-17340-3-git-send-email-ppandit@redhat.com> In-Reply-To: <1455648821-17340-1-git-send-email-ppandit@redhat.com> References: <1455648821-17340-1-git-send-email-ppandit@redhat.com> Subject: [Qemu-devel] [PATCH 2/2] usb: check RNDIS buffer offsets & length List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Qemu Developers Cc: Qinghao Tang , Gerd Hoffmann , Prasad J Pandit From: Prasad J Pandit When processing remote NDIS control message packets, the USB Net device emulator uses a fixed length(4096) data buffer. The incoming informationBufferOffset & Length combination could overflow and cross that range. Check control message buffer offsets and length to avoid it. Reported-by: Qinghao Tang Signed-off-by: Prasad J Pandit --- hw/usb/dev-network.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) Update as per review -> https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03475.html diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 8a4ff49..180adce 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -915,8 +915,9 @@ static int rndis_query_response(USBNetState *s, bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8; buflen = le32_to_cpu(buf->InformationBufferLength); - if (bufoffs + buflen > length) + if (buflen > length || bufoffs >= length || bufoffs + buflen > length) { return USB_RET_STALL; + } infobuflen = ndis_query(s, le32_to_cpu(buf->OID), bufoffs + (uint8_t *) buf, buflen, infobuf, @@ -961,8 +962,9 @@ static int rndis_set_response(USBNetState *s, bufoffs = le32_to_cpu(buf->InformationBufferOffset) + 8; buflen = le32_to_cpu(buf->InformationBufferLength); - if (bufoffs + buflen > length) + if (buflen > length || bufoffs >= length || bufoffs + buflen > length) { return USB_RET_STALL; + } ret = ndis_set(s, le32_to_cpu(buf->OID), bufoffs + (uint8_t *) buf, buflen); @@ -1212,8 +1214,9 @@ static void usb_net_handle_dataout(USBNetState *s, USBPacket *p) if (le32_to_cpu(msg->MessageType) == RNDIS_PACKET_MSG) { uint32_t offs = 8 + le32_to_cpu(msg->DataOffset); uint32_t size = le32_to_cpu(msg->DataLength); - if (offs + size <= len) + if (offs < len && size < len && offs + size <= len) { qemu_send_packet(qemu_get_queue(s->nic), s->out_buf + offs, size); + } } s->out_ptr -= len; memmove(s->out_buf, &s->out_buf[len], s->out_ptr); -- 2.5.0