staging: gigaset: fix crashes on probe
Subsystems (3)
v2 cover staging: gigaset: fix crashes on probe
Syzbot has been reporting a GPF on probe in the gigaset ISDN driver, which have since been moved to staging.
The first patch fixes that issue, and the next one fixes a second crash found during testing.
The third patch addresses a benign warning in USB core which syzbot is bound to report once the crashes have been fixed.
Johan
Changes in v2
- use usb_endpoint_is_bulk_out() and friends in patch 3/3, and drop patch 4/4 which only renamed an identifier.
Johan Hovold (3):
staging: gigaset: fix general protection fault on probe
staging: gigaset: fix illegal free on probe errors
staging: gigaset: add endpoint-type sanity check
drivers/staging/isdn/gigaset/usb-gigaset.c | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.24.0
PATCH v2 1/3 staging: gigaset: fix general protection fault on probe
Fix a general protection fault when accessing the endpoint descriptors which could be triggered by a malicious device due to missing sanity checks on the number of endpoints.
--- drivers/staging/isdn/gigaset/usb-gigaset.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/staging/isdn/gigaset/usb-gigaset.c +5 -0
@@ -685,6 +685,11 @@ static int gigaset_probe(struct usb_interface *interface,return -ENODEV ; } +if (hostif->desc.bNumEndpoints <2 ) { +dev_err (&interface->dev,"missing endpoints\n" ); +return -ENODEV ; + } +dev_info (&udev->dev,"%s: Device matched ... !\n" , __func__);/* allocate memory for our device state and initialize it */
Signature · 1 line
2.24.0
PATCH v2 2/3 staging: gigaset: fix illegal free on probe errors
In reply to Johan HovoldThe driver failed to initialise its receive-buffer pointer, something which could lead to an illegal free on late probe errors.
Fix this by making sure to clear all driver data at allocation.
--- drivers/staging/isdn/gigaset/usb-gigaset.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/staging/isdn/gigaset/usb-gigaset.c +1 -5
@@ -571,8 +571,7 @@ static int gigaset_initcshw(struct cardstate *cs) {struct usb_cardstate *ucs; - cs->hw.usb = ucs = -kmalloc (sizeof (struct usb_cardstate ),GFP_KERNEL ); + cs->hw.usb = ucs =kzalloc (sizeof (struct usb_cardstate ),GFP_KERNEL );if (!ucs) {pr_err ("out of memory\n" );return -ENOMEM ;
@@ -584,9 +583,6 @@ static int gigaset_initcshw(struct cardstate *cs) ucs->bchars[3 ] =0 ; ucs->bchars[4 ] =0x11 ; ucs->bchars[5 ] =0x13 ; - ucs->bulk_out_buffer =NULL ; - ucs->bulk_out_urb =NULL ; - ucs->read_urb =NULL ;tasklet_init (&cs->write_tasklet, gigaset_modem_fill, (unsigned long ) cs);
Signature · 1 line
2.24.0
PATCH v2 3/3 staging: gigaset: add endpoint-type sanity check
In reply to Johan HovoldAdd missing endpoint-type sanity checks to probe.
This specifically prevents a warning in USB core on URB submission when fuzzing USB descriptors.
--- drivers/staging/isdn/gigaset/usb-gigaset.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/staging/isdn/gigaset/usb-gigaset.c +12 -0
@@ -705,6 +705,12 @@ static int gigaset_probe(struct usb_interface *interface, endpoint = &hostif->endpoint[0 ].desc; +if (!usb_endpoint_is_bulk_out (endpoint)) { +dev_err (&interface->dev,"missing bulk-out endpoint\n" ); + retval = -ENODEV ; + goto error; + } + buffer_size =le16_to_cpu (endpoint->wMaxPacketSize); ucs->bulk_out_size = buffer_size; ucs->bulk_out_epnum =usb_endpoint_num (endpoint);
@@ -724,6 +730,12 @@ static int gigaset_probe(struct usb_interface *interface, endpoint = &hostif->endpoint[1 ].desc; +if (!usb_endpoint_is_int_in (endpoint)) { +dev_err (&interface->dev,"missing int-in endpoint\n" ); + retval = -ENODEV ; + goto error; + } + ucs->busy =0 ; ucs->read_urb =usb_alloc_urb (0 ,GFP_KERNEL );
Signature · 1 line
2.24.0