Skip to content

Commit

Permalink
usb: gadget: f_fs: Ensure io_completion_wq is idle during unbind
Browse files Browse the repository at this point in the history
commit 6fc1db5 upstream.

During unbind, ffs_func_eps_disable() will be executed, resulting in
completion callbacks for any pending USB requests.  When using AIO,
irrespective of the completion status, io_data work is queued to
io_completion_wq to evaluate and handle the completed requests.  Since
work runs asynchronously to the unbind() routine, there can be a
scenario where the work runs after the USB gadget has been fully
removed, resulting in accessing of a resource which has been already
freed. (i.e. usb_ep_free_request() accessing the USB ep structure)

Explicitly drain the io_completion_wq, instead of relying on the
destroy_workqueue() (in ffs_data_put()) to make sure no pending
completion work items are running.

Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/1621644261-1236-1-git-send-email-wcheng@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Wesley Cheng authored and gregkh committed Jun 16, 2021
1 parent 0b3bb79 commit 5cead89
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions drivers/usb/gadget/function/f_fs.c
Expand Up @@ -3566,6 +3566,9 @@ static void ffs_func_unbind(struct usb_configuration *c,
ffs->func = NULL;
}

/* Drain any pending AIO completions */
drain_workqueue(ffs->io_completion_wq);

if (!--opts->refcnt)
functionfs_unbind(ffs);

Expand Down

0 comments on commit 5cead89

Please sign in to comment.