Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp490218pxb; Wed, 18 Aug 2021 07:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAi/8VdfO6hvXTNejwBB+Zq5Rei10pwuYlb1eG8QZSNpUyxFnaiHdZIGKA8WIVqqPFotej X-Received: by 2002:a5d:85cf:: with SMTP id e15mr7192555ios.208.1629295527876; Wed, 18 Aug 2021 07:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629295527; cv=none; d=google.com; s=arc-20160816; b=eF/HUOhEsj15TJXQGTNUFdBo9C5XdMA3zKBLWgkXOjomYEo0WrHmo5DZQLnthTpANE KAkFEOnhBjbRYFDGm0Zw3P95jg7Y2IRO2tZ/07FDYPpbeFgooh/kABYPQNh8MTRu6Ume kOePtXTziJyV3QvPTCIhfsmRziEhKX8qzNw+eMSAnEC3PcOOFkKfcIFWEPW3PzDPE8C+ 42yk2zL1GKX43cfDgdutC1c5O3cYzl6yAJpb4rBrxb1WzQusjvTZyLmVhsmMEWlqwT9c vEpymxelx0Eq6LNBzIBVtgPQbEw8uQ2OWqhO9ISEcGPF7MJLBOLAJAr37qVuNkcwb4oB ct8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ELrRF0S1vj0llFJDLYYfWcM0SKj3srnmim9vejEj9GQ=; b=HL7NLY9R4NMYeIlu2ez3XPlZKkO6AzvqT6yl+FSF8omrOzUBExoGoXIWlWSikM4qLU 1V/cYyOGA5iYP6tVtryVBvoB67WGAWsFoZ7JVscudCxLpZOjSXBQgBRnWZeMLnwy5AmX a44GCv9bJw1U/fCt8P+8V22tA8Xh+AIgVjOzv2zNX0/SL2kNJMbcDsTS4qhA+DNJ5lQ8 UspjQqSkC+i4qEia4XIy7nULjv2+Vqw9n4UGuegApRA1BLGV7DxuBeqRICprN6wnIAY0 rB+QWqwLplBgONNUk4DyFbPS+YlqDhrnhXNNX8WBz0+NlZvEH+U3Fn1m1RBosmMH/RSj Becw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rx5TKLHC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u10si7982529jat.85.2021.08.18.07.05.15; Wed, 18 Aug 2021 07:05:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Rx5TKLHC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238761AbhHROEd (ORCPT + 99 others); Wed, 18 Aug 2021 10:04:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:51418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238668AbhHROE0 (ORCPT ); Wed, 18 Aug 2021 10:04:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3590B61051; Wed, 18 Aug 2021 14:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1629295431; bh=OtHThCXmHDiPy0w6lt1fEL2vmZQbCKRBjm4W84idpsI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Rx5TKLHCisM/jt55skOkrCVNfntYjFdCbIbtDzpTNmpkAOX3ImgebHL812XZe9ulp H3rzMUDDOc7Hn90T6JvADqe0HfCHjXI1gELcST56HOlqVKFtco9drONZmebFDHtXrC LLoRvnCDGEj6p6Z8VRpRN06sCWJhksk9xWclybp8= Date: Wed, 18 Aug 2021 16:03:49 +0200 From: Greg KH To: Phi Nguyen Cc: jirislaby@kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, syzbot+97388eb9d31b997fe1d0@syzkaller.appspotmail.com Subject: Re: [PATCH] tty: Fix data race between tiocsti() and flush_to_ldisc() Message-ID: References: <20210807190513.3810821-1-phind.uet@gmail.com> <7323d825-f596-223b-a063-7539a6a57107@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7323d825-f596-223b-a063-7539a6a57107@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 14, 2021 at 02:35:53AM +0800, Phi Nguyen wrote: > On 8/13/2021 3:33 PM, Greg KH wrote: > > > > > > Signed-off-by: Nguyen Dinh Phi > > > Reported-by: syzbot+97388eb9d31b997fe1d0@syzkaller.appspotmail.com > > > --- > > > drivers/tty/tty_io.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c > > > index e8532006e960..746fe13a2054 100644 > > > --- a/drivers/tty/tty_io.c > > > +++ b/drivers/tty/tty_io.c > > > @@ -2307,8 +2307,10 @@ static int tiocsti(struct tty_struct *tty, char __user *p) > > > ld = tty_ldisc_ref_wait(tty); > > > if (!ld) > > > return -EIO; > > > + tty_buffer_lock_exclusive(tty->port); > > > if (ld->ops->receive_buf) > > > ld->ops->receive_buf(tty, &ch, &mbz, 1); > > > + tty_buffer_unlock_exclusive(tty->port); > > > > Did this fix the syzbot reported issue? > > > > thanks, > > > > greg k-h > > Yes, this fixed the syzbot reported issue. > > The lock is grabbed in flush_to_ldisc() and paste_selection(). > Actually, I follow the document in tty_buffer.c, where it say the callers to > receive_buff() other than flush_to_ldisc() need to exclude the kworker from > concurrent use of the line discipline. > > And function tiocsti() has the following comment: > /* FIXME: may race normal receive processing */ > that why I add lock in this function. As you are fixing this FIXME, please remove it in this patch, otherwise we will not know it is resolved :) Can you add that to the change and submit a new version? Also, this should go to stable kernels, right? Any idea how far back? thanks, greg k-h