Re: [PATCH] tty: n_tty: hold termios_rwsem in n_tty_lookahead_flow_ctrl()

From: Jiayi Zhang

Date: Sat Dec 05 2026 - 03:26:11 EST


On Fri, Dec 04, 2026, Greg Kroah-Hartman wrote:
> What changed to cause this to be needed now?

Nothing changed. n_tty_lookahead_flow_ctrl() has read the termios and
updated ldata->lookahead_count without termios_rwsem since the
lookahead was added in 6bb6fa6908eb ("tty: Implement lookahead to
process XON/XOFF timely"), in v6.0. syzbot's first reports of the two
races are from August and September 2022. The reports in the Closes:
tags are the 5th and the 10th with these titles. syzbot closed each
earlier one as obsolete after it had not recurred for a while.

> And why the "private" syzbot reports?

Pimyn has explained how the moderation list works. The dashboard
pages show that syzbot's AI triage marked both races as benign, so
neither report was forwarded to the lists. I found them while going
through open syzbot reports on the dashboard.

For the hangup in the second report the benign rating is right:
tty_ldisc_hangup() closes the ldisc after the flush, and n_tty_close()
frees ldata. The other cases need backed-up input, because only then
does the lookahead run, and a concurrent TCIFLUSH or TCSETS. After
TCIFLUSH, a lost reset makes the receive path drop later START/STOP
characters without stopping or starting the tty. A TCSETS that clears
IXON during a lookahead pass can leave the tty stopped. I found these
by reading the code and have not seen them happen.

Sorry, I missed that Osama Abdelkader (Cc'd) sent the same change in
February for an earlier report of the flush race:
https://lore.kernel.org/all/20260211210838.45127-1-osama.abdelkader@xxxxxxxxx/
You replied then that it felt wrong and asked for a lot of testing
and validation. My testing was the syzbot reproducer with KCSAN
(described below the --- of my patch) and the same reproducer for
9 minutes on 5 VMs with lockdep enabled, which reported nothing.

Since Osama's patch came first, please drop mine. If you want the
change, please take his.

Thanks,
Jiayi