From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 F36B633067F for ; Fri, 6 Mar 2026 07:52:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772783527; cv=none; b=DKC5VMOfQyQoKH38OjcRuqZ3X9wVL1mq9+y34Xx9Ef6Vpn3LD1/uUddRLFSRGa+J2cNTuStiDLbFwWRyj0b4l0l39MOg57KA0Fxqq3BJT6kgJtvRfEX9X3s8wDptL5N36OZvXNsGoy2iHcrCoRuezuGhAASX9vwuWH1DCKLT+YU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772783527; c=relaxed/simple; bh=1DSf/40QIi0281oAVrfAMFHgyT4F0i/JEwAu+RloXTs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jq4yrqkK0CjOcuQIAZJiHfi75mdiFE7pxtCkLdcaoAJntVsMk8e6mUuv2eW5JmaD0MdEJDg4oAqpTw4i1rcvE868HvoDy5xohJjeL8dQTo/s3MA0cQuu4uAT8cn+8vNCw0+SEA+W778MM3AZYtGbMCXhXl4bRwavLxwFq5PJyQs= 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=B/v9F3ot; arc=none smtp.client-ip=209.85.128.50 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="B/v9F3ot" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4837907f535so81061825e9.3 for ; Thu, 05 Mar 2026 23:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772783524; x=1773388324; 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=IeT+0mSKswHLx4Rvh/oZxQm5lIPM5axHkAAQqdyqiJM=; b=B/v9F3otvopqFfiKWeT5uRYv9nIeT72iv8i+l+r1uR74sXhg80+1Ske5fL51tpNpN7 j/SXjn21bgBHsxqslJG4QDx3GU7wmTeNv1ZjqufkN1JLj6JJPqkwH36Si7KvsDueMQni lNV6dtM9Z01QimxSE8U36WVT4oooelB58OkrPigvtnc6WF4bNJrARrBLr4poMMmWhP/4 1Oa9miIUut2isL6Lpb8lPXDC5DKyKK6eoUg48yFq7XGxkqxsLZemr8CtI66AlwdGJyoA lnNg9FnlkPyHHATYFczyZRSYLGLvCAxbnOJos+jmnzu/Z8MxAiaOvzPHDU4x7P775KPZ CjCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772783524; x=1773388324; 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=IeT+0mSKswHLx4Rvh/oZxQm5lIPM5axHkAAQqdyqiJM=; b=w+s+BO/iRKO/IjgwEQCDNXLfluDesqXfmKuqiwy2PLWWzM0aHrw5T4BF84rH/GrFw/ sPTC8zbQRNAr0GktVLkOoVa+YEW73H+lJhMPxcqvsNW5qo1OGNdcncBEbjzt3d2Ea9Eh 7HJA7iIlE9IaBdqiAcWFsuG1yh8KnRpmKIjnfZ6ktQhEn/cq+GgU+9NKDy97E+hV4UYU iQQGABdCfmMLF0om5B3aQO4qIEGOq/dHZw9n0MwlHA8EtJQBK+AE5cZZCDpGFhnabq11 JDWYyELgQdeuiNlWDHDm3nZDgYuk3fxysfprkyRHzS1Borw9be44+ZlcvnGkr/RWy8M8 XP9A== X-Forwarded-Encrypted: i=1; AJvYcCWC8mBkNjN8shfsViAfqkOQX5lD6E8ZdPZ04idyl2oKa59lxQW4EkEE2wTBelPRJB8FmQLx8053D66DcmE=@vger.kernel.org X-Gm-Message-State: AOJu0YzQng9xEv99LeLtYFHFPZTtpdBQasZQMizi/xQxlQHi5Yi/DpwQ vY4nx1MQ0RYSJzxCi+ib/c1HCWhlluYU/wgZnOm+vtMXwvCGI4zFj+e0 X-Gm-Gg: ATEYQzxi774Eb3lw5x9EmnkVqgK94ZVcsXFn8v3+GVGs2ZeRcVndXsXRg13Er+4gWEN A+pRgv29ozo4+70wbG6ggMMbvApjptPh9k1SMIMx5k0QT05cIuaTF7019JX2u/fWiGdeiCnZ5g8 jjRPFoddiZqu/nSwSEpByzHyMK2HqKNQ6YYuhQtAIk20k0rPbwHKELYPT/fBpPfnEznYgy9UiI+ 9pveAWTvOt55euhn4yOtgpFkAXq95w1yWA2doVUpOp2cIz+EDlxklNBztYnorsR2aHUxZja4rpE UYZ+VxrOboh8dXYDoolzfU4g6e3nZfIKe4LnZRLoKOs9BNWecscPEb5o0D/Yo7OvPPLsQLsLyPz XdedlpAoHpasytz/YUXYcoAt1CzvUaT0N1k1AM5N8CMoK6jxHBep97lVVLMuQen0NVmZXGekiXw DD/3LAYfHRDYX96tlC1LIlezCy9OY3TePVIBpcJHLeSyUQp6GjZIdlidDEJw== X-Received: by 2002:a05:600c:3488:b0:47a:81b7:9a20 with SMTP id 5b1f17b1804b1-48526923bc7mr16119525e9.9.1772783524062; Thu, 05 Mar 2026 23:52:04 -0800 (PST) Received: from osama ([2c0f:fc89:104:8900:7a1a:21b3:e0a6:ba62]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-485246ed174sm17072405e9.5.2026.03.05.23.52.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 23:52:03 -0800 (PST) Date: Fri, 6 Mar 2026 08:51:59 +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 > Hi All, Can you please review? Thanks for your time in advance. BR, Osama