mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-29 15:43:59 +08:00
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.
Fixes: c559a35341
("usb: gadget: f_fs: add ioctl returning ep descriptor")
Reviewed-by: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Vamsi Krishna Samavedam <vskrishn@codeaurora.org>
Signed-off-by: Jack Pham <jackp@codeaurora.org>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20201130203453.28154-1-jackp@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
45c5775460
commit
a4b98a7512
@ -1324,7 +1324,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
|
|||||||
case FUNCTIONFS_ENDPOINT_DESC:
|
case FUNCTIONFS_ENDPOINT_DESC:
|
||||||
{
|
{
|
||||||
int desc_idx;
|
int desc_idx;
|
||||||
struct usb_endpoint_descriptor *desc;
|
struct usb_endpoint_descriptor desc1, *desc;
|
||||||
|
|
||||||
switch (epfile->ffs->gadget->speed) {
|
switch (epfile->ffs->gadget->speed) {
|
||||||
case USB_SPEED_SUPER:
|
case USB_SPEED_SUPER:
|
||||||
@ -1336,10 +1336,12 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
|
|||||||
default:
|
default:
|
||||||
desc_idx = 0;
|
desc_idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
desc = epfile->ep->descs[desc_idx];
|
desc = epfile->ep->descs[desc_idx];
|
||||||
|
memcpy(&desc1, desc, desc->bLength);
|
||||||
|
|
||||||
spin_unlock_irq(&epfile->ffs->eps_lock);
|
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)
|
if (ret)
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user