mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tty: reset ldisc to N_TTY on reopen after hangup
@ 2026-11-20 11:24 Johan Hovold
  0 siblings, 0 replies; only message in thread
From: Johan Hovold @ 2026-11-20 11:24 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-usb, linux-kernel, Johan Hovold,
	William A. Kennington III, stable

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@wkennington.com>
Link: https://lore.kernel.org/20261118145636.3534234-1-william@wkennington.com
Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 11:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 11:24 [PATCH] tty: reset ldisc to N_TTY on reopen after hangup Johan Hovold

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®