From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW3Na-0005e9-AB for qemu-devel@nongnu.org; Wed, 17 Feb 2016 09:46:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aW3NX-0004Zr-56 for qemu-devel@nongnu.org; Wed, 17 Feb 2016 09:46:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55506) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aW3NW-0004Zg-Vn for qemu-devel@nongnu.org; Wed, 17 Feb 2016 09:46:55 -0500 Message-ID: <1455720412.9127.36.camel@redhat.com> From: Gerd Hoffmann Date: Wed, 17 Feb 2016 15:46:52 +0100 In-Reply-To: References: <1454669651-29411-1-git-send-email-ppandit@redhat.com> <1455633230.7504.107.camel@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] usb: check RNDIS buffer offsets & length List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: P J P Cc: Qinghao Tang , Qemu Developers On Mi, 2016-02-17 at 13:55 +0530, P J P wrote: > +-- On Tue, 16 Feb 2016, Gerd Hoffmann wrote --+ > | > @@ -172,11 +172,18 @@ static void do_token_in(USBDevice *s, USBPacket= *p) > | > assert(p->ep->nr =3D=3D 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 =3D USB_RET_STALL; > | > + return; > | > + } > |=20 > | Why this is needed? All control transfers go through do_token_setup > | first, so with the check moved in do_token_setup we should never ever > | trigger it here ... >=20 > usb_handle_packet > -> usb_process_one > -> do_token_in >=20 > Is it possible for a guest to call do_token_in, without calling=20 > do_token_setup first? For anything interesting to happen in do_token_in() setup_state must be set to either ACK or DATA, and for that to be the case do_token_setup() must run first. I don't think the guest can trick qemu to go straight to do_token_in(). Also s->setup_len is set in do_token_setup() only, verifying it once (after setting it from guest-supplied data) should be enough. cheers, Gerd