Linux USB
 help / color / mirror / Atom feed
From: Frode Isaksen <fisaksen@baylibre.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, Thinh.Nguyen@synopsys.com,
	Frode Isaksen <frode@meta.com>,
	stable@vger.kernel.org, jassibrar@meta.com
Subject: Re: [PATCH v2] usb: gadget: f_fs: Invalidate io_data when USB request is dequeued or interrupted
Date: Fri, 11 Apr 2025 15:32:37 +0200	[thread overview]
Message-ID: <dab8e91a-a751-4307-ad21-31d3539963da@baylibre.com> (raw)
In-Reply-To: <2025041139-sedan-liquid-de35@gregkh>

On 4/11/25 3:08 PM, Greg KH wrote:
> On Mon, Mar 31, 2025 at 10:53:50AM +0200, Frode Isaksen wrote:
>> From: Frode Isaksen <frode@meta.com>
>>
>> Invalidate io_data by setting context to NULL when USB request is
>> dequeued or interrupted, and check for NULL io_data in epfile_io_complete().
>> The invalidation of io_data in req->context is done when exiting
>> epfile_io(), since then io_data will become invalid as it is allocated
>> on the stack.
>> The epfile_io_complete() may be called after ffs_epfile_io() returns
>> in case the wait_for_completion_interruptible() is interrupted.
>> This fixes a use-after-free error with the following call stack:
>>
>> Unable to handle kernel paging request at virtual address ffffffc02f7bbcc0
>> pc : ffs_epfile_io_complete+0x30/0x48
>> lr : usb_gadget_giveback_request+0x30/0xf8
>> Call trace:
>> ffs_epfile_io_complete+0x30/0x48
>> usb_gadget_giveback_request+0x30/0xf8
>> dwc3_remove_requests+0x264/0x2e8
>> dwc3_gadget_pullup+0x1d0/0x250
>> kretprobe_trampoline+0x0/0xc4
>> usb_gadget_remove_driver+0x40/0xf4
>> usb_gadget_unregister_driver+0xdc/0x178
>> unregister_gadget_item+0x40/0x6c
>> ffs_closed+0xd4/0x10c
>> ffs_data_clear+0x2c/0xf0
>> ffs_data_closed+0x178/0x1ec
>> ffs_ep0_release+0x24/0x38
>> __fput+0xe8/0x27c
>>
>> Signed-off-by: Frode Isaksen <frode@meta.com>
>> Cc: stable@vger.kernel.org
>> ---
>> v1 -> v2:
>> Removed WARN_ON() in ffs_epfile_io_complete().
>> Clarified commit message.
>> Added stable Cc tag.
>>
>>   drivers/usb/gadget/function/f_fs.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
>> index 2dea9e42a0f8..e35d32e7be58 100644
>> --- a/drivers/usb/gadget/function/f_fs.c
>> +++ b/drivers/usb/gadget/function/f_fs.c
>> @@ -738,6 +738,9 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
>>   {
>>   	struct ffs_io_data *io_data = req->context;
>>   
>> +	if (io_data == NULL)
>> +		return;
> What prevents req->context to be set to NULL right after you check this?
>
> thanks,
>
> greg k-h

Nothing really, but the race is really much shorter. We will try to redo 
this code, but that will take some time.

Thanks,

Frode



      reply	other threads:[~2025-04-11 13:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-31  8:53 [PATCH v2] usb: gadget: f_fs: Invalidate io_data when USB request is dequeued or interrupted Frode Isaksen
2025-04-11 13:08 ` Greg KH
2025-04-11 13:32   ` Frode Isaksen [this message]

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=dab8e91a-a751-4307-ad21-31d3539963da@baylibre.com \
    --to=fisaksen@baylibre.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=frode@meta.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jassibrar@meta.com \
    --cc=linux-usb@vger.kernel.org \
    --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