Re: [PATCH] tty: n_tty: read termios under lock in poll

From: Greg KH

Date: Sun May 10 2026 - 12:24:24 EST


On Sun, May 10, 2026 at 10:59:40AM +0800, Cen Zhang wrote:
> n_tty_poll() uses input_available_p() to decide whether buffered input
> makes the tty readable. That helper reads termios state through
> L_EXTPROC(), VMIN, and VTIME, but the poll path does not hold the read
> side of tty->termios_rwsem.
>
> tty_set_termios() updates tty->termios under the write side of the same
> semaphore, including c_lflag and c_cc[]. n_tty_read() already takes the
> read side before reading the same termios fields and before calling
> input_available_p(). Protect the poll-side readiness checks the same way
> so poll observes a coherent termios state when deciding whether to report
> readable input.

But why does that matter? If it changes right after you grab/release
the lock, the data will be stale as well. What userspace logic is
broken because of there not being a lock held here?

thanks,

greg k-h