tty: reset ldisc to N_TTY on reopen after hangup
Subsystems (3)
PATCH 1/1 tty: reset ldisc to N_TTY on reopen after hangup
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.
--- drivers/tty/tty_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/tty_io.c +1 -1
@@ -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); }
Signature · 1 line
2.56.1
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 14 lines
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 toopen()but that still leaves a small window where an ldisc could call into the TTY driver before the device has been opened.
Quoted 7 lines
For hotpluggable devices,
open()can also race with disconnect,[ ... ]Fixes 638b9648ab51 ("tty: Fix the ldisc hangup race")Reported-by William A. Kennington III <[email protected]>Signed-off-by Johan Hovold <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1