Re: [PATCH v2] usb: gadget: u_serial: fix use-after-free between tty open/close and gserial_free_line

From: Syed Tayyab Farooq

Date: Mon Nov 23 2026 - 07:53:48 EST


Hi,

I have gone through the concerns. Both points look valid, but I believe both are
pre-existing and independent of the lifetime bug this patch fixes, so I
would prefer to handle them in follow-ups to keep this fix minimal.

> If a concurrent USB disconnect triggers gserial_disconnect() while the
> lock is dropped [in gs_open()], it will see port->port.count == 0 and
> call kfifo_free().

Agreed, this race exists today. gs_open() drops port_lock around
kfifo_alloc(), and ports[].lock only serializes openers against each
other, so gserial_disconnect() can free a kfifo that is half-allocated.
>From my reading of __kfifo_alloc()/__kfifo_free() the likely result is a
NULL data pointer with a non-zero mask (NULL dereference on a later
write) or a leaked buffer, rather than a write into freed memory, but
either way it is a real bug. This patch does not touch that code path.
A possible fix is to free the kfifo from the port destructor instead of
gserial_disconnect(), or to allocate into a local kfifo and install it
under port_lock. I can send that separately.

> Could this wait_event() block the caller (configfs rmdir)
> indefinitely if a userspace process keeps the TTY device open?

Yes, that behaviour is pre-existing. The wait was what kept the port
from being freed while a tty was open. With the port now refcounted via
tty_port_get()/tty_port_put(), I agree the wait is likely redundant.
Removing it changes rmdir semantics (rmdir would succeed while a tty is
still open), so I would rather do that as a separate patch where that
change can be reviewed on its own.

Please let me know if you would prefer either of these folded into this
patch instead.

Best Regards,
Tayyab

On Fri, Nov 20, 2026 at 6:55 PM Greg Kroah-Hartman
<gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, Oct 20, 2026 at 05:41:33PM +0500, Syed Tayyab Farooq wrote:
> > Hi,
> >
> > syzbot has tested this against the reported issue, and the test passed
> > successfully.
>
> Yes, but the reviews for it are not ok:
> https://sashiko.dev/#/patchset/20260910105359.12915-1-syedtayyabfarooq08@xxxxxxxxx
>