From: Varun Singh <varun.singh10011@gmail.com>
To: nkapron@google.com, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
bigeasy@linutronix.de,
syzbot+39a2135de1558208d3b3@syzkaller.appspotmail.com,
Varun Singh <varun.singh10011@gmail.com>
Subject: [PATCH v3 0/2] usb: gadget: u_serial: fix gs_port use-after-free on open/unbind race
Date: Mon, 9 Nov 2026 19:41:08 +0530 [thread overview]
Message-ID: <20261109141110.3538-1-varun.singh10011@gmail.com> (raw)
2/2 fixes the use-after-free reported by syzbot in check_tty_count(). It
is based on v2, with the device unregistration change moved into 1/2.
1/2 is new. While reviewing v2 I noticed that ports[n].lock protected the
ports[n].port slot but not the matching tty device registration, letting
concurrent function creation and removal race so that creation fails with
-EEXIST. That is independent of the reported use-after-free, but 2/2
relies on the slot and the device changing together, so it goes first.
v2 -> v3:
- new 1/2: hold ports[n].lock across slot assignment and device
registration, and across slot clearing and device unregistration
- 2/2: unregister-before-free moved into 1/2; otherwise unchanged
v1 -> v2:
- look the port up in .install and hold a tty_port reference for the
lifetime of the tty, instead of clearing tty->driver_data on close
- drop the close_wait handshake: with a correct port count it blocks
rmdir until userspace closes /dev/ttyGS*, seen as a hung task
- hang up any tty still installed on a freed line, and recheck in
gs_open() that tty->driver_data matches the registered port
Testing, in QEMU against a configfs mkdir/rmdir and open() race
reproducer, A/B against unmodified master each time:
- clean under KASAN and, separately, under lockdep (PROVE_LOCKING,
DEBUG_ATOMIC_SLEEP, DETECT_HUNG_TASK); kmemleak reported no leaks
- slab fault injection exercised 1/2's registration-failure rollback
107 times, after which the line was still allocatable and openable
- 1/2 was built and booted on its own, to check bisectability
- the series passed #syz test on 2026-11-08 against syzbot's own
reproducer, which covers the acm path the local one does not:
"testing succeeded, no crash reproduced"
Not addressed here: gserial_alloc_line() re-reads ports[0].port after the
line's lock has been dropped and passes it to gs_console_init(), which has
no NULL check, so a concurrent gserial_free_line(0) can leave it NULL.
This predates the series. I have left it out rather than pull
register_console() under ports[n].lock without investigating that further,
and can send a separate patch for it.
Link: https://lore.kernel.org/all/20261102193436.6044-1-varun.singh10011@gmail.com/ [v2]
Varun Singh (2):
usb: gadget: u_serial: serialise line setup against line teardown
usb: gadget: u_serial: fix gs_port use-after-free on open/unbind race
drivers/usb/gadget/function/u_serial.c | 132 ++++++++++++++++---------
1 file changed, 85 insertions(+), 47 deletions(-)
--
2.34.1
next reply other threads:[~2026-11-09 14:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 14:11 Varun Singh [this message]
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:11 ` [PATCH v3 2/2] usb: gadget: u_serial: fix gs_port use-after-free on open/unbind race Varun Singh
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=20261109141110.3538-1-varun.singh10011@gmail.com \
--to=varun.singh10011@gmail.com \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=syzbot+39a2135de1558208d3b3@syzkaller.appspotmail.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®