Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752154AbdI2LnG (ORCPT ); Fri, 29 Sep 2017 07:43:06 -0400 Received: from mail-oi0-f42.google.com ([209.85.218.42]:53400 "EHLO mail-oi0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751091AbdI2LnD (ORCPT ); Fri, 29 Sep 2017 07:43:03 -0400 X-Google-Smtp-Source: AOwi7QDss18Yp2lThDRxx4Tv4py4aChcCwZRtmEnFJXitiaLnWaSiDf8PELKPVs2bv/SrTF6wSjN/3DoyQyriPNQJSM= MIME-Version: 1.0 In-Reply-To: References: From: Andrey Konovalov Date: Fri, 29 Sep 2017 13:43:02 +0200 Message-ID: Subject: Re: usb/misc/usbtest: null-ptr-deref in usbtest_probe/get_endpoints To: Alan Stern Cc: Greg Kroah-Hartman , "Gustavo A. R. Silva" , Felipe Balbi , Peter Chen , Colin Ian King , USB list , LKML , Dmitry Vyukov , Kostya Serebryany , syzkaller Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2652 Lines: 77 On Thu, Sep 28, 2017 at 7:01 PM, Alan Stern wrote: > On Thu, 28 Sep 2017, Andrey Konovalov wrote: > >> Hi! >> >> I've got the following report while fuzzing the kernel with syzkaller. >> >> On commit dc972a67cc54585bd83ad811c4e9b6ab3dcd427e (4.14-rc2+). >> >> It seems that out pointer ends up being NULL and kernel crashes on >> access to out->desc.bEndpointAddress. >> >> gadgetfs: bound to dummy_udc driver >> usb 1-1: new full-speed USB device number 2 using dummy_hcd >> gadgetfs: connected >> gadgetfs: disconnected >> gadgetfs: connected >> usb 1-1: config 2 interface 0 altsetting 206 endpoint 0x81 has invalid >> maxpacket 2040, setting to 64 >> usb 1-1: config 2 interface 0 altsetting 206 has an invalid endpoint >> with address 0xFF, skipping >> usb 1-1: config 2 interface 0 altsetting 206 endpoint 0x5 has an >> invalid bInterval 255, changing to 4 >> usb 1-1: config 2 interface 0 has no altsetting 0 >> usb 1-1: New USB device found, idVendor=0525, idProduct=a4a0 >> usb 1-1: New USB device strings: Mfr=0, Product=185, SerialNumber=1 >> usb 1-1: Product: a >> usb 1-1: SerialNumber: a >> gadgetfs: configuration #2 >> kasan: CONFIG_KASAN_INLINE enabled >> kasan: GPF could be caused by NULL-ptr deref or user memory access >> general protection fault: 0000 [#1] PREEMPT SMP KASAN >> Modules linked in: >> CPU: 1 PID: 1845 Comm: kworker/1:2 Not tainted >> 4.14.0-rc2-42664-gaf7d1481b3cb #297 >> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 >> Workqueue: usb_hub_wq hub_event >> task: ffff880064328000 task.stack: ffff880064398000 >> RIP: 0010:get_endpoints drivers/usb/misc/usbtest.c:208 >> RIP: 0010:usbtest_probe+0x114f/0x1ef0 drivers/usb/misc/usbtest.c:2706 > > This looks like a simple logic error. > > Alan Stern Hi Alan, This fixes it. Tested-by: Andrey Konovalov Thanks! > > > > Index: usb-4.x/drivers/usb/misc/usbtest.c > =================================================================== > --- usb-4.x.orig/drivers/usb/misc/usbtest.c > +++ usb-4.x/drivers/usb/misc/usbtest.c > @@ -202,12 +202,13 @@ found: > return tmp; > } > > - if (in) { > + if (in) > dev->in_pipe = usb_rcvbulkpipe(udev, > in->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); > + if (out) > dev->out_pipe = usb_sndbulkpipe(udev, > out->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); > - } > + > if (iso_in) { > dev->iso_in = &iso_in->desc; > dev->in_iso_pipe = usb_rcvisocpipe(udev, >