aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/core/devio.c
diff options
context:
space:
mode:
authorJann Horn <[email protected]>2024-10-16 15:24:06 +0000
committerGreg Kroah-Hartman <[email protected]>2024-10-17 06:36:52 +0000
commit3ea36dc8ddd72d92d737612507f98dfaf3b77c3f (patch)
tree71dc9a3f7b55b84b211e0259aa9870aa9cdf5c9d /drivers/usb/core/devio.c
parentusb: gadget: uvc: configfs: Add frame-based frame format support (diff)
downloadkernel-3ea36dc8ddd72d92d737612507f98dfaf3b77c3f.tar.gz
kernel-3ea36dc8ddd72d92d737612507f98dfaf3b77c3f.zip
usb: require FMODE_WRITE for usbdev_mmap()
usbdev_mmap() creates VMAs which can only be used through usbdev_do_ioctl(), which requires FMODE_WRITE; so usbdev_mmap() is only useful with FMODE_WRITE. On typical Linux systems, files at /dev/bus/usb/*/* are mode 0664, so UIDs without any special privileges can't use usbdev_do_ioctl(), but they can still execute the usbdev_mmap() codepath. Check for FMODE_WRITE in usbdev_mmap() to reduce attack surface a little bit. Signed-off-by: Jann Horn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
Diffstat (limited to 'drivers/usb/core/devio.c')
-rw-r--r--drivers/usb/core/devio.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 3beb6a862e80..5363468a282f 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -238,6 +238,9 @@ static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
dma_addr_t dma_handle = DMA_MAPPING_ERROR;
int ret;
+ if (!(file->f_mode & FMODE_WRITE))
+ return -EPERM;
+
ret = usbfs_increase_memory_usage(size + sizeof(struct usb_memory));
if (ret)
goto error;