mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Minseo Kim <neck3922@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzkaller@googlegroups.com
Subject: Re: [BUG] usb: gadgetfs: KASAN null-ptr-deref and intermittent UAF in ep_aio_cancel()
Date: Thu, 17 Sep 2026 11:38:49 -0400	[thread overview]
Message-ID: <9c07ce98-a5bf-4bcc-9304-e7f5e1747842@rowland.harvard.edu> (raw)
In-Reply-To: <CAFmvuTU9xfCWFaoXzE6J0uC6y6eCZ43CRg+JWkLV3dgLNYu5Cw@mail.gmail.com>

On Thu, Sep 17, 2026 at 11:02:13PM +0900, Minseo Kim wrote:
> Hi Alan,
> 
> Thank you for the patch.
> 
> > Can you repeat these tests with the patch below applied on top
> > of the other two?  It should cause usb_gadget_unregister_driver() to
> > wait until ep_aio_complete() returns (the actual wait loop is in
> > dummy-hcd's dummy_udc_async_callbacks() routine).
> 
> Yes. With the new dummy_hcd change applied on top of the two GadgetFS
> patches, usb_gadget_unregister_driver() waited in
> dummy_udc_async_callbacks() until the held ep_aio_complete() callback
> returned in both the normal transfer path through dummy_giveback() and
> the direct giveback path in dummy_queue().
> 
> I used upstream v7.2-rc1 as the base. Because dummy_giveback() is not
> present in v7.2-rc1, both matched test trees also included the changes
> from upstream commit d5e5cd3654d2b5359a12ea6586120f05b28634ee
> ("usb: gadget: dummy_hcd: prevent fifo_req reuse during giveback").

Okay.  I recently rebased my kernel tree to v7.3-rc3, so a few 
discrepancies are to be expected.

> In the normal transfer case, I held ep_aio_complete() immediately after
> iocb->ki_complete(). Without the new dummy_hcd change,
> dummy_udc_async_callbacks(false) saw callback_usage equal to 0, and the
> ep0 close returned while the callback was still held. With the change,
> it saw callback_usage equal to 1, and the ep0 close task remained blocked
> in dummy_udc_async_callbacks(). The relevant part of the blocked close
> task's stack was:
> 
>     dummy_udc_async_callbacks [dummy_hcd]
>     gadget_unbind_driver
>     device_remove
>     device_release_driver_internal
>     driver_detach
>     bus_remove_driver
>     driver_unregister
>     usb_gadget_unregister_driver
>     dev_release [gadgetfs]

That is just as it should be.

dummy-hcd emulates a UDC driver.  With a real driver, givebacks would be 
triggered by a device interrupt (signalling completion of a request) and 
the synchronize_irq() call in gadget_unbind_driver() would wait until 
outstanding calls to the IRQ handler (and thus the completion handler) 
had completed.  But dummy-hcd doesn't have real hardware, so instead of 
device interrupts it relies on timer interrupts and its 
dummy_ucd_async_callbacks() routine is supposed to emulate 
synchronize_irq().  Thus it should wait until all outstanding completion 
handler calls have completed.

> After I released the callback gate, ep_aio_complete() returned,
> callback_usage fell to 0, and the same close completed. I observed this
> sequence in four separate runs with the new change.
> 
> To exercise the other accounting site, I separately tested the direct
> giveback path for a 64-byte write in dummy_queue(). With the change, the
> close task again waited in dummy_udc_async_callbacks() with callback_usage
> equal to 1. In the matched control, dummy_udc_async_callbacks() returned
> with callback_usage at 0, and gadgetfs_unbind() then remained in its
> existing udc_usage wait until I released the callback gate.

I wonder which part of the code was holding udc_usage above 0?

> I also repeated the case where the request was still on the endpoint
> queue when usb_ep_disable() began. Neither usb_ep_disable() nor the ep0
> close returned while the completion callback was held. After I released
> the callback gate, io_getevents() returned one completion with
> res=-ESHUTDOWN, and a subsequent check returned no additional completion
> event.

It all sounds good.  I will submit the patches, with your Signed-off-by: 
added to this one also, if that's okay with you.

Alan Stern

  reply	other threads:[~2026-09-17 15:38 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 23:08 김민서
2026-07-01  2:13 ` Alan Stern
2026-07-02  8:08   ` 김민서
2026-07-02 14:22     ` Alan Stern
2026-07-06  1:18       ` 김민서
2026-07-07 17:31         ` Alan Stern
2026-07-13 18:47           ` Minseo Kim
2026-07-14  3:23             ` Alan Stern
2026-07-19 20:59               ` Minseo Kim
2026-07-21  2:18                 ` Alan Stern
2026-07-29 15:31                   ` Alan Stern
2026-07-30 15:55                     ` Minseo Kim
2026-07-31 18:59                       ` Alan Stern
2026-08-02  6:08                         ` Minseo Kim
2026-08-02 16:07                           ` Alan Stern
2026-08-04 23:12                             ` Minseo Kim
2026-08-05 16:17                               ` Alan Stern
2026-08-09 22:19                                 ` Andrey Konovalov
2026-08-14 16:17                                 ` Alan Stern
2026-08-17 19:49                                   ` Minseo Kim
2026-08-18  2:57                                     ` Alan Stern
2026-08-20  9:40                                       ` Minseo Kim
2026-08-20 14:08                                         ` Alan Stern
2026-08-22 20:26                                           ` Minseo Kim
2026-08-23  1:10                                             ` Alan Stern
2026-08-28 20:30                                               ` neck3922
2026-08-29 16:08                                                 ` Alan Stern
2026-08-31 13:30                                                   ` Minseo Kim
2026-09-01  2:47                                                     ` Alan Stern
2026-09-04 14:00                                                       ` Minseo Kim
2026-09-04 20:09                                                         ` Alan Stern
2026-09-07 13:00                                                           ` Minseo Kim
2026-09-08 19:02                                                             ` Alan Stern
2026-09-10 14:00                                                               ` Minseo Kim
2026-09-10 15:50                                                                 ` Alan Stern
2026-09-11 14:00                                                                   ` Minseo Kim
2026-09-11 19:22                                                                     ` Alan Stern
2026-09-14 14:00                                                                       ` Minseo Kim
2026-09-14 16:00                                                                         ` Alan Stern
2026-09-16 14:00                                                                           ` Minseo Kim
2026-09-16 19:39                                                                             ` Alan Stern
2026-09-17 14:02                                                                               ` Minseo Kim
2026-09-17 15:38                                                                                 ` Alan Stern [this message]
2026-09-18 13:30                                                                                   ` Minseo Kim
2026-09-18 14:17                                                                                     ` Alan Stern

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=9c07ce98-a5bf-4bcc-9304-e7f5e1747842@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=andreyknvl@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=neck3922@gmail.com \
    --cc=syzkaller@googlegroups.com \
    /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

all inboxes | Powered by JetHome®