[PATCH] tty: reset ldisc to N_TTY on reopen after hangup
From: Johan Hovold
Date: Fri Nov 20 2026 - 06:26:48 EST
Line disciplines should not call into a TTY driver for a device that has
been hung up as the underlying hardware may have been powered down or
resources may have been freed.
Since commit 638b9648ab51 ("tty: Fix the ldisc hangup race") the line
discipline is however reinitialised on hangup which means that ldiscs
that register class devices on initialisation (e.g. N_SLIP) can call
back into a TTY driver after hangup.
Commit 892d1fa7eaae ("tty: Destroy ldisc instance on hangup") later
moved reinitialisation to open() but that still leaves a small window
where an ldisc could call into the TTY driver before the device has been
opened.
For hotpluggable devices, open() can also race with disconnect,
reinitialise the ldisc and leave a class device registered indefinitely
after the underlying device and its resources are gone.
Fix this by restoring the pre-2004 behaviour of always resetting the
ldisc to N_TTY when a tty is reopened after hangup.
Note that console ldiscs are still reinitialised on hangup but consoles
are special in that they are not shut down on hangup.
Also note the line disciplines currently affected by this require
CAP_NET_ADMIN.
Fixes: 638b9648ab51 ("tty: Fix the ldisc hangup race")
Reported-by: William A. Kennington III <william@xxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/20261118145636.3534234-1-william@xxxxxxxxxxxxxxx
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/tty/tty_io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 1a6c8a1bc764..363572f10456 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1323,7 +1323,7 @@ static int tty_reopen(struct tty_struct *tty)
return retval;
if (!tty->ldisc)
- retval = tty_ldisc_reinit(tty, tty->termios.c_line);
+ retval = tty_ldisc_reinit(tty, N_TTY);
tty_ldisc_unlock(tty);
}
--
2.56.1