Re: [PATCH v3] tty: ldisc: fix deadlock between ldisc_sem and rtnl_mutex
Greg KH <[email protected]> Thu, 30 Jul 2026 16:50:42 +0200
| Newsgroups | org.kernel.vger.linux-can,org.kernel.vger.linux-kernel,org.kernel.vger.linux-serial,org.kernel.vger.netdev |
|---|---|
| Message-ID | <2026073027-nervy-imposing-0068@gregkh> |
On Fri, Jul 24, 2026 at 04:46:48PM +0800, Yun Zhou wrote: > syzbot reported a circular lock dependency involving tty ldisc_sem and > the networking rtnl_mutex. The full chain is: > > rtnl_mutex --> nft_commit_mutex --> ... --> ep->mtx --> ldisc_sem --> rtnl_mutex > > The last edge (ldisc_sem -> rtnl_mutex) is created because tty line > discipline .open() callbacks (slcan, slip) call register_netdev() which > acquires rtnl_mutex, and .open() runs under ldisc_sem write lock in > tty_set_ldisc(). > > Fix by moving the .open() call outside the ldisc_sem write lock. The > ldisc .open() is initialization of the NEW discipline after the old one > has been closed - there is no need for ldisc_sem protection at this > point since: > > - tty_lock is held throughout, preventing concurrent tty_set_ldisc, > hangup, or close > - tty->ldisc is set to NULL during the window. tty_ldisc_ref_wait() > waits for the transition to complete. tty_ldisc_ref() returns NULL > which callers already handle. > - tty buffer data stays queued until the ldisc is installed > > The sequence becomes: > 1. Hold ldisc_sem(write): close old ldisc, set tty->ldisc = NULL > 2. Release ldisc_sem(write) > 3. Call new_ldisc->ops->open() without ldisc_sem > 4. Re-acquire ldisc_sem(write): install new ldisc (or restore old) > 5. Release ldisc_sem(write) > > Reported-by: [email protected] > Closes: https://syzkaller.appspot.com/bug?extid=de610eeef174bd59a8a3 > Signed-off-by: Yun Zhou <[email protected]> > --- Sashiko has some comments: https://sashiko.dev/#/patchset/[email protected] are they correct? thanks, greg k-h