Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp187465ybv; Tue, 18 Feb 2020 20:53:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxER2gG3usiEU9EDClvEvhmoAO67LY21dBIthVj8gz/OPrw2uxaLNlmdaf3icPvZJk8LmPP X-Received: by 2002:a05:6830:c7:: with SMTP id x7mr17486918oto.272.1582087980555; Tue, 18 Feb 2020 20:53:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582087980; cv=none; d=google.com; s=arc-20160816; b=gDcmFxjn2e75BmesbHtI0khtCLl2HNBZOykf4d6PD5WEwKyYxUo0qrEYRkhc1sKGHX GxxZ5CLHlV2Eu9B6AvHaUtMXYmij2W+9w/gzL4BnNW+kQnYQ4OKh7XsGwsb6+lyNkKVd WkA71ekQoJMnsrUHEYpY84gByZyUg1WFsn57Xl/po8ZtKkLRdl5CC9BVUWyTvbNGfF5n /ZjNRma65dgdqlU/cjMebA2S0lTKH+K0DZSfr7ltyC/07NgCWU+xPfbS91Y0p8/nzioR z2GpmDJv61k/8wPELuu75KssJb6fvJfxxJOGH/FZTRsd3b6HTWUkmfFhh+plLga9EvLI xZDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=1lUI0L+Gf1MwAiNq257uuFjtFovluR5/sau2NV6hEjo=; b=Or0C8kclQTxju9cZ8VDhDbFTTx43J3X/U96lTV1Kz+3uUaIowSl9RRpasjXu5en6A9 aHRY8jBeFrsWLHianJ616CcY04JTiMWfKxpPntL8rQOGZxHGBfjBuWz+2ArH4CncN4A/ ffWtDQlR/1Ywn8jB09uf7v1XR+4jqK/VQtV557+bjSzWYHKlkIlEX4/UOB/gwg/RQaIG Dg+FJIR6VeEJDWEMQwTwq9O7wd4vj1WBgmbu92fyHpgmFJMox5NdZ2kWKHu+UCVL9HXB UDjkL36Newp2kZ2Ca0dzLsBRSW2hHxey1z0//k+fJGwAsK22atVom9li3Nt0rIKLTDMk C/EA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i124si9148883oif.214.2020.02.18.20.52.47; Tue, 18 Feb 2020 20:53:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726548AbgBSEwi (ORCPT + 99 others); Tue, 18 Feb 2020 23:52:38 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:36514 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726477AbgBSEwi (ORCPT ); Tue, 18 Feb 2020 23:52:38 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j4HLY-00F4Ft-Q9; Wed, 19 Feb 2020 04:52:28 +0000 Date: Wed, 19 Feb 2020 04:52:28 +0000 From: Al Viro To: Qian Cai Cc: hch@infradead.org, darrick.wong@oracle.com, elver@google.com, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] fs: fix a data race in i_size_write/i_size_read Message-ID: <20200219045228.GO23230@ZenIV.linux.org.uk> References: <20200219040426.1140-1-cai@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219040426.1140-1-cai@lca.pw> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 18, 2020 at 11:04:26PM -0500, Qian Cai wrote: > inode::i_size could be accessed concurently as noticed by KCSAN, > > BUG: KCSAN: data-race in iomap_do_writepage / iomap_write_end > > write to 0xffff8bf68fc0cac0 of 8 bytes by task 7484 on cpu 71: > iomap_write_end+0xea/0x530 > i_size_write at include/linux/fs.h:888 > (inlined by) iomap_write_end at fs/iomap/buffered-io.c:782 > iomap_write_actor+0x132/0x200 > iomap_apply+0x245/0x8a5 > iomap_file_buffered_write+0xbd/0xf0 > xfs_file_buffered_aio_write+0x1c2/0x790 [xfs] > xfs_file_write_iter+0x232/0x2d0 [xfs] > new_sync_write+0x29c/0x3b0 > __vfs_write+0x92/0xa0 > vfs_write+0x103/0x260 > ksys_write+0x9d/0x130 > __x64_sys_write+0x4c/0x60 > do_syscall_64+0x91/0xb05 > entry_SYSCALL_64_after_hwframe+0x49/0xbe > > read to 0xffff8bf68fc0cac0 of 8 bytes by task 5901 on cpu 70: > iomap_do_writepage+0xf4/0x450 > i_size_read at include/linux/fs.h:866 > (inlined by) iomap_do_writepage at fs/iomap/buffered-io.c:1558 > write_cache_pages+0x523/0xb20 > iomap_writepages+0x47/0x80 > xfs_vm_writepages+0xc7/0x100 [xfs] > do_writepages+0x5e/0x130 > __writeback_single_inode+0xd5/0xb20 > writeback_sb_inodes+0x429/0x910 > __writeback_inodes_wb+0xc4/0x150 > wb_writeback+0x47b/0x830 > wb_workfn+0x688/0x930 > process_one_work+0x54f/0xb90 > worker_thread+0x80/0x5f0 > kthread+0x1cd/0x1f0 > ret_from_fork+0x27/0x50 > > Reported by Kernel Concurrency Sanitizer on: > CPU: 70 PID: 5901 Comm: kworker/u257:2 Tainted: G L 5.6.0-rc2-next-20200218+ #2 > Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 07/10/2019 > Workqueue: writeback wb_workfn (flush-254:0) > > The write is protected by exclusive inode::i_rwsem (in > xfs_file_buffered_aio_write()) but the read is not. A shattered value > could introduce a logic bug. Fixed it using a pair of WRITE/READ_ONCE(). If aligned 64bit stores on 64bit host (note the BITS_PER_LONG ifdefs) end up being split, the kernel is FUBAR anyway. Details, please - how could that end up happening?