CVE-2026-142984: usb: gadget: u_serial: pin ports while TTYs are installed
In the Linux kernel, the following vulnerability has been resolved:
usb: gadget: userial: pin ports while TTYs are installed
A slab-use-after-free can occur when gserialfreeline() frees struct gsport while it is still reachable through an installed TTY. The port->port.count value tracks successful opens, but it is zero before gsopen() and again after gsclose(), before TTY cleanup has finished. Teardown can therefore free gsport while ttyinitdev() or releasetty() still accesses its ttyport.
Manage gsport lifetime with ttyport references. Take a reference in gsinstall(), drop it in gscleanup(), and move the final free to gsportdestruct(). Unregister the TTY device before dropping the owner reference.
Keep each minor reserved until the old port is destroyed so an installed TTY for one generation cannot overlap a replacement at the same minor. Publish the new port before device registration so the cdev and add uevent never expose a TTY before gsinstall() can pin it. Since commit 8df07fe93573 ("tty: fix saved termios reset race"), userial registration no longer frees saved termios. On registration failure, unpublish the port before dropping its owner reference.
Check in gsopen() that the installed port is still the published generation. Track failures after a successful install so close callbacks issued by the TTY core do not decrement port->port.count for opens that never incremented it.
Affected Software
Event History
Frequently Asked Questions
Which systems are exposed to this issue?
Systems using the Linux USB gadget serial (u_serial) functionality are exposed when a gadget serial port can be freed while its TTY remains installed. The vulnerable lifetime window exists during port teardown and TTY initialization or cleanup.
What sequence triggers the use-after-free?
The port's open count can be zero before gs_open() or after gs_close() even though tty_init_dev() or release_tty() still accesses the associated tty_port. If gserial_free_line() frees the gs_port during that interval, those TTY operations can access freed memory.
What does the fix change to prevent recurrence?
The fix pins gs_port with tty_port references while a TTY is installed and performs final freeing in gs_port_destruct(). It also reserves each minor until the old port is destroyed and unregisters the TTY device before dropping the owner's reference.