Re: [PATCH] USB: prevent overlapping access by usb-storage and usbfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

On 01/14/2013 11:36 PM, Sergei Shtylyov wrote:

> Serialize usb-storage operations with usbfs and 'cat /proc/bus/usb/devices',
> so that they cannot disturb storage by seemingly harmless control reads.

> This patch was adapted from 2.4.28 patch by Pete Zaitcev -- which I even had to
> reconstruct as I have never found it in its final  form.  That patch dates back
> to 2004 and it unfortunately wasn't applied to 2.6 branch in the same form back
> then (it was applied in another form and then immediately reverted). Despite 8+
> years passing from that moment, the vendors didn't stop producing USB devices
> that require this patch. Two recent examples are SanDisk Cruzer Slice 8GB and
> Kingston DataTraveller 100 G2 32GB.  In the latter case, even the enumeration
> fails as the INQUIRY command takes 2.8 seconds to finish, so 'udev' also comes
> into action with its control requests, with neither completing normally.

> Signed-off-by: Sergei Shtylyov <sshtylyov@xxxxxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx

> ---
> This patch is atop of 'usb-linus' branch of Greg's tree...

>  drivers/usb/core/devices.c      |   13 +++++++++++--
>  drivers/usb/core/devio.c        |    7 +++++++
>  drivers/usb/core/usb.c          |    2 ++
>  drivers/usb/storage/transport.c |   11 +++++++++++
>  include/linux/usb.h             |    4 ++++
>  5 files changed, 35 insertions(+), 2 deletions(-)

> Index: usb/drivers/usb/core/devio.c
> ===================================================================
> --- usb.orig/drivers/usb/core/devio.c
> +++ usb/drivers/usb/core/devio.c
> @@ -1983,6 +1983,12 @@ static long usbdev_do_ioctl(struct file 
>  		return -ENODEV;
>  	}
>  
> +	/*
> +	 * Grab device's exclusive_access mutex to prevent its driver from
> +	 * using this device while it is being accessed by us.
> +	 */
> +	mutex_lock(&dev->exclusive_access);
> +
>  	switch (cmd) {
>  	case USBDEVFS_CONTROL:
>  		snoop(&dev->dev, "%s: CONTROL\n", __func__);
> @@ -2138,6 +2144,7 @@ static long usbdev_do_ioctl(struct file 
>  		ret = proc_disconnect_claim(ps, p);
>  		break;
>  	}
> +	mutex_unlock(&dev->exclusive_access);
>  	usb_unlock_device(dev);
>  	if (ret >= 0)
>  		inode->i_atime = CURRENT_TIME;

   Forgot to mention the side effect of the patch: one can't submit read and
write URB simultaneously via USBDEVFS_BULK ioctl(). That has been dealt in 2.4
by later patch by Pete, which I can try to port if needed.

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux