From: Johan Hovold <johan@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: linux-serial@vger.kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>,
"William A. Kennington III" <william@wkennington.com>,
stable@vger.kernel.org
Subject: [PATCH] tty: reset ldisc to N_TTY on reopen after hangup
Date: Fri, 20 Nov 2026 12:24:55 +0100 [thread overview]
Message-ID: <20261120112455.1353962-1-johan@kernel.org> (raw)
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
next reply other threads:[~2026-11-20 11:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 11:24 Johan Hovold [this message]
2026-11-20 11:33 ` [PATCH] tty: reset ldisc to N_TTY on reopen after hangup sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120112455.1353962-1-johan@kernel.org \
--to=johan@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=william@wkennington.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox