From: sashiko-bot@kernel.org
To: "Varun Singh" <varun.singh10011@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v3 1/2] usb: gadget: u_serial: serialise line setup against line teardown
Date: Mon, 09 Nov 2026 14:28:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-205101@kernel.org> (raw)
In-Reply-To: <20261109141110.3538-2-varun.singh10011@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: u_serial: missing Fixes trailer for commit
19b10a8828a6
--
commit 7fc863482be78ba089c79dd3a13d5ea59b19a79c
Author: Varun Singh <varun.singh10011@gmail.com>
> usb: gadget: u_serial: serialise line setup against line teardown
>
> Creating a u_serial gadget function can fail with -EEXIST for no reason:
>
> sysfs: cannot create duplicate filename '/devices/virtual/tty/ttyGS0'
> gserial_alloc_line_no_console: failed to register tty for port 0, err -17
>
> ports[n].lock protects the ports[n].port slot, but the line's tty device
> is registered and unregistered outside it, so the two can change
> independently:
>
> gserial_alloc_line_no_console() gserial_free_line()
> gs_port_alloc()
> mutex_lock(ports[n].lock)
> mutex_lock(ports[n].lock)
> ports[n].port = NULL
> mutex_unlock(ports[n].lock)
> ports[n].port = new
> mutex_unlock(ports[n].lock)
> tty_port_register_device(n) <- device for n still there
> tty_unregister_device(n)
>
> The allocator claims a slot whose old device is still registered, which
> is the -EEXIST above. The reverse order leaves a slot with no device
> node.
>
> Hold ports[n].lock across slot assignment and device registration, and
> across slot clearing and unregistration, so a concurrent caller sees
> either both or neither. gs_port_alloc() is now called with the lock
> held. Neither tty_port_register_device() nor tty_unregister_device()
> takes tty_lock or ports[n].lock, and gserial_free_line() already slept
> under this mutex, so this adds no new lock dependency.
>
> With two gadgets racing for line 0, 25 of 383 function creations failed
> on an unpatched kernel; 0 of 530 with this patch.
>
> Found with the assistance of Claude Opus 5.
>
> Signed-off-by: Varun Singh <varun.singh10011@gmail.com>
[Severity: Low]
Should this bug fix include a Fixes: tag for the commit that introduced
dynamic serial line allocation and teardown without holding
ports[port_num].lock across tty device registration and unregistration?
Fixes: 19b10a8828a6 ("usb: gadget: allocate & giveback serial ports instead hard code them")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261109141110.3538-1-varun.singh10011@gmail.com?part=1
next prev parent reply other threads:[~2026-11-09 14:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 14:11 [PATCH v3 0/2] usb: gadget: u_serial: fix gs_port use-after-free on open/unbind race Varun Singh
2026-11-09 14:11 ` [PATCH v3 1/2] usb: gadget: u_serial: serialise line setup against line teardown Varun Singh
2026-11-09 14:28 ` sashiko-bot [this message]
2026-11-09 14:11 ` [PATCH v3 2/2] usb: gadget: u_serial: fix gs_port use-after-free on open/unbind race Varun Singh
2026-11-09 14:33 ` sashiko-bot
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=sashiko-outbox-205101@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=varun.singh10011@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.