linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Inconsistency in how URBs are unlinked
@ 2020-01-16 21:34 Chris Dickens
  2020-01-16 21:40 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Chris Dickens @ 2020-01-16 21:34 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, Alan Stern

Hi,

A bug [1] has been reported against libusb about a segfault that
occurs when a device is disconnected while processing isochronous
transfers.  In my investigation I discovered an interesting
inconsistency in how URBs are unlinked across the USB core.

The usbfs driver will unlink URBs in the same order they are
submitted.  From what I can see this code is executed when
setting/releasing an interface or when alloc'ing/freeing streams.  I
see there is also a call within the usbfs driver's disconnect
function, but that appears to be a no-op (is this really the case?) as
by the time that function is called the interface would have already
been disabled and thus usb_hcd_flush_endpoint() would have been
called.

Since commit 2eac136243 ("usb: core: unlink urbs from the tail of the
endpoint's urb_list"), the usb_hcd_flush_endpoint() function will
unlink URBs in the reverse order of submission.  This subtle change is
what led to the crash within libusb.  The bug manifests when transfers
within libusb are split into multiple URBs.  Prior to this change, the
order in which URBs were reaped matched the order in which they were
submitted.  Internally libusb expects this order to match and frees
memory when it encounters the last URB in a multi-URB transfer, but
since it reaps the last URB first the memory is freed right away and
things take a turn when the freed memory is accessed when reaping the
other URB(s) in that same transfer.

I will fix libusb to account for this behavior, but I thought it worth
mentioning as this new behavior isn't what I (and possibly others)
necessarily expect.

Chris

[1] https://github.com/libusb/libusb/issues/607

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-01-17 15:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 21:34 Inconsistency in how URBs are unlinked Chris Dickens
2020-01-16 21:40 ` Greg Kroah-Hartman
2020-01-16 22:06   ` Alan Stern
2020-01-17  4:48     ` Chris Dickens
2020-01-17 15:47     ` [PATCH] USB: usbfs: Always unlink URBs in reverse order Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).