Linux USB
 help / color / mirror / Atom feed
* [PATCH v10 0/6] usb: gadget: gadgetfs: fix ep0 request lifetime and control races
@ 2026-11-26 12:44 Jing Lin via B4 Relay
  2026-11-26 12:44 ` [PATCH v10 1/6] usb: gadget: gadgetfs: fix ep0 request lifetime on unbind Jing Lin via B4 Relay
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Jing Lin via B4 Relay @ 2026-11-26 12:44 UTC (permalink / raw)
  To: Neill Kapron, Greg Kroah-Hartman
  Cc: Alan Stern, linux-usb, linux-kernel, syzbot+c73e1942197af9f54ca3,
	stable, Jing Lin

This series fixes the ep0 request lifetime on unbind, control buffer and
setup_abort state races, lost completed control-OUT transfers, event
counter underflow, and the const cast in gadgetfs_setup().

1/6 tracks active ep0 requests and waits for completion after
    usb_ep_dequeue() in gadgetfs_unbind() before freeing dev->req, while
    keeping descriptor buffers out of kfree().
2/6 copies delegated control-IN payloads into a private memdup_user()
    buffer before touching dev->req and drops responses superseded
    during the unlocked copy.
3/6 fixes setup_abort tracking across ep0_poll(), gadgetfs_disconnect(),
    ep0_read() event waits, and early returns or in-kernel requests in
    gadgetfs_setup().
4/6 preserves completed control-OUT payloads until ep0_read() collects
    them, leaving ep0 unqueued so the controller NAKs newly arriving
    control transfers in the meantime and replaying the deferred setup
    afterwards.
5/6 dequeues ep0 events before dropping dev->lock for copy_to_user() to
    prevent dev->ev_next underflow.
6/6 removes the const cast on ctrl->wLength in gadgetfs_setup().

The setup() callback runs in atomic context and may not sleep, so a
mutex cannot serialize it against ep0_read() and ep0_write(); shared ep0
state remains protected by dev->lock.

---
Changes in v10:
- Re-check setup_abort and dev->state in ep0_read() after waking from
  the event wait before jumping to scan: (3/6).
- Track the active control-OUT request with dev->setup_out_generation so
  ep0_complete() ignores requests superseded before completion, and
  check setup_generation in the ep0_read() control-OUT wait path (4/6).
- Recheck dev->state and dev->setup_generation after queue_ep0_req()
  re-acquires dev->lock in gadgetfs_do_setup(), increment
  setup_generation on disconnect and unbind, and verify generation and
  state before calling usb_ep_set_halt() in ep0_process_pending_setup()
  (4/6).
- Link to v9: https://patch.msgid.link/20261126-gadgetfs-ep0-v9-0-81b464c6e641@gmail.com

To: Neill Kapron <nkapron@google.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: linux-usb@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: syzbot+c73e1942197af9f54ca3@syzkaller.appspotmail.com
Cc: stable@vger.kernel.org
Signed-off-by: Jing Lin <kayano050408@gmail.com>

---
Jing Lin (6):
      usb: gadget: gadgetfs: fix ep0 request lifetime on unbind
      usb: gadget: gadgetfs: isolate ep0_write() buffer and reduce setup race
      usb: gadget: gadgetfs: fix ep0 setup_abort tracking and reporting
      usb: gadget: gadgetfs: NAK new setups until control-OUT data is read
      usb: gadget: gadgetfs: prevent ep0 event counter underflow
      usb: gadget: gadgetfs: avoid writing through the const setup pointer

 drivers/usb/gadget/legacy/inode.c | 551 +++++++++++++++++++++++++++-----------
 1 file changed, 399 insertions(+), 152 deletions(-)
---
base-commit: 90d6263e867be7089b3d3323bef8d2accd327c77
change-id: 20261126-gadgetfs-ep0-fc2255305a75

Best regards,
--  
Jing Lin <kayano050408@gmail.com>



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-26 13:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 12:44 [PATCH v10 0/6] usb: gadget: gadgetfs: fix ep0 request lifetime and control races Jing Lin via B4 Relay
2026-11-26 12:44 ` [PATCH v10 1/6] usb: gadget: gadgetfs: fix ep0 request lifetime on unbind Jing Lin via B4 Relay
2026-11-26 12:44 ` [PATCH v10 2/6] usb: gadget: gadgetfs: isolate ep0_write() buffer and reduce setup race Jing Lin via B4 Relay
2026-11-26 12:44 ` [PATCH v10 3/6] usb: gadget: gadgetfs: fix ep0 setup_abort tracking and reporting Jing Lin via B4 Relay
2026-11-26 12:44 ` [PATCH v10 4/6] usb: gadget: gadgetfs: NAK new setups until control-OUT data is read Jing Lin via B4 Relay
2026-11-26 12:44 ` [PATCH v10 5/6] usb: gadget: gadgetfs: prevent ep0 event counter underflow Jing Lin via B4 Relay
2026-11-26 12:44 ` [PATCH v10 6/6] usb: gadget: gadgetfs: avoid writing through the const setup pointer Jing Lin via B4 Relay
2026-11-26 13:07 ` [PATCH v10 0/6] usb: gadget: gadgetfs: fix ep0 request lifetime and control races sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox