ioxide: N_GSM 0 day
A race condition in the N_GSM tty line discipline allows two concurrent ioctl calls to allocate and register the same DLCI slot, leaving one object unreferenced. When the mux is torn down, the unreferenced object is freed while a timer still points to it, leading to a use-after-free that could be exploited for kernel code execution.
github.com
Published on github.com
NGSM is a tty line discipline. We can autoload this in Ubuntu, because the dev.tty.ldiscautoload sysctl is enabled, the ngsm module isn't blacklisted -- it should be! -- and in kernels prior to 6.6 any user can open the ngsm discipline without privileges[1].
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a missing lock around the check-and-allocate of a DLCI slot in gsmld_ioctl, allowing two threads to both see the slot as empty and allocate separate objects, with only one stored in the array.
What the attacker needed
Local user access; kernel before 6.6 or without backported patch; dev.tty.ldisc_autoload enabled; n_gsm module not blacklisted
How it was found
- Open a tty and set the N_GSM line discipline via the TIOCSETD ioctl.
- Race two threads calling the GSMIOC_SETCONF_DLCI ioctl to allocate the same DLCI slot.
- Close the tty or change the line discipline to trigger gsm_cleanup_mux, which frees the referenced DLCI but leaves the other object's timer armed.
- Wait for the timer to fire, causing a use-after-free in gsm_dlci_t1.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
The kernel has a driver for a serial protocol called GSM. Two threads can ask it to set up the same channel at the same time, and both succeed, but only one is remembered. When the connection is closed, the forgotten one is freed, yet a timer still tries to use it later, which is a use-after-free. An attacker with local access could turn this into running their own code in the kernel.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.