From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796356434; b=w6LWi8akMSGNCvG2ExJ3f4kRpP5KckLBHpF6EKpj3+unJXhxCGdj07Ug7S61OKEx9oou gt1E6B8caGmmiZoncgQ2dRh1676nU4IdLac8BtPcn/s4VFboT52e04NFYF4mCyUBiBJhw EGV/FLxj/8o++yp9qZeFiHCNHrZ6m/GcguDmzKJQQpu9QqS1GHwAea7TdLx9M+fAmWHSx ZXIKdQTUtxwYG+6CYWUm8nRNR7H5bTFJW9znsCZ7hUiPzyIWh8s6RG0D6QXMZcNzGOlCy UIe8fsc1Yt2Rqv9MT/vJA8K5GpD5zSQu+rJqoLuM5RrcpE0n+gwTc5nXagRAlHipzCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796356434; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=SrBf4qS0xrGeDjI6sVKpq4oKppPhYQag1hZW+QxzaH0=; b=P/UvgSMdSUE/xKg26FyojreowrKTNvzwiOIxiQwxEIcSHf3eSzC7imxtYy984UWeOzEw fRSmi3OoFt4VGooyMQOmuXbqouvVIvCb7kA8i1nNsbhq1+8OUCjSl5CP0O3JU6p0li2fY XMhIvn5lWe+xAJmAC7xVm+kyBcTvAev+aSCoyqigXLA1vqRC+FfjsZLUwNZqpeKxjytPw eQ9gOkBGHWU2gXn3SwB//itMCEnXhuAjMmxP3vq79bIupDVSIoENNhPvDco7Io4Vfeoel AeYbnrH9xpfo/SbDRa9n5xemphb0UPgAEd0XDaFl9rHlKwcZiQYieQO4l92K4AoQ0aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wmPyRpGP; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF51B606A322; Fri, 4 Dec 2026 03:53:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wmPyRpGP Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFE041F000C2; Fri, 4 Dec 2026 03:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796356433; bh=SrBf4qS0xrGeDjI6sVKpq4oKppPhYQag1hZW+QxzaH0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=wmPyRpGPSyiRk8AbUc0blF3xdtdanltTwPtSi6yBf8c5TWNekZtv4pfHTOW/BDKdq 3zUGnjpuqwbZ/0josEVPtl0pEXBoXYnuaWsTvh3qKnZ6nOev4m7llRKJhBFa2dJL3i 93r+a4xPk0TrSaS554gwwSs6F4yhSdGYbrG5dkW0= Date: Thu, 3 Dec 2026 23:35:02 +0100 From: Greg KH To: Zhu Jun 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 Message-ID: <2026120334-dweeb-jokingly-478d@gregkh> References: <20261111084116.80897-1-zhujun2@cmss.chinamobile.com> X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > --- > 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