Skip to contentSkip to conversation

usb: check page select value while processing iTD

PATCH In review P J P 2 participants 2 messages Jan 19, 2016 – Jan 20, 2016

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/1 usb: check page select value while processing iTD

From: Prasad J Pandit <[email protected]>

While processing isochronous transfer descriptors(iTD), the page select(PG) field value could lead to an OOB read access. Add check to avoid it.

---
 hw/usb/hcd-ehci.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
hw/usb/hcd-ehci.c +6 -4
index d07f228..c40013e 100644
@@ -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);
Signature · 1 line
2.5.0
#1 lore raw
Quoted 3 lines · P J P

While processing isochronous transfer descriptors(iTD), the page select(PG) field value could lead to an OOB read access. Add check to avoid it.

Added to usb patch queue.

thanks,
Gerd