Skip to content

Commit d171853

Browse files
Nikita Zhandarovichgregkh
authored andcommitted
comedi: vmk80xx: fix incomplete endpoint checking
While vmk80xx does have endpoint checking implemented, some things can fall through the cracks. Depending on the hardware model, URBs can have either bulk or interrupt type, and current version of vmk80xx_find_usb_endpoints() function does not take that fully into account. While this warning does not seem to be too harmful, at the very least it will crash systems with 'panic_on_warn' set on them. Fix the issue found by Syzkaller [1] by somewhat simplifying the endpoint checking process with usb_find_common_endpoints() and ensuring that only expected endpoint types are present. This patch has not been tested on real hardware. [1] Syzkaller report: usb 1-1: BOGUS urb xfer, pipe 1 != type 3 WARNING: CPU: 0 PID: 781 at drivers/usb/core/urb.c:504 usb_submit_urb+0xc4e/0x18c0 drivers/usb/core/urb.c:503 ... Call Trace: <TASK> usb_start_wait_urb+0x113/0x520 drivers/usb/core/message.c:59 vmk80xx_reset_device drivers/comedi/drivers/vmk80xx.c:227 [inline] vmk80xx_auto_attach+0xa1c/0x1a40 drivers/comedi/drivers/vmk80xx.c:818 comedi_auto_config+0x238/0x380 drivers/comedi/drivers.c:1067 usb_probe_interface+0x5cd/0xb00 drivers/usb/core/driver.c:399 ... Similar issue also found by Syzkaller: Link: https://syzkaller.appspot.com/bug?extid=5205eb2f17de3e01946e Reported-and-tested-by: [email protected] Cc: stable <[email protected]> Fixes: 49253d5 ("staging: comedi: vmk80xx: factor out usb endpoint detection") Reviewed-by: Ian Abbott <[email protected]> Signed-off-by: Nikita Zhandarovich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f6085a9 commit d171853

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

drivers/comedi/drivers/vmk80xx.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -641,33 +641,22 @@ static int vmk80xx_find_usb_endpoints(struct comedi_device *dev)
641641
struct vmk80xx_private *devpriv = dev->private;
642642
struct usb_interface *intf = comedi_to_usb_interface(dev);
643643
struct usb_host_interface *iface_desc = intf->cur_altsetting;
644-
struct usb_endpoint_descriptor *ep_desc;
645-
int i;
646-
647-
if (iface_desc->desc.bNumEndpoints != 2)
648-
return -ENODEV;
649-
650-
for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
651-
ep_desc = &iface_desc->endpoint[i].desc;
652-
653-
if (usb_endpoint_is_int_in(ep_desc) ||
654-
usb_endpoint_is_bulk_in(ep_desc)) {
655-
if (!devpriv->ep_rx)
656-
devpriv->ep_rx = ep_desc;
657-
continue;
658-
}
644+
struct usb_endpoint_descriptor *ep_rx_desc, *ep_tx_desc;
645+
int ret;
659646

660-
if (usb_endpoint_is_int_out(ep_desc) ||
661-
usb_endpoint_is_bulk_out(ep_desc)) {
662-
if (!devpriv->ep_tx)
663-
devpriv->ep_tx = ep_desc;
664-
continue;
665-
}
666-
}
647+
if (devpriv->model == VMK8061_MODEL)
648+
ret = usb_find_common_endpoints(iface_desc, &ep_rx_desc,
649+
&ep_tx_desc, NULL, NULL);
650+
else
651+
ret = usb_find_common_endpoints(iface_desc, NULL, NULL,
652+
&ep_rx_desc, &ep_tx_desc);
667653

668-
if (!devpriv->ep_rx || !devpriv->ep_tx)
654+
if (ret)
669655
return -ENODEV;
670656

657+
devpriv->ep_rx = ep_rx_desc;
658+
devpriv->ep_tx = ep_tx_desc;
659+
671660
if (!usb_endpoint_maxp(devpriv->ep_rx) || !usb_endpoint_maxp(devpriv->ep_tx))
672661
return -EINVAL;
673662

0 commit comments

Comments
 (0)