patch "usb: gadget: f_fs: change ep->ep safe in ffs_epfile_io()" 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: change ep->ep safe in ffs_epfile_io()
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 0698f0209d8032e8869525aeb68f65ee7fde12ad Mon Sep 17 00:00:00 2001
From: Linyu Yuan <[email protected]>
Date: Fri, 10 Jun 2022 20:17:58 +0800
Subject: usb: gadget: f_fs: change ep->ep safe in ffs_epfile_io()
In ffs_epfile_io(), when read/write data in blocking mode, it will wait the completion in interruptible mode, if task receive a signal, it will terminate the wait, at same time, if function unbind occurs, ffs_func_unbind() will kfree all eps, ffs_epfile_io() still try to dequeue request by dereferencing ep which may become invalid.
Fix it by add ep spinlock and will not dereference ep if it is not valid.
--- drivers/usb/gadget/function/f_fs.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/gadget/function/f_fs.c +6 -0
@@ -1080,6 +1080,11 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)spin_unlock_irq (&epfile->ffs->eps_lock);if (wait_for_completion_interruptible (&io_data->done)) { +spin_lock_irq (&epfile->ffs->eps_lock); +if (epfile->ep != ep) { + ret = -ESHUTDOWN ; + goto error_lock; + }/* * To avoid race condition with ffs_epfile_io_complete, * dequeue the request first then check
@@ -1087,6 +1092,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)* condition with req->complete callback. */ usb_ep_dequeue (ep->ep, req); +spin_unlock_irq (&epfile->ffs->eps_lock);wait_for_completion (&io_data->done); interrupted = io_data->status <0 ; }
Signature · 1 line
2.36.1