<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/drivers/usb/core/devio.c, branch v4.9</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v4.9</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v4.9'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2016-09-28T01:06:21Z</updated>
<entry>
<title>fs: Replace CURRENT_TIME with current_time() for inode timestamps</title>
<updated>2016-09-28T01:06:21Z</updated>
<author>
<name>Deepa Dinamani</name>
<email>deepa.kernel@gmail.com</email>
</author>
<published>2016-09-14T14:48:04Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=078cd8279e659989b103359bb22373cc79445bde'/>
<id>urn:sha1:078cd8279e659989b103359bb22373cc79445bde</id>
<content type='text'>
CURRENT_TIME macro is not appropriate for filesystems as it
doesn't use the right granularity for filesystem timestamps.
Use current_time() instead.

CURRENT_TIME is also not y2038 safe.

This is also in preparation for the patch that transitions
vfs timestamps to use 64 bit time and hence make them
y2038 safe. As part of the effort current_time() will be
extended to do range checks. Hence, it is necessary for all
file system timestamps to use current_time(). Also,
current_time() will be transitioned along with vfs to be
y2038 safe.

Note that whenever a single call to current_time() is used
to change timestamps in different inodes, it is because they
share the same time granularity.

Signed-off-by: Deepa Dinamani &lt;deepa.kernel@gmail.com&gt;
Reviewed-by: Arnd Bergmann &lt;arnd@arndb.de&gt;
Acked-by: Felipe Balbi &lt;balbi@kernel.org&gt;
Acked-by: Steven Whitehouse &lt;swhiteho@redhat.com&gt;
Acked-by: Ryusuke Konishi &lt;konishi.ryusuke@lab.ntt.co.jp&gt;
Acked-by: David Sterba &lt;dsterba@suse.com&gt;
Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
</content>
</entry>
<entry>
<title>USB: avoid left shift by -1</title>
<updated>2016-08-23T20:35:20Z</updated>
<author>
<name>Alan Stern</name>
<email>stern@rowland.harvard.edu</email>
</author>
<published>2016-08-23T19:32:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=53e5f36fbd2453ad69a3369a1db62dc06c30a4aa'/>
<id>urn:sha1:53e5f36fbd2453ad69a3369a1db62dc06c30a4aa</id>
<content type='text'>
UBSAN complains about a left shift by -1 in proc_do_submiturb().  This
can occur when an URB is submitted for a bulk or control endpoint on
a high-speed device, since the code doesn't bother to check the
endpoint type; normally only interrupt or isochronous endpoints have
a nonzero bInterval value.

Aside from the fact that the operation is illegal, it shouldn't matter
because the result isn't used.  Still, in theory it could cause a
hardware exception or other problem, so we should work around it.
This patch avoids doing the left shift unless the shift amount is &gt;= 0.

The same piece of code has another problem.  When checking the device
speed (the exponential encoding for interrupt endpoints is used only
by high-speed or faster devices), we need to look for speed &gt;=
USB_SPEED_SUPER as well as speed == USB_SPEED HIGH.  The patch adds
this check.

Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Reported-by: Vittorio Zecca &lt;zeccav@gmail.com&gt;
Tested-by: Vittorio Zecca &lt;zeccav@gmail.com&gt;
Suggested-by: Bjørn Mork &lt;bjorn@mork.no&gt;
CC: &lt;stable@vger.kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>USB: remove race condition in usbfs/libusb when using reap-after-disconnect</title>
<updated>2016-08-09T14:14:18Z</updated>
<author>
<name>Alan Stern</name>
<email>stern@rowland.harvard.edu</email>
</author>
<published>2016-06-10T18:42:55Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5cce438298a0d2a7a857a4a3c3e26aeb8f77b941'/>
<id>urn:sha1:5cce438298a0d2a7a857a4a3c3e26aeb8f77b941</id>
<content type='text'>
Hans de Goede has reported a difficulty in the Linux port of libusb.
When a device is removed, the poll() system call in usbfs starts
returning POLLERR as soon as udev-&gt;state is set to
USB_STATE_NOTATTACHED, but the outstanding URBs are not available for
reaping until some time later (after usbdev_remove() has been called).
This is awkward for libusb or other usbfs clients, although not an
insuperable problem.

At any rate, it's easy to change usbfs so that it returns POLLHUP as
soon as the state becomes USB_STATE_NOTATTACHED but it doesn't return
POLLERR until after the outstanding URBs have completed.  That's what
this patch does; it uses the fact that ps-&gt;list is always on the
dev-&gt;filelist list until usbdev_remove() takes it off, which happens
after all the outstanding URBs have been cancelled.

Signed-off-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Reported-by: Hans de Goede &lt;hdegoede@redhat.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: devio, do not warn when allocation fails</title>
<updated>2016-08-09T14:14:18Z</updated>
<author>
<name>Jiri Slaby</name>
<email>jslaby@suse.cz</email>
</author>
<published>2016-06-15T13:56:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=70f7ca9a0262784d0b80727860a63d64ab228e7b'/>
<id>urn:sha1:70f7ca9a0262784d0b80727860a63d64ab228e7b</id>
<content type='text'>
usbdev_mmap allocates a buffer. The size of the buffer is determined
by a user. So with this code (no need to be root):

	int fd = open("/dev/bus/usb/001/001", O_RDONLY);
	mmap(NULL, 0x800000, PROT_READ, MAP_SHARED, fd, 0);

we can see a warning:

WARNING: CPU: 0 PID: 21771 at ../mm/page_alloc.c:3563 __alloc_pages_slowpath+0x1036/0x16e0()
...
Call Trace:
 [&lt;ffffffff8117a3ae&gt;] ? warn_slowpath_null+0x2e/0x40
 [&lt;ffffffff815178b6&gt;] ? __alloc_pages_slowpath+0x1036/0x16e0
 [&lt;ffffffff81516880&gt;] ? warn_alloc_failed+0x250/0x250
 [&lt;ffffffff8151226b&gt;] ? get_page_from_freelist+0x75b/0x28b0
 [&lt;ffffffff815184e3&gt;] ? __alloc_pages_nodemask+0x583/0x6b0
 [&lt;ffffffff81517f60&gt;] ? __alloc_pages_slowpath+0x16e0/0x16e0
 [&lt;ffffffff810565d4&gt;] ? dma_generic_alloc_coherent+0x104/0x220
 [&lt;ffffffffa0269e56&gt;] ? hcd_buffer_alloc+0x1d6/0x3e0 [usbcore]
 [&lt;ffffffffa0269c80&gt;] ? hcd_buffer_destroy+0xa0/0xa0 [usbcore]
 [&lt;ffffffffa0228f05&gt;] ? usb_alloc_coherent+0x65/0x90 [usbcore]
 [&lt;ffffffffa0275c05&gt;] ? usbdev_mmap+0x1a5/0x770 [usbcore]
...

Allocations like this one should be marked as __GFP_NOWARN. So do so.

The size could be also clipped by something like:
	if (size &gt;= (1 &lt;&lt; (MAX_ORDER + PAGE_SHIFT - 1)))
		return -ENOMEM;
But I think the overall limit of 16M (by usbfs_increase_memory_usage)
is enough, so that we only silence the warning here.

Signed-off-by: Jiri Slaby &lt;jslaby@suse.cz&gt;
Cc: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Cc: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Cc: Steinar H. Gunderson &lt;sesse@google.com&gt;
Cc: Markus Rechberger &lt;mrechberger@gmail.com&gt;
Fixes: f7d34b445a (USB: Add support for usbfs zerocopy.)
Cc: 4.6+ &lt;stable@vger.kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>USB: usbfs: fix potential infoleak in devio</title>
<updated>2016-05-03T21:32:07Z</updated>
<author>
<name>Kangjie Lu</name>
<email>kangjielu@gmail.com</email>
</author>
<published>2016-05-03T20:32:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=681fef8380eb818c0b845fca5d2ab1dcbab114ee'/>
<id>urn:sha1:681fef8380eb818c0b845fca5d2ab1dcbab114ee</id>
<content type='text'>
The stack object “ci” has a total size of 8 bytes. Its last 3 bytes
are padding bytes which are not initialized and leaked to userland
via “copy_to_user”.

Signed-off-by: Kangjie Lu &lt;kjlu@gatech.edu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: devio: declare usbdev_vm_ops as static</title>
<updated>2016-04-28T19:35:36Z</updated>
<author>
<name>Michele Curti</name>
<email>michele.curti@gmail.com</email>
</author>
<published>2016-04-27T19:23:07Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=10871c13608a624562e082196148f1dc4e37005e'/>
<id>urn:sha1:10871c13608a624562e082196148f1dc4e37005e</id>
<content type='text'>
usbdev_vm_ops is used in devio.c only, so declare it as static

Signed-off-by: Michele Curti &lt;michele.curti@gmail.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: devio: Add ioctl to disallow detaching kernel USB drivers.</title>
<updated>2016-03-05T20:05:01Z</updated>
<author>
<name>Reilly Grant</name>
<email>reillyg@chromium.org</email>
</author>
<published>2016-02-21T21:38:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d883f52e1f6d2eca8378e3795f333c1396943873'/>
<id>urn:sha1:d883f52e1f6d2eca8378e3795f333c1396943873</id>
<content type='text'>
The new USBDEVFS_DROP_PRIVILEGES ioctl allows a process to voluntarily
relinquish the ability to issue other ioctls that may interfere with
other processes and drivers that have claimed an interface on the
device.

This commit also includes a simple utility to be able to test the
ioctl, located at Documentation/usb/usbdevfs-drop-permissions.c

Example (with qemu-kvm's input device):

    $ lsusb
    ...
    Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd

    $ usb-devices
    ...
    C:  #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA
    I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=02 Driver=usbhid

    $ sudo ./usbdevfs-drop-permissions /dev/bus/usb/001/002
    OK: privileges dropped!
    Available options:
    [0] Exit now
    [1] Reset device. Should fail if device is in use
    [2] Claim 4 interfaces. Should succeed where not in use
    [3] Narrow interface permission mask
    Which option shall I run?: 1
    ERROR: USBDEVFS_RESET failed! (1 - Operation not permitted)
    Which test shall I run next?: 2
    ERROR claiming if 0 (1 - Operation not permitted)
    ERROR claiming if 1 (1 - Operation not permitted)
    ERROR claiming if 2 (1 - Operation not permitted)
    ERROR claiming if 3 (1 - Operation not permitted)
    Which test shall I run next?: 0

After unbinding usbhid:

    $ usb-devices
    ...
    I:  If#= 0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=02 Driver=(none)

    $ sudo ./usbdevfs-drop-permissions /dev/bus/usb/001/002
    ...
    Which option shall I run?: 2
    OK: claimed if 0
    ERROR claiming if 1 (1 - Operation not permitted)
    ERROR claiming if 2 (1 - Operation not permitted)
    ERROR claiming if 3 (1 - Operation not permitted)
    Which test shall I run next?: 1
    OK: USBDEVFS_RESET succeeded
    Which test shall I run next?: 0

After unbinding usbhid and restricting the mask:

    $ sudo ./usbdevfs-drop-permissions /dev/bus/usb/001/002
    ...
    Which option shall I run?: 3
    Insert new mask: 0
    OK: privileges dropped!
    Which test shall I run next?: 2
    ERROR claiming if 0 (1 - Operation not permitted)
    ERROR claiming if 1 (1 - Operation not permitted)
    ERROR claiming if 2 (1 - Operation not permitted)
    ERROR claiming if 3 (1 - Operation not permitted)

Signed-off-by: Reilly Grant &lt;reillyg@chromium.org&gt;
Acked-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Emilio López &lt;emilio.lopez@collabora.co.uk&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>USB: Add support for usbfs zerocopy.</title>
<updated>2016-02-15T01:11:48Z</updated>
<author>
<name>Steinar H. Gunderson</name>
<email>sesse@google.com</email>
</author>
<published>2016-02-03T21:58:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f7d34b445abc00e979b7cf36b9580ac3d1a47cd8'/>
<id>urn:sha1:f7d34b445abc00e979b7cf36b9580ac3d1a47cd8</id>
<content type='text'>
Add a new interface for userspace to preallocate memory that can be
used with usbfs. This gives two primary benefits:

 - Zerocopy; data no longer needs to be copied between the userspace
   and the kernel, but can instead be read directly by the driver from
   userspace's buffers. This works for all kinds of transfers (even if
   nonsensical for control and interrupt transfers); isochronous also
   no longer need to memset() the buffer to zero to avoid leaking kernel data.

 - Once the buffers are allocated, USB transfers can no longer fail due to
   memory fragmentation; previously, long-running programs could run into
   problems finding a large enough contiguous memory chunk, especially on
   embedded systems or at high rates.

Memory is allocated by using mmap() against the usbfs file descriptor,
and similarly deallocated by munmap(). Once memory has been allocated,
using it as pointers to a bulk or isochronous operation means you will
automatically get zerocopy behavior. Note that this also means you cannot
modify outgoing data until the transfer is complete. The same holds for
data on the same cache lines as incoming data; DMA modifying them at the
same time could lead to your changes being overwritten.

There's a new capability USBDEVFS_CAP_MMAP that userspace can query to see
if the running kernel supports this functionality, if just trying mmap() is
not acceptable.

Largely based on a patch by Markus Rechberger with some updates. The original
patch can be found at:

  http://sundtek.de/support/devio_mmap_v0.4.diff

Signed-off-by: Steinar H. Gunderson &lt;sesse@google.com&gt;
Signed-off-by: Markus Rechberger &lt;mrechberger@gmail.com&gt;
Acked-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>USB: core, devio: use to_usb_device</title>
<updated>2016-01-25T05:00:33Z</updated>
<author>
<name>Geliang Tang</name>
<email>geliangtang@163.com</email>
</author>
<published>2015-12-23T13:26:50Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=69ab55d7be6c3d69fa2e38f2a2bed4e91b9edf8d'/>
<id>urn:sha1:69ab55d7be6c3d69fa2e38f2a2bed4e91b9edf8d</id>
<content type='text'>
Use to_usb_device() instead of open-coding it.

Signed-off-by: Geliang Tang &lt;geliangtang@163.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: Use memdup_user to reuse the code</title>
<updated>2016-01-25T03:45:09Z</updated>
<author>
<name>Rahul Pathak</name>
<email>rpathak@visteon.com</email>
</author>
<published>2015-12-11T05:40:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=73a02d32458ecff5b6241e7e7bd6445f70400bad'/>
<id>urn:sha1:73a02d32458ecff5b6241e7e7bd6445f70400bad</id>
<content type='text'>
Fixing coccicheck warning which recommends to use memdup_user instead
to reimplement its code, using memdup_user simplifies the code

./drivers/usb/core/devio.c:1398:11-18: WARNING opportunity for memdup_user

Signed-off-by: Rahul Pathak &lt;rpathak@visteon.com&gt;
Acked-by: Alan Stern &lt;stern@rowland.harvard.edu&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
