Received: from eggs.gnu.org ([2001:4830:134:3::10]:54996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLcOg-0008CY-Pp for qemu-devel@nongnu.org; Tue, 19 Jan 2016 14:56:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLcOc-0003kT-Hp for qemu-devel@nongnu.org; Tue, 19 Jan 2016 14:56:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLcOc-0003il-D8 for qemu-devel@nongnu.org; Tue, 19 Jan 2016 14:56:54 -0500 From: P J P Date: Wed, 20 Jan 2016 01:26:46 +0530 Message-Id: <1453233406-12165-1-git-send-email-ppandit@redhat.com> Subject: [Qemu-devel] [PATCH] usb: check page select value while processing iTD List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Qinghao Tang , Gerd Hoffmann , Prasad J Pandit From: Prasad J Pandit While processing isochronous transfer descriptors(iTD), the page select(PG) field value could lead to an OOB read access. Add check to avoid it. Reported-by: Qinghao Tang Signed-off-by: Prasad J Pandit --- hw/usb/hcd-ehci.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index d07f228..c40013e 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -1404,21 +1404,23 @@ static int ehci_process_itd(EHCIState *ehci, if (itd->transact[i] & ITD_XACT_ACTIVE) { pg = get_field(itd->transact[i], ITD_XACT_PGSEL); off = itd->transact[i] & ITD_XACT_OFFSET_MASK; - ptr1 = (itd->bufptr[pg] & ITD_BUFPTR_MASK); - ptr2 = (itd->bufptr[pg+1] & ITD_BUFPTR_MASK); len = get_field(itd->transact[i], ITD_XACT_LENGTH); if (len > max * mult) { len = max * mult; } - - if (len > BUFF_SIZE) { + if (len > BUFF_SIZE || pg > 6) { return -1; } + ptr1 = (itd->bufptr[pg] & ITD_BUFPTR_MASK); qemu_sglist_init(&ehci->isgl, ehci->device, 2, ehci->as); if (off + len > 4096) { /* transfer crosses page border */ + if (pg == 6) { + return -1; /* avoid page pg + 1 */ + } + ptr2 = (itd->bufptr[pg + 1] & ITD_BUFPTR_MASK); uint32_t len2 = off + len - 4096; uint32_t len1 = len - len2; qemu_sglist_add(&ehci->isgl, ptr1 + off, len1); -- 2.5.0