Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp822660ybh; Wed, 15 Jul 2020 16:45:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgjMCsWwozGT9TsscoOUXnrj20HKXrTcm811E/ZYU+e2roBsqTlZ+vs8yXc8ncjVhCx76U X-Received: by 2002:aa7:c887:: with SMTP id p7mr2030787eds.240.1594856745200; Wed, 15 Jul 2020 16:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594856745; cv=none; d=google.com; s=arc-20160816; b=m247dIMrCLXjwCO6M02PwD+1adlN//iQ4Fa6sbh7GI3Hm+MBq8k+phsTRH/VbVrCI1 KOL2bb5ROEtEQaiqjf31cRZGKdnKaOsMTcK1j6dSStHs9yMUADXtsqdgfYTKTIwil57Q JOrSU66xUIOipjXdvUvOXvfgplSS2GIO3m1PzIdpy555zOOpcMMUJwSLmmUiXTfOh0Rn St3bMfkoqUsAMwr69mGfwZ2aZpiCI8Hp9S8QI11HjdA3kQDLYOjj4hEc1A7TLpq2UvKa GwbtIR23a2gQHWo0iuncoR7CaRTeu7s1HRHhgxn3atopmoLRi2zdVu0hfwlyLyLC4cQ7 dW7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=QanDndzhHn7ltvGhvwtJeUPWEZ+FzfcRAfI65bW0ZUQ=; b=M9RcPDkZLyYHU/N28W09QEG2uECiEI+a+zSvX6gxeuIFGLjev74GSm+s1oOGw6eh7l EyUoWekga915ev32ujX4b8KTBXzmR1WpbkzEUROIF8WAcowrc9Tn70GeAwvQV/E2VgkO YLqfPszQYpbtR3I83HOP7eJ6kJUzn8HiaCc2nrLW25xoiaOidaTKbVLvxvx79Fa84CS/ IdzIGymZOJVbSYMxTBnROMRhlwrVVhMFCbzMxCXQCyxrCBbS1B319qfeqIMeh6yZ3Rgi 74jAMxWgYY37m7NomtgkCXR/dD+mw3A4VMGdax+8BXCNS1xyXuClV+nU6mCxCKMeh4Na 9qlQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p16si2129533ejj.708.2020.07.15.16.45.20; Wed, 15 Jul 2020 16:45:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727826AbgGOXmK (ORCPT + 99 others); Wed, 15 Jul 2020 19:42:10 -0400 Received: from mail109.syd.optusnet.com.au ([211.29.132.80]:35404 "EHLO mail109.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbgGOXmJ (ORCPT ); Wed, 15 Jul 2020 19:42:09 -0400 Received: from dread.disaster.area (pa49-180-53-24.pa.nsw.optusnet.com.au [49.180.53.24]) by mail109.syd.optusnet.com.au (Postfix) with ESMTPS id 30842D7C575; Thu, 16 Jul 2020 09:42:04 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1jvr2J-0001Fq-DD; Thu, 16 Jul 2020 09:42:03 +1000 Date: Thu, 16 Jul 2020 09:42:03 +1000 From: Dave Chinner To: Eric Biggers Cc: Marco Elver , syzbot , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, syzkaller-bugs@googlegroups.com, "Paul E. McKenney" , Will Deacon Subject: Re: KCSAN: data-race in generic_file_buffered_read / generic_file_buffered_read Message-ID: <20200715234203.GK5369@dread.disaster.area> References: <0000000000004a4d6505aa7c688a@google.com> <20200715152912.GA2209203@elver.google.com> <20200715163256.GB1167@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200715163256.GB1167@sol.localdomain> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=W5xGqiek c=1 sm=1 tr=0 a=moVtWZxmCkf3aAMJKIb/8g==:117 a=moVtWZxmCkf3aAMJKIb/8g==:17 a=kj9zAlcOel0A:10 a=_RQrkK6FrEwA:10 a=VwQbUJbxAAAA:8 a=edf1wS77AAAA:8 a=eU0e3LhYAAAA:20 a=hSkVLCK3AAAA:8 a=7-415B0cAAAA:8 a=ZUY0gg6SJnirf6z4UTcA:9 a=CjuIK1q_8ugA:10 a=AjGcO6oz07-iQ99wixmX:22 a=DcSpbTIhAlouE1Uv7lRv:22 a=cQPPKAXgyycSBL8etih5:22 a=biEYGPWJfzWAr4FL6Ov7:22 a=pHzHmUro8NiASowvMSCR:22 a=nt3jZW36AmriUCFCBwmW:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 15, 2020 at 09:32:56AM -0700, Eric Biggers wrote: > [+Cc linux-fsdevel] > > On Wed, Jul 15, 2020 at 05:29:12PM +0200, 'Marco Elver' via syzkaller-bugs wrote: > > On Wed, Jul 15, 2020 at 08:16AM -0700, syzbot wrote: > > > Hello, > > > > > > syzbot found the following issue on: > > > > > > HEAD commit: e9919e11 Merge branch 'for-linus' of git://git.kernel.org/.. > > > git tree: upstream > > > console output: https://syzkaller.appspot.com/x/log.txt?x=1217a83b100000 > > > kernel config: https://syzkaller.appspot.com/x/.config?x=570eb530a65cd98e > > > dashboard link: https://syzkaller.appspot.com/bug?extid=0f1e470df6a4316e0a11 > > > compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project.git ca2dcbd030eadbf0aa9b660efe864ff08af6e18b) > > > > > > Unfortunately, I don't have any reproducer for this issue yet. > > > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > > Reported-by: syzbot+0f1e470df6a4316e0a11@syzkaller.appspotmail.com > > > > > > ================================================================== > > > BUG: KCSAN: data-race in generic_file_buffered_read / generic_file_buffered_read > > > > Our guess is that this is either misuse of an API from userspace, or a > > bug. Can someone clarify? > > > > Below are the snippets of code around these accesses. > > Concurrent reads on the same file descriptor are allowed. Not with sys_read(), > as that implicitly uses the file position. But it's allowed with sys_pread(), > and also with sys_sendfile() which is the case syzbot is reporting here. Concurrent read()s are fine, they'll just read from the same offset. > > > > > > write to 0xffff8880968747b0 of 8 bytes by task 6336 on cpu 0: > > > generic_file_buffered_read+0x18be/0x19e0 mm/filemap.c:2246 > > > > ... > > would_block: > > error = -EAGAIN; > > out: > > ra->prev_pos = prev_index; > > ra->prev_pos <<= PAGE_SHIFT; > > 2246) ra->prev_pos |= prev_offset; > > > > *ppos = ((loff_t)index << PAGE_SHIFT) + offset; > > file_accessed(filp); > > return written ? written : error; > > } > > EXPORT_SYMBOL_GPL(generic_file_buffered_read); > > ... > > Well, it's a data race. Each open file descriptor has just one readahead state > (struct file_ra_state), and concurrent reads of the same file descriptor > use/change that readahead state without any locking. > > Presumably this has traditionally been considered okay, since readahead is > "only" for performance and doesn't affect correctness. And for performance > reasons, we want to avoid locking during file reads. > > So we may just need to annotate all access to file_ra_state with > READ_ONCE() and WRITE_ONCE()... Please, no. Can we stop making the code hard to read, more difficult to maintain and preventing the compiler from optimising it by doing stupid "turn off naive static checker warnings" stuff like this? If the code is fine with races, then -leave it alone-. If it's not fine with a data race, then please go and work out the correct ordering and place well documented barriers and/or release/acquire ordering semantics in the code so that we do not need to hide data races behind a compiler optimisation defeating macro.... Yes, I know data_race() exists to tell the tooling that it should ignore data races in the expression, but that makes just as much mess of the code as READ_ONCE/WRITE_ONCE being spewed everywhere indiscriminately because . Cheers, Dave. -- Dave Chinner david@fromorbit.com