From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9793B3EDAC0 for ; Thu, 26 Feb 2026 15:16:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772119017; cv=none; b=VrYEXCfod/UQxLTuNq4lh8ntfM+J+Ky4Z5quEGZ9hGa9PeCeJzGpYKI5c2x+rtRt/wjkl+sLosZefw/illNw83EHHgt3YmDbL8biK88If9ZCIQKaeaz5t/Mqqw1fxEk2hY6KA9Bwzd5SJNYon3TIJ7AO3hZKwNOMWwCEJXem5D0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772119017; c=relaxed/simple; bh=31s2WJyuIuyZZS39CvKxsQBTXRhjei2RcsCwi+NC6g0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=H6LnFkYtxoTk+LHN211pXCQ+t2j95xt3nn8wv7pb+cyZAzZeCTxQR/yw/WG2ce1U2txgRNVvyyOGCgboNofjqA3j0cifIq0J/yaapaKarX7OttHUzLVKi70bwSrOQyrtSHf6UHthgvtgmJN+B9EkHzj1TuiSWAoQvy4nFUeJvHc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Wj1jzceO; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wj1jzceO" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48371bb515eso13489655e9.1 for ; Thu, 26 Feb 2026 07:16:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772119014; x=1772723814; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x+9nNRTMs9TtVhYWkHqh6WpqdW+Y7K36DSB96fNVI8Q=; b=Wj1jzceOQnBcvuq3HBPXc4pkAD6wDfd9ubyXSy38hq6N9eA5GhitBTZYzsWZAO9crD eHulHl5nytsvClP3e/tsSjNvl7TBlvBfnPTb90Qz+GoI22hrFLe28Cs0bZCF6dGrZUp7 Gu+eC3XBZ6nIq+M8JFEH4NZgDbBNLr2oOUSsHBVRGIynpsryI9ClCvtOC0KY/8Gc/Ar3 ElU/IWIDxTmcO96wtBIJJSeK2paLCFX9rIUsGwrx/X/aud1t8Kwp49P9XxnZu5GRLwV4 bgoJucC1V8y/HBhzmPcSKkBDzOQCDjO0Cb7veoX1QziCaRIecMIo6kqjphAIAY24iE6H TN6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772119014; x=1772723814; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x+9nNRTMs9TtVhYWkHqh6WpqdW+Y7K36DSB96fNVI8Q=; b=JUahV1TiZcpCp7EsAnCruggV/3qF0ntPQBdUTgoSM2cy0Aj6vx7ASFB04vwtGvMZU8 EpoKsOGjuPiht2a5/bASd7JakTemaacd5GXf1RA6eo0KoDvX45D+XK915lRsWb2/UXwG ngqTAb/Wz287+PfjmdppKRZF0rnwrpsHdLnyIYzMOJRG+QIBRfPjguMwWUU4WsjRgHsF DXqdR1yHPsJUcakrpmDGwHuwn13kKX2aAOWEB5OirzFT+2/rBSrBPwEA8vxpCqn1rmBa kPA6bC4H1kbc69bAKDHcARnlovmg1hbTGuojwKVFRcs1XjcSMJnm+boBvIqqRKXfQGvy 0Pag== X-Forwarded-Encrypted: i=1; AJvYcCU5ughA8EmRXLgBlPkyKbNw1b/2ZbKQ7J6WI4E+lLCghGyd0GVeMTwYs72eagojN4PDV7tH5oesbdfx6Nk=@vger.kernel.org X-Gm-Message-State: AOJu0YzcNtWv69lOwaC/bl7XF1BXMk7eWJ+ytFpe7AE9DPotwaqWcPCA KBsp0UHk/PZIfxWa2WFnM+Byq3k4NyAyEq0esem82U0oYMbyQnij+FT5 X-Gm-Gg: ATEYQzyTxePo1TfAxVwNN7G2M1ULa/yY6V05a69p9xIXf+VXZYulnqEK3us5wgHk+Fy I9d8SduoLykg4zPoO4AIwhcH837ku/ABj6Zm9eb7ILxqkGLAFfW5x4CU215EplwtrdO9M9eYrM+ 8DBa8DnqkNyZd4DVdbyEVOwQFgPdpJrfJbr5CtGhE8+d/pm6v30//ogGjyyAkPufgGwN5sKyrv0 DO8zDwieGpey30WHTY9s72yRuyaXUC7v7YPo+ljK2KvnUEb9f4897TtP+H5wnstqc6fz4j7P+jO /ArMKKOPPtbS5wq8Q3VufBZPiO+UdevA2XmlU8jlmrY7/1WDefJWgUmzRFeCJgZS9OP/7sE1+Pl Zc1n/93VpivuY/iVRKAKvkna8J4RGGb++vPO1gJp9Z1ofOIqdfj1new4PEAdHjm4EAt8XojmL2S 2v6zLvQMe+e5oDxp2Zav78oM7UmvHA0MnCh6SP1x/FJP9htctR79OUHL1U X-Received: by 2002:a05:600c:638d:b0:477:b642:9dc1 with SMTP id 5b1f17b1804b1-483c3dd71eamr33988995e9.20.1772119013595; Thu, 26 Feb 2026 07:16:53 -0800 (PST) Received: from osama ([41.232.219.174]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483c3b84023sm50654235e9.12.2026.02.26.07.16.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Feb 2026 07:16:53 -0800 (PST) Date: Thu, 26 Feb 2026 16:16:49 +0100 From: Osama Abdelkader To: Greg Kroah-Hartman , Jiri Slaby , Andy Shevchenko , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org Cc: syzbot+80806cf7508e92c7cc86@syzkaller.appspotmail.com Subject: Re: [PATCH] tty: n_tty: fix KCSAN data-race in n_tty_flush_buffer / n_tty_lookahead_flow_ctrl Message-ID: References: <20260211210838.45127-1-osama.abdelkader@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260211210838.45127-1-osama.abdelkader@gmail.com> On Wed, Feb 11, 2026 at 10:08:38PM +0100, Osama Abdelkader wrote: > n_tty_lookahead_flow_ctrl() accesses ldata->lookahead_count without > holding termios_rwsem, while reset_buffer_flags() in n_tty_flush_buffer() > resets it with exclusive termios_rwsem held. This causes a data race > reported by KCSAN when a PTY is closed while flush_to_ldisc is still > processing lookahead data. > > Fix by taking termios_rwsem (read) in n_tty_lookahead_flow_ctrl(), > consistent with __receive_buf() which also modifies lookahead_count > under the read lock. > > Reported-by: syzbot+80806cf7508e92c7cc86@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=80806cf7508e92c7cc86 > Fixes: 6bb6fa6908eb ("tty: Implement lookahead to process XON/XOFF timely") > Signed-off-by: Osama Abdelkader > --- > drivers/tty/n_tty.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c > index e6a0f5b40d0a..725d6ed2b863 100644 > --- a/drivers/tty/n_tty.c > +++ b/drivers/tty/n_tty.c > @@ -1480,6 +1480,8 @@ static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const u8 *cp, > struct n_tty_data *ldata = tty->disc_data; > u8 flag = TTY_NORMAL; > > + guard(rwsem_read)(&tty->termios_rwsem); > + > ldata->lookahead_count += count; > > if (!I_IXON(tty)) > -- > 2.43.0 > ping