From: Greg KH <gregkh@linuxfoundation.org>
To: Zhu Jun <zhujun2@cmss.chinamobile.com>
Cc: jirislaby@kernel.org, linux-serial@vger.kernel.org,
linux-kernel@vger.kernel.org,
syzbot+3a7eb6d437d568d1c34d@syzkaller.appspotmail.com
Subject: Re: [PATCH] tty: n_tty: Protect poll input checks against termios changes
Date: Thu, 3 Dec 2026 23:35:02 +0100 [thread overview]
Message-ID: <2026120334-dweeb-jokingly-478d@gregkh> (raw)
In-Reply-To: <20261111084116.80897-1-zhujun2@cmss.chinamobile.com>
On Wed, Nov 11, 2026 at 04:41:16PM +0800, Zhu Jun wrote:
> n_tty_poll() calls input_available_p() without holding termios_rwsem.
> It can therefore race with n_tty_set_termios() changing the canonical
> mode and resetting the buffer indices. In particular, the availability
> check can combine one input mode with indices from the other mode.
>
> Take the read side of termios_rwsem for each poll input check, as the
> read path already does. Release it before flushing the receive worker,
> since that worker also needs termios_rwsem.
>
> Fixes: 1da177e4c3f41 ("Linux-2.6.12-rc2")
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
> ---
> drivers/tty/n_tty.c | 12 +++++++++---
> 1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
> index e6a0f5b40d0a..115bc4a67e8a 100644
> --- a/drivers/tty/n_tty.c
> +++ b/drivers/tty/n_tty.c
> @@ -2416,6 +2416,12 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
> return (b - buf) ? b - buf : retval;
> }
>
> +static bool n_tty_poll_input(struct tty_struct *tty)
> +{
> + guard(rwsem_read)(&tty->termios_rwsem);
> + return input_available_p(tty, 1);
> +}
> +
> /**
> * n_tty_poll - poll method for N_TTY
> * @tty: terminal device
> @@ -2437,11 +2443,11 @@ static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file,
>
> poll_wait(file, &tty->read_wait, wait);
> poll_wait(file, &tty->write_wait, wait);
> - if (input_available_p(tty, 1))
> + if (n_tty_poll_input(tty)) {
> mask |= EPOLLIN | EPOLLRDNORM;
> - else {
> + } else {
> tty_buffer_flush_work(tty->port);
> - if (input_available_p(tty, 1))
> + if (n_tty_poll_input(tty))
This change doesn't actually fix this properly. Be more careful next
time please and try to write a test to verify that your change will
actually work.
thanks,
greg k-h
prev parent reply other threads:[~2026-12-04 3:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 8:41 [PATCH] tty: n_tty: Protect poll input checks against termios changes Zhu Jun
2026-11-11 8:49 ` sashiko-bot
2026-12-03 22:35 ` Greg KH [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=2026120334-dweeb-jokingly-478d@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=syzbot+3a7eb6d437d568d1c34d@syzkaller.appspotmail.com \
--cc=zhujun2@cmss.chinamobile.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