patch "usb: gadget: f_fs: Use local copy of descriptors for userspace copy" added to usb-linus
Subsystems (2)
This is a note to let you know that I've just added the patch titled
usb: gadget: f_fs: Use local copy of descriptors for userspace copy
to my usb git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
in the usb-linus branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.
If you have any questions about this process, please let me know.
From a4b98a7512f18534ce33a7e98e49115af59ffa00 Mon Sep 17 00:00:00 2001
From: Vamsi Krishna Samavedam <[email protected]>
Date: Mon, 30 Nov 2020 12:34:53 -0800
Subject: usb: gadget: f_fs: Use local copy of descriptors for userspace copy
The function may be unbound causing the ffs_ep and its descriptors to be freed while userspace is in the middle of an ioctl requesting the same descriptors. Avoid dangling pointer reference by first making a local copy of desctiptors before releasing the spinlock.
--- drivers/usb/gadget/function/f_fs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/f_fs.c +4 -2
@@ -1324,7 +1324,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,case FUNCTIONFS_ENDPOINT_DESC : {int desc_idx; -struct usb_endpoint_descriptor *desc; +struct usb_endpoint_descriptor desc1, *desc;switch (epfile->ffs->gadget->speed) {case USB_SPEED_SUPER :
@@ -1336,10 +1336,12 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,default : desc_idx =0 ; } + desc = epfile->ep->descs[desc_idx]; +memcpy (&desc1, desc, desc->bLength);spin_unlock_irq (&epfile->ffs->eps_lock); - ret =copy_to_user ((void __user *)value, desc, desc->bLength); + ret =copy_to_user ((void __user *)value, &desc1, desc1.bLength);if (ret) ret = -EFAULT ;return ret;
Signature · 1 line
2.29.2