Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4823988pxj; Wed, 9 Jun 2021 02:45:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzdGM//H/jRtxXce/5OBP3tOE3yvaY5Od6KTgLBPQ0frU3DFaGOEp7KLVnReKLHVUHZ19lm X-Received: by 2002:a92:d412:: with SMTP id q18mr23484981ilm.258.1623231958789; Wed, 09 Jun 2021 02:45:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623231958; cv=none; d=google.com; s=arc-20160816; b=U0HzRF9svYf2oUHEbobT5ta40dPw422pvJqIf9E2TONy1QDA5z8M4BrG9SmKyXQbSL ye+/pLGB99hYnqO89e+ONPzDVFy0xbWreBs8Wszy6i0Q1ZVhuTG6ImaJw0fLitJiC7WF VhIwN1YYAZ3UsGdvaCEkpJ3jQ9WQ8lDOOWpL2BA7qqv3+JKja3AzXwyIxSUWJPasTVAm 6EbIowa8s4nz4YwghTHQj3RvxnKsWxV0EIY6+z2P85fBt5kTyGXJJT/6KlHB/mtAYHGT FZ/KJVuKh9cY1UQNkrCMsYOupRC6+E6DulthC6VoGOTwBEio6j10dlpCWfGMxEDvSOhe Xbzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bSrygbVfp8A9X8gP0/gkJWk/ui1TyBWmMndHYuCZLkI=; b=nniPJCmU83wCXr8HuWg8zSVezrMwz5mHaynE1umTv/6UgfIdPN13U8wM+CAg1oQ9lV 1VJnXSmpTP5hS6wnGeo3M2I38rf0nTuP0tykOHRF14Akx+qycnuPItKQtEUQcIGxupMN rrC0STzkn2w7U3fwk28HWnjnS4nF1qx7eIae7dT4OOIA9Vb4Sg/VLRPYRAZ+9DNXFjGf CYYY9iRF+MZVjtC4nTaet3HOjHZQHZ0Hwe/8Vy8MDSQ/UZofmfCJXkVRDv9Dr26GQn5N mlQ4PMCKHvpMuS1nj+VyP+akhruKhq8+SqC0T421unM9CBITGgJZWyyJ862vVv3oBoHe YuXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=e63Zx553; 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 e1si2946414jap.46.2021.06.09.02.45.46; Wed, 09 Jun 2021 02:45:58 -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=e63Zx553; 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 S234988AbhFHSqO (ORCPT + 99 others); Tue, 8 Jun 2021 14:46:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:40750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235204AbhFHSl5 (ORCPT ); Tue, 8 Jun 2021 14:41:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C9E1861440; Tue, 8 Jun 2021 18:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177317; bh=tdxkAgQ7QiWvPP74vo/lH4xWBDPoWkAZu/LdRhWYB6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e63Zx553sCQLTjECAdr+reBoPiV9FVUnXN+mAVN3RgXtr86+djJ4NukrpaYeMSvwl FLSvxV1NInCkSXY3pnT2ck1y2NcOaVea4QerVn9mh8e0tAQo4oXWSrNhgoCXD+VOhm xyvP+kBaDeCsVNbRXDlZw0l/xlF2jVibJG31wVgQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Tuomas=20L=C3=A4hdekorpi?= , Filipe Manana , Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 5.4 01/78] btrfs: tree-checker: do not error out if extent ref hash doesnt match Date: Tue, 8 Jun 2021 20:26:30 +0200 Message-Id: <20210608175935.313690735@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175935.254388043@linuxfoundation.org> References: <20210608175935.254388043@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik commit 1119a72e223f3073a604f8fccb3a470ccd8a4416 upstream. The tree checker checks the extent ref hash at read and write time to make sure we do not corrupt the file system. Generally extent references go inline, but if we have enough of them we need to make an item, which looks like key.objectid = key.type = key.offset = hash(tree, owner, offset) However if key.offset collide with an unrelated extent reference we'll simply key.offset++ until we get something that doesn't collide. Obviously this doesn't match at tree checker time, and thus we error while writing out the transaction. This is relatively easy to reproduce, simply do something like the following xfs_io -f -c "pwrite 0 1M" file offset=2 for i in {0..10000} do xfs_io -c "reflink file 0 ${offset}M 1M" file offset=$(( offset + 2 )) done xfs_io -c "reflink file 0 17999258914816 1M" file xfs_io -c "reflink file 0 35998517829632 1M" file xfs_io -c "reflink file 0 53752752058368 1M" file btrfs filesystem sync And the sync will error out because we'll abort the transaction. The magic values above are used because they generate hash collisions with the first file in the main subvol. The fix for this is to remove the hash value check from tree checker, as we have no idea which offset ours should belong to. Reported-by: Tuomas Lähdekorpi Fixes: 0785a9aacf9d ("btrfs: tree-checker: Add EXTENT_DATA_REF check") CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Filipe Manana Signed-off-by: Josef Bacik Reviewed-by: David Sterba [ add comment] Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/tree-checker.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 7d06842a3d74..368c43c6cbd0 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1285,22 +1285,14 @@ static int check_extent_data_ref(struct extent_buffer *leaf, return -EUCLEAN; } for (; ptr < end; ptr += sizeof(*dref)) { - u64 root_objectid; - u64 owner; u64 offset; - u64 hash; + /* + * We cannot check the extent_data_ref hash due to possible + * overflow from the leaf due to hash collisions. + */ dref = (struct btrfs_extent_data_ref *)ptr; - root_objectid = btrfs_extent_data_ref_root(leaf, dref); - owner = btrfs_extent_data_ref_objectid(leaf, dref); offset = btrfs_extent_data_ref_offset(leaf, dref); - hash = hash_extent_data_ref(root_objectid, owner, offset); - if (hash != key->offset) { - extent_err(leaf, slot, - "invalid extent data ref hash, item has 0x%016llx key has 0x%016llx", - hash, key->offset); - return -EUCLEAN; - } if (!IS_ALIGNED(offset, leaf->fs_info->sectorsize)) { extent_err(leaf, slot, "invalid extent data backref offset, have %llu expect aligned to %u", -- 2.30.2