mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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-kernel@vger.kernel.org,
	Johan Hovold <johan@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH 3/3] tty: n_hdlc: fix read() hangup check
Date: Wed, 28 Oct 2026 14:20:49 +0100	[thread overview]
Message-ID: <20261028132049.728457-4-johan@kernel.org> (raw)
In-Reply-To: <20261028132049.728457-1-johan@kernel.org>

When a tty is hung up, the file ops are generally set to
hung_up_tty_fops, but this is not the case for, for example,
/dev/console.

Make sure to check the TTY_HUPPING flag so that a hangup is detected and
read() returns zero also with /dev/console (as is done for n_tty [1]).

Note that before commit c96cf923a98d ("tty: Don't block on IO when ldisc
change is pending") a task hanging up the tty would 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.

[1] 28b0f8a6962a ("tty: make n_tty_read() always abort if hangup is in progress")

Fixes: 1035b63d3c6f ("n_hdlc: fix read and write locking")
Cc: stable@vger.kernel.org	# 2.6.38
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/tty/n_hdlc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 02676ae9b112..1a3a276f2db3 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -437,7 +437,8 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
 			ret = -EIO;
 			break;
 		}
-		if (tty_hung_up_p(file))
+
+		if (tty_hung_up_p(file) || test_bit(TTY_HUPPING, &tty->flags))
 			break;
 
 		rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list);
-- 
2.55.0


      parent reply	other threads:[~2026-10-28 13:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 13:20 [PATCH 0/3] tty: n_hdlc: fix hangup handling Johan Hovold
2026-10-28 13:20 ` [PATCH 1/3] tty: n_hdlc: fix missing write() hangup check Johan Hovold
2026-10-28 13:20 ` [PATCH 2/3] tty: n_hdlc: fix read() hangup race Johan Hovold
2026-10-28 13:20 ` Johan Hovold [this message]

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=20261028132049.728457-4-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=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®