From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Linyu Yuan <quic_linyyuan@quicinc.com>
Cc: Felipe Balbi <balbi@kernel.org>,
linux-usb@vger.kernel.org, stable@vger.kernel.org,
Jack Pham <quic_jackp@quicinc.com>,
Michael Wu <michael@allwinnertech.com>,
John Keeping <john@metanate.com>
Subject: Re: [PATCH v4 1/2] usb: gadget: f_fs: change ep->status safe in ffs_epfile_io()
Date: Fri, 10 Jun 2022 11:14:34 +0200 [thread overview]
Message-ID: <YqMLeipEA4eEUD/3@kroah.com> (raw)
In-Reply-To: <1654311295-9700-2-git-send-email-quic_linyyuan@quicinc.com>
On Sat, Jun 04, 2022 at 10:54:54AM +0800, Linyu Yuan wrote:
> If a task read/write data in blocking mode, it will wait the completion
> in ffs_epfile_io(), if function unbind occurs, ffs_func_unbind() will
> kfree ffs ep, once the task wake up, it still dereference the ffs ep to
> obtain the request status.
>
> Fix it by moving the request status to io_data which is stack-safe.
>
> 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>
> ---
> v2: correct interrupted assignment
> v3: add Reviewed-by and Reported-by
> v4: add Tetsed-by from Michael Wu,
> remove one empty line
> cc stable kernel
>
> drivers/usb/gadget/function/f_fs.c | 31 ++++++++++++++++---------------
> 1 file changed, 16 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 4585ee3..3958c60 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -122,8 +122,6 @@ struct ffs_ep {
> struct usb_endpoint_descriptor *descs[3];
>
> u8 num;
> -
> - int status; /* P: epfile->mutex */
> };
>
> struct ffs_epfile {
> @@ -227,6 +225,9 @@ struct ffs_io_data {
> bool use_sg;
>
> struct ffs_data *ffs;
> +
> + int status;
> + struct completion done;
> };
>
> struct ffs_desc_helper {
> @@ -707,12 +708,12 @@ static const struct file_operations ffs_ep0_operations = {
>
> static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
> {
> + struct ffs_io_data *io_data = req->context;
> +
> ENTER();
> - if (req->context) {
> - struct ffs_ep *ep = _ep->driver_data;
> - ep->status = req->status ? req->status : req->actual;
> - complete(req->context);
> - }
> +
> + io_data->status = req->status ? req->status : req->actual;
Please do not use ? : lines unless you have to. Please write this as
normal if () lines.
thanks,
greg k-h
next prev parent reply other threads:[~2022-06-10 9:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-04 2:54 [PATCH v4 0/2] usb: f_fs: safe operation in ffs_epfile_io() Linyu Yuan
2022-06-04 2:54 ` [PATCH v4 1/2] usb: gadget: f_fs: change ep->status safe " Linyu Yuan
2022-06-10 9:14 ` Greg Kroah-Hartman [this message]
2022-06-04 2:54 ` [PATCH v4 2/2] usb: gadget: f_fs: change ep->ep " Linyu Yuan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YqMLeipEA4eEUD/3@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=balbi@kernel.org \
--cc=john@metanate.com \
--cc=linux-usb@vger.kernel.org \
--cc=michael@allwinnertech.com \
--cc=quic_jackp@quicinc.com \
--cc=quic_linyyuan@quicinc.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox