Skip to content

Commit 0698f02

Browse files
Linyu Yuangregkh
authored andcommitted
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. Cc: <stable@vger.kernel.org> # 5.15 Reported-by: Michael Wu <michael@allwinnertech.com> Tested-by: Michael Wu <michael@allwinnertech.com> Reviewed-by: John Keeping <john@metanate.com> Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com> Link: https://lore.kernel.org/r/1654863478-26228-3-git-send-email-quic_linyyuan@quicinc.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fb1f16d commit 0698f02

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • drivers/usb/gadget/function

drivers/usb/gadget/function/f_fs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,13 +1080,19 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
10801080
spin_unlock_irq(&epfile->ffs->eps_lock);
10811081

10821082
if (wait_for_completion_interruptible(&io_data->done)) {
1083+
spin_lock_irq(&epfile->ffs->eps_lock);
1084+
if (epfile->ep != ep) {
1085+
ret = -ESHUTDOWN;
1086+
goto error_lock;
1087+
}
10831088
/*
10841089
* To avoid race condition with ffs_epfile_io_complete,
10851090
* dequeue the request first then check
10861091
* status. usb_ep_dequeue API should guarantee no race
10871092
* condition with req->complete callback.
10881093
*/
10891094
usb_ep_dequeue(ep->ep, req);
1095+
spin_unlock_irq(&epfile->ffs->eps_lock);
10901096
wait_for_completion(&io_data->done);
10911097
interrupted = io_data->status < 0;
10921098
}

0 commit comments

Comments
 (0)