* [PATCH v2] tty: do not drop hangups during reopen
@ 2026-11-30 16:12 YuanZhe Liu
2026-11-30 16:27 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: YuanZhe Liu @ 2026-11-30 16:12 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Peter Hurley, Johan Hovold, linux-kernel, linux-serial, stable,
Bin Yu, Cheng Wen
TTY_HUPPED is only cleared after ->open() has returned. A tty that is
reopened while still being referenced by another process therefore
remains marked as hung up for the duration of the new open, including
while a blocking open sleeps in tty_port_block_til_ready().
__tty_hangup() ignores hangup requests while TTY_HUPPED is set, so a
hangup (e.g. from USB disconnect) that races with such an open is
dropped: the line discipline and the new file reference are not hung up,
and the port remains initialised while the driver tears down its port
data. The blocked open then calls into the driver with the port data
already gone.
Clear TTY_HUPPED when reopening the tty, while holding the tty lock, so
that a hangup racing with the open is not ignored and the line
discipline and file references are hung up in one go.
This was found while analysing a NULL-pointer dereference in
pl2303_dtr_rts() on USB disconnect. Only compile-tested on x86_64.
Fixes: d4855e1fc03c ("tty: Reset hupped state on open")
Cc: stable@vger.kernel.org
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
Changes in v2:
- Clear TTY_HUPPED in tty_reopen() instead of forcing a port hangup from
tty_port_tty_vhangup(). The latter left the reopening file reference
and line discipline un-hung-up and could desynchronise port->count for
console ports.
Link: https://lore.kernel.org/r/20261130141413.10581-1-25031212351@stu.xidian.edu.cn
drivers/tty/tty_io.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 150052f6d9db..c5bd7f965532 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1327,8 +1327,16 @@ static int tty_reopen(struct tty_struct *tty)
tty_ldisc_unlock(tty);
}
- if (retval == 0)
+ if (retval == 0) {
tty->count++;
+ /*
+ * The tty is being reopened and TTY_HUPPED is only cleared
+ * after the driver's open() has returned. Clear it here so
+ * that a hangup racing with a (blocking) open is not dropped
+ * by __tty_hangup().
+ */
+ clear_bit(TTY_HUPPED, &tty->flags);
+ }
return retval;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] tty: do not drop hangups during reopen
2026-11-30 16:12 [PATCH v2] tty: do not drop hangups during reopen YuanZhe Liu
@ 2026-11-30 16:27 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 16:27 UTC (permalink / raw)
To: YuanZhe Liu; +Cc: linux-serial
> TTY_HUPPED is only cleared after ->open() has returned. A tty that is
> reopened while still being referenced by another process therefore
> remains marked as hung up for the duration of the new open, including
> while a blocking open sleeps in tty_port_block_til_ready().
>
> __tty_hangup() ignores hangup requests while TTY_HUPPED is set, so a
> hangup (e.g. from USB disconnect) that races with such an open is
> dropped: the line discipline and the new file reference are not hung up,
> and the port remains initialised while the driver tears down its port
> data. The blocked open then calls into the driver with the port data
> already gone.
>
> Clear TTY_HUPPED when reopening the tty, while holding the tty lock, so
> that a hangup racing with the open is not ignored and the line
> discipline and file references are hung up in one go.
>
> This was found while analysing a NULL-pointer dereference in
> pl2303_dtr_rts() on USB disconnect. Only compile-tested on x86_64.
>
> Fixes: d4855e1fc03c ("tty: Reset hupped state on open")
> Cc: stable@vger.kernel.org
> Co-developed-by: Bin Yu <byu@xidian.edu.cn>
> Signed-off-by: Bin Yu <byu@xidian.edu.cn>
> Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
> Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130161204.5003-1-25031212351@stu.xidian.edu.cn?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 16:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 16:12 [PATCH v2] tty: do not drop hangups during reopen YuanZhe Liu
2026-11-30 16:27 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox