Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2729352imj; Mon, 11 Feb 2019 07:37:25 -0800 (PST) X-Google-Smtp-Source: AHgI3IZxIe8MQMV+DiKYgBrR10+A1PcAFhEqc5yp39Ci96RWbxQ57zOZusUyDOjqpxWNAhFUIdSD X-Received: by 2002:a62:d10b:: with SMTP id z11mr7930686pfg.84.1549899445581; Mon, 11 Feb 2019 07:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899445; cv=none; d=google.com; s=arc-20160816; b=YAu1ugezl0Hgn/PvLU7m1l17giFTSuEMLPTjrQlLjMyb7f2Re5HZMeZ4BbezN93+y3 tzZAldeuPuN9lfKSbDSu7GWE6/neWpGrtvapAK8TbCXAbRy1nqJF916UO7uwUU189Rvx BJbqLXkimZ7cHSApMDWE5UN44qktNfCIHphjjnYNTZSyZdHd8IKVYBIj2jxzfDxm4H5o 0m1ul/Ef1ZFZHLBWOh9c+CDIU9LfTBycmwKVJfRQN6H36q+D3OGBWKEmvAdeOffJ55F1 kkYu+g3AZbJyvD1TQMo1NNy+5NW/5WrQT1J2myUiuvBdsoTYQWfk6aKMrF+yiuySwjvM gttA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=argC5/CRBkwp8Iwya01/TOeub1l1/vZ8dZr6vSYNsZk=; b=PRJPCDSdLGlKuQeyZ9JNMbrXaz9QkZluSm1ekXbX6Yw37/tipxsORZdTQJnraKWiqg j1S9fOnRD6/+4dFTczXaomZJMPxFhe7Xj40aSK4G5SD/bYMKVZbZ0gk1V7EL2i7FU/v9 ySUVSsoLRd19xjVjOLW+ZYGJIt1bMYPKXOsJBM+nUuxVMrmeofVKzXAnERzDIoCb3p/z rlO2kIGKKtXIIS063NjqLf15Iu48MKnDHFP6IflXRVMB1vgZPg2h82SfW9f7Nh9yPixx 4EMkbEV/R3DoVOl7NEVPPOByvfBt7u3esDG4XMfhd9Ji5yxcHG1AhW0XQjx52pzTHMvY yi9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i2Zu6XRR; 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 d1si10008324plr.145.2019.02.11.07.37.09; Mon, 11 Feb 2019 07:37:25 -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; dkim=pass header.i=@kernel.org header.s=default header.b=i2Zu6XRR; 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 S2388250AbfBKPgS (ORCPT + 99 others); Mon, 11 Feb 2019 10:36:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:38230 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388356AbfBKOwD (ORCPT ); Mon, 11 Feb 2019 09:52:03 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B864B2081B; Mon, 11 Feb 2019 14:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896722; bh=dcOVIART2IzLvjZPnq7Tr59A29Nr8oIiJe/yaKrkE6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i2Zu6XRRoeUwaDldwrCqYBnIBlbB8sM/KA6Tg6mEKncP670csPF0O7SdD3H1ioNxC NK68PSSHR8ThSFYEPnrnrvExPp2N0OHXJG8ZAwh41/vQduVNv2Tf8mu7jLqJhXwmnb 2qOl2cUsNFFueTDSDFOZ55k3vmDLsnpa4/1gIe/w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , Christoph Hellwig , "Darrick J. Wong" , Luis Chamberlain , Sasha Levin Subject: [PATCH 4.19 252/313] xfs: fix shared extent data corruption due to missing cow reservation Date: Mon, 11 Feb 2019 15:18:52 +0100 Message-Id: <20190211141910.169800156@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ commit 59e4293149106fb92530f8e56fa3992d8548c5e6 upstream. Page writeback indirectly handles shared extents via the existence of overlapping COW fork blocks. If COW fork blocks exist, writeback always performs the associated copy-on-write regardless if the underlying blocks are actually shared. If the blocks are shared, then overlapping COW fork blocks must always exist. fstests shared/010 reproduces a case where a buffered write occurs over a shared block without performing the requisite COW fork reservation. This ultimately causes writeback to the shared extent and data corruption that is detected across md5 checks of the filesystem across a mount cycle. The problem occurs when a buffered write lands over a shared extent that crosses an extent size hint boundary and that also happens to have a partial COW reservation that doesn't cover the start and end blocks of the data fork extent. For example, a buffered write occurs across the file offset (in FSB units) range of [29, 57]. A shared extent exists at blocks [29, 35] and COW reservation already exists at blocks [32, 34]. After accommodating a COW extent size hint of 32 blocks and the existing reservation at offset 32, xfs_reflink_reserve_cow() allocates 32 blocks of reservation at offset 0 and returns with COW reservation across the range of [0, 34]. The associated data fork extent is still [29, 35], however, which isn't fully covered by the COW reservation. This leads to a buffered write at file offset 35 over a shared extent without associated COW reservation. Writeback eventually kicks in, performs an overwrite of the underlying shared block and causes the associated data corruption. Update xfs_reflink_reserve_cow() to accommodate the fact that a delalloc allocation request may not fully cover the extent in the data fork. Trim the data fork extent appropriately, just as is done for shared extent boundaries and/or existing COW reservations that happen to overlap the start of the data fork extent. This prevents shared/010 failures due to data corruption on reflink enabled filesystems. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Luis Chamberlain Signed-off-by: Sasha Levin --- fs/xfs/xfs_reflink.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c index 42ea7bab9144..7088f44c0c59 100644 --- a/fs/xfs/xfs_reflink.c +++ b/fs/xfs/xfs_reflink.c @@ -302,6 +302,7 @@ xfs_reflink_reserve_cow( if (error) return error; + xfs_trim_extent(imap, got.br_startoff, got.br_blockcount); trace_xfs_reflink_cow_alloc(ip, &got); return 0; } -- 2.19.1