Skip to content

Commit a4b98a7

Browse files
Vamsi Krishna Samavedamgregkh
authored andcommitted
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: c559a35 ("usb: gadget: f_fs: add ioctl returning ep descriptor") Reviewed-by: Peter Chen <[email protected]> Signed-off-by: Vamsi Krishna Samavedam <[email protected]> Signed-off-by: Jack Pham <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 45c5775 commit a4b98a7

File tree

1 file changed

+4
-2
lines changed
  • drivers/usb/gadget/function

1 file changed

+4
-2
lines changed

drivers/usb/gadget/function/f_fs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
13241324
case FUNCTIONFS_ENDPOINT_DESC:
13251325
{
13261326
int desc_idx;
1327-
struct usb_endpoint_descriptor *desc;
1327+
struct usb_endpoint_descriptor desc1, *desc;
13281328

13291329
switch (epfile->ffs->gadget->speed) {
13301330
case USB_SPEED_SUPER:
@@ -1336,10 +1336,12 @@ static long ffs_epfile_ioctl(struct file *file, unsigned code,
13361336
default:
13371337
desc_idx = 0;
13381338
}
1339+
13391340
desc = epfile->ep->descs[desc_idx];
1341+
memcpy(&desc1, desc, desc->bLength);
13401342

13411343
spin_unlock_irq(&epfile->ffs->eps_lock);
1342-
ret = copy_to_user((void __user *)value, desc, desc->bLength);
1344+
ret = copy_to_user((void __user *)value, &desc1, desc1.bLength);
13431345
if (ret)
13441346
ret = -EFAULT;
13451347
return ret;

0 commit comments

Comments
 (0)