• Reilly Grant's avatar
    usb: devio: Add ioctl to disallow detaching kernel USB drivers. · d883f52e
    Reilly Grant authored
    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: default avatarReilly Grant <reillyg@chromium.org>
    Acked-by: default avatarAlan Stern <stern@rowland.harvard.edu>
    Signed-off-by: default avatarEmilio López <emilio.lopez@collabora.co.uk>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    d883f52e
Name
Last commit
Last update
..
CREDITS Loading commit data...
URB.txt Loading commit data...
WUSB-Design-overview.txt Loading commit data...
acm.txt Loading commit data...
anchors.txt Loading commit data...
authorization.txt Loading commit data...
bulk-streams.txt Loading commit data...
callbacks.txt Loading commit data...
chipidea.txt Loading commit data...
dma.txt Loading commit data...
dwc3.txt Loading commit data...
ehci.txt Loading commit data...
error-codes.txt Loading commit data...
functionfs.txt Loading commit data...
gadget-testing.txt Loading commit data...
gadget_configfs.txt Loading commit data...
gadget_hid.txt Loading commit data...
gadget_multi.txt Loading commit data...
gadget_printer.txt Loading commit data...
gadget_serial.txt Loading commit data...
hotplug.txt Loading commit data...
iuu_phoenix.txt Loading commit data...
linux-cdc-acm.inf Loading commit data...
linux.inf Loading commit data...
mass-storage.txt Loading commit data...
misc_usbsevseg.txt Loading commit data...
mtouchusb.txt Loading commit data...
ohci.txt Loading commit data...
persist.txt Loading commit data...
power-management.txt Loading commit data...
proc_usb_info.txt Loading commit data...
rio.txt Loading commit data...
usb-help.txt Loading commit data...
usb-serial.txt Loading commit data...
usbdevfs-drop-permissions.c Loading commit data...
usbip_protocol.txt Loading commit data...
usbmon.txt Loading commit data...
wusb-cbaf Loading commit data...