[PATCH 2/3] tty: n_hdlc: fix read() hangup race
From: Johan Hovold
Date: Wed Oct 28 2026 - 09:25:05 EST
Make sure to set the task state before checking the break conditions in
the read() wait loop to avoid missing a racing wakeup.
Note that before commit c96cf923a98d ("tty: Don't block on IO when ldisc
change is pending") a racing task hanging up the tty could get stuck in
uninterruptible sleep when there are blocked readers, but since then
read() incorrectly returns -EAGAIN instead.
The false-positive stuck hangup issue was flagged by an LLM.
Fixes: 1035b63d3c6f ("n_hdlc: fix read and write locking")
Cc: stable@xxxxxxxxxxxxxxx # 2.6.38
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
---
drivers/tty/n_hdlc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 0fbc44968a44..02676ae9b112 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -431,6 +431,8 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
add_wait_queue(&tty->read_wait, &wait);
for (;;) {
+ set_current_state(TASK_INTERRUPTIBLE);
+
if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
ret = -EIO;
break;
@@ -438,8 +440,6 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
if (tty_hung_up_p(file))
break;
- set_current_state(TASK_INTERRUPTIBLE);
-
rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
if (rbuf)
break;
--
2.55.0