Re: [PATCH v8 3/4] usb: gadget: gadgetfs: prevent ep0 event counter underflow
From: Alan Stern
Date: Wed Nov 25 2026 - 22:32:56 EST
On Tue, Nov 10, 2026 at 12:13:24PM +0800, Jing Lin via B4 Relay wrote:
> From: Jing Lin <kayano050408@xxxxxxxxx>
>
> ep0_read() snapshots dev->ev_next, drops dev->lock while copy_to_user()
> runs directly from dev->event[], and subtracts the snapshot afterwards.
> A concurrent disconnect, connect, setup, or another reader can reset,
> deduplicate, or consume the queue in that window. This races on
> dev->event[], can drop newly arrived GADGETFS_SETUP events, and wraps
> dev->ev_next if the queue shrinks below the snapshot.
>
> Dequeue the events into the local buffer and update dev->ev_next before
> dropping dev->lock for copy_to_user().
>
> Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jing Lin <kayano050408@xxxxxxxxx>
> ---
This and the 4/4 patch look good. They may need a little adjustment
after you update the first two patches, though.
Alan Stern