Re: WARNING in usbhid_raw_request/usb_submit_urb (3)
From: Alan Stern
Date: Thu Apr 02 2020 - 15:00:06 EST
On Thu, 2 Apr 2020, syzbot wrote:
> Hello,
>
> syzbot has tested the proposed patch but the reproducer still triggered crash:
> WARNING in usbhid_raw_request/usb_submit_urb
>
> ------------[ cut here ]------------
> usb 3-1: BOGUS urb xfer, pipe 2 != type 2, ep addr 0x00, pipe 0x80001a00, xfertype 0
Not much help, I'm afraid. The pipe value decodes to:
Direction: OUT
Device address: 26 (which agrees with the console output)
Endpoint: 0
Pipe type: Control (which is appropriate for ep 0
and agrees with xfertype)
Unfortunately, the values printed here need not be the same as the
values checked by usb_urb_ep_type_check(), if either the URB or the
descriptor is modified concurrently by another thread.
Let's try a different approach. Since this modifies the code before
the test, it may not trigger the warning. But it's worth a try.
Alan Stern
#syz test: https://github.com/google/kasan.git 0fa84af8
Index: usb-devel/drivers/usb/core/urb.c
===================================================================
--- usb-devel.orig/drivers/usb/core/urb.c
+++ usb-devel/drivers/usb/core/urb.c
@@ -199,15 +199,27 @@ static const int pipetypes[4] = {
* given urb. It returns 0 if the urb contains a valid endpoint, otherwise
* a negative error code.
*/
+unsigned int alan_pipe, alan_epaddr, alan_epattr;
int usb_urb_ep_type_check(const struct urb *urb)
{
const struct usb_host_endpoint *ep;
+ unsigned int pipe, epattr;
- ep = usb_pipe_endpoint(urb->dev, urb->pipe);
- if (!ep)
+ pipe = READ_ONCE(urb->pipe);
+ ep = usb_pipe_endpoint(urb->dev, pipe);
+ if (!ep) {
+ alan_pipe = pipe;
+ alan_epattr = 0;
+ alan_epaddr = 0xff;
return -EINVAL;
- if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)])
+ }
+ epattr = READ_ONCE(ep->desc.bmAttributes);
+ if (usb_pipetype(pipe) != pipetypes[epattr & USB_ENDPOINT_XFERTYPE_MASK]) {
+ alan_pipe = pipe;
+ alan_epattr = epattr;
+ alan_epaddr = ep->desc.bEndpointAddress;
return -EINVAL;
+ }
return 0;
}
EXPORT_SYMBOL_GPL(usb_urb_ep_type_check);
@@ -475,8 +487,9 @@ int usb_submit_urb(struct urb *urb, gfp_
/* Check that the pipe's type matches the endpoint's type */
if (usb_urb_ep_type_check(urb))
- dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
- usb_pipetype(urb->pipe), pipetypes[xfertype]);
+ dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x, pipe 0x%x, ep attr 0x%02x, ep addr 0x%02x\n",
+ usb_pipetype(urb->pipe), pipetypes[xfertype],
+ alan_pipe, alan_epattr, alan_epaddr);
/* Check against a simple/standard policy */
allowed = (URB_NO_TRANSFER_DMA_MAP | URB_NO_INTERRUPT | URB_DIR_MASK |