From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVkky-0004Or-Kr for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:53:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVkkx-0007C4-NC for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:53:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37787) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVkkx-0007C0-I6 for qemu-devel@nongnu.org; Tue, 16 Feb 2016 13:53:51 -0500 From: P J P Date: Wed, 17 Feb 2016 00:23:40 +0530 Message-Id: <1455648821-17340-2-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 1/2] usb: check RNDIS message 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 packet length could exceed this limit. Add a check to avoid it. Signed-off-by: Prasad J Pandit --- hw/usb/core.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) Update as per review -> https://lists.gnu.org/archive/html/qemu-devel/2016-02/msg03475.html diff --git a/hw/usb/core.c b/hw/usb/core.c index d0025db..7f46370 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -128,9 +128,16 @@ static void do_token_setup(USBDevice *s, USBPacket *p) } usb_packet_copy(p, s->setup_buf, p->iov.size); + s->setup_index = 0; p->actual_length = 0; s->setup_len = (s->setup_buf[7] << 8) | s->setup_buf[6]; - s->setup_index = 0; + if (s->setup_len > sizeof(s->data_buf)) { + fprintf(stderr, + "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n", + s->setup_len, sizeof(s->data_buf)); + p->status = USB_RET_STALL; + return; + } request = (s->setup_buf[0] << 8) | s->setup_buf[1]; value = (s->setup_buf[3] << 8) | s->setup_buf[2]; @@ -151,13 +158,6 @@ static void do_token_setup(USBDevice *s, USBPacket *p) } s->setup_state = SETUP_STATE_DATA; } else { - if (s->setup_len > sizeof(s->data_buf)) { - fprintf(stderr, - "usb_generic_handle_packet: ctrl buffer too small (%d > %zu)\n", - s->setup_len, sizeof(s->data_buf)); - p->status = USB_RET_STALL; - return; - } if (s->setup_len == 0) s->setup_state = SETUP_STATE_ACK; else @@ -176,7 +176,7 @@ static void do_token_in(USBDevice *s, USBPacket *p) request = (s->setup_buf[0] << 8) | s->setup_buf[1]; value = (s->setup_buf[3] << 8) | s->setup_buf[2]; index = (s->setup_buf[5] << 8) | s->setup_buf[4]; - + switch(s->setup_state) { case SETUP_STATE_ACK: if (!(s->setup_buf[0] & USB_DIR_IN)) { -- 2.5.0