Technical Analysis of the Root Cause
1. Vulnerability Mechanism and Files Involved
The bug is located in drivers/usb/serial/upd78f0730.c in the implementation of the dtr_rts USB serial driver callback:
- File:
drivers/usb/serial/upd78f0730.c
- Functions:
upd78f0730_dtr_rts() (lines 268–280) and upd78f0730_tiocmset() (lines 204–239)
- Structs/Fields:
struct usb_serial_port::port (struct tty_port::tty) and struct tty_struct::driver_data (at byte offset 0x620 / 1568 bytes).
In upd78f0730.c:
static int upd78f0730_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear)
{
struct usb_serial_port *port = tty->driver_data;
...
}
static void upd78f0730_dtr_rts(struct usb_serial_port *port, int on)
{
struct tty_struct *tty = port->port.tty;
unsigned int set = 0;
unsigned int clear = 0;
if (on)
set = TIOCM_DTR | TIOCM_RTS;
else
clear = TIOCM_DTR | TIOCM_RTS;
upd78f0730_tiocmset(tty, set, clear);
}
The dtr_rts callback of struct usb_serial_driver takes struct usb_serial_port *port directly (void (*dtr_rts)(struct usb_serial_port *port, int on)). In upd78f0730_dtr_rts(), the function attempts to retrieve port->port.tty solely to forward it to upd78f0730_tiocmset(tty, ...). Inside upd78f0730_tiocmset(), tty is only used to unpack tty->driver_data back into struct usb_serial_port *port.
2. Triggering Sequence and Lifecycle Invariant Violation
When a USB serial port is opened and subsequently disconnected, or when an open tty port is hung up:
usb_serial_disconnect() invokes tty_port_tty_vhangup(&port->port).
tty_port_tty_vhangup() initiates a synchronous hangup (tty_vhangup() -> __tty_hangup()).
__tty_hangup() invokes the driver's hangup callback (serial_hangup() in drivers/usb/serial/usb-serial.c), which calls tty_port_hangup(&port->port).
- In
tty_port_hangup() (drivers/tty/tty_port.c:395–406):
scoped_guard(mutex, &port->mutex) {
scoped_guard(spinlock_irqsave, &port->lock) {
port->count = 0;
tty = port->tty;
if (tty)
set_bit(TTY_IO_ERROR, &tty->flags);
port->tty = NULL; /* <--- port->tty explicitly set to NULL */
}
tty_port_set_active(port, false);
tty_port_shutdown_locked(port, tty);
}
port->tty is cleared to NULL.
tty_port_shutdown_locked() receives the saved local pointer tty. If the terminal flags have C_HUPCL(tty) set (hangup on close/drop lines), tty_port_shutdown_locked() calls:
if (tty && C_HUPCL(tty))
tty_port_lower_dtr_rts(port);
tty_port_lower_dtr_rts(port) invokes port->ops->dtr_rts(port, false) -> serial_port_dtr_rts() -> upd78f0730_dtr_rts(port, 0).
upd78f0730_dtr_rts() reads port->port.tty, which is now NULL.
upd78f0730_dtr_rts() calls upd78f0730_tiocmset(NULL, 0, TIOCM_DTR | TIOCM_RTS).
upd78f0730_tiocmset() attempts to access tty->driver_data at offset 0x620 from NULL (0x0000000000000620). In KASAN-instrumented kernels, the shadow memory check for 0x620 (0xdffffc0000000000 + (0x620 >> 3) == 0xdffffc00000000c4) fails, generating the reported GPF null-ptr-deref.
3. Resolution
upd78f0730.c should not rely on port->port.tty. Instead, like other USB serial drivers (e.g. xr_serial.c, cp210x.c), modem control line updates should be factored into a helper function operating directly on struct usb_serial_port *port (e.g. upd78f0730_tiocmset_port(port, set, clear)). Both upd78f0730_tiocmset() and upd78f0730_dtr_rts() should call this helper, allowing upd78f0730_dtr_rts() to update DTR/RTS without ever referencing tty_struct.