Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3848263pxb; Tue, 17 Nov 2020 05:19:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPk8e1R6jbWRFWC9dAziUUZxJek5q4jBqnKK5JiuVT1A+ZtGTb3jT5EvZZ9AQYPinmSHLF X-Received: by 2002:a05:6402:22ab:: with SMTP id cx11mr19791388edb.98.1605619147872; Tue, 17 Nov 2020 05:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619147; cv=none; d=google.com; s=arc-20160816; b=bCOGXyvJBzjT/dPN6ErKPOKo+hq2KoKt5foIG+Z0Hsxs0QK2e2BDNAEwVaqOiQYgzm DjHEVKNVAMTgVOcBOeOGbOeouNE9CV58+UYu7pgB55xQt1M67eyYo41RFC0yI3NDkdNZ Tq3IMAxe25hHhrLZYhQZQTSR/gFfvoqb5znjeAXnfyi7un00tqtF7eSVr/WKoaKRpEWV tXplXZ2Z484I1GcVHuuUzE0BtJ8dwEq5DmZcREhCWC2bqkhUb2eCEAm0gkP3biq8Xcph fw/vx5zBRFDyLKfKj49ekByeQ4lM6lMHqnLUueEORqmHVNGuC+imfpoNvBSYeoR7j70m 1YPQ== 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=PW5Q0JqbGxEztZBi9tXIFm5NgJT2jKp+xfvu5Oi6tPc=; b=gJVjkrZbCDJaGdFRRRI1Rhq4AEKJ73lvmEM4aCMvf/1WqX/ps7gB40tV3LxyTZdkce vAqBuBInpoIKMs681HHTXleEvbnPeeIDBksSaEBnGsskRbLToQcA80w0ObIl2UlS4wrG BpjtDs0Omf+ToWqdbQ2eiZw30lifCHiwr5FHyMrMCrtZVqqZBlZ+WYEvFxpywzsIMttt ByJeJ/ZC8X/MVJ1z/p8VNl00qM4uH8BWy/UHMMwBcHofQeiQCKu7E6RV3kLCiXyZdCQS m98/kXXlgpRf7xXSE926kgWmSKl7mxMfp30NUCtP3FF44N3VJRTOuklkmXdbIkKkJZif rDQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Hnz+oliq; 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=fail (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 h19si13073483ejg.9.2020.11.17.05.18.44; Tue, 17 Nov 2020 05:19:07 -0800 (PST) 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=@kernel.org header.s=default header.b=Hnz+oliq; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729891AbgKQNQR (ORCPT + 99 others); Tue, 17 Nov 2020 08:16:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:47912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730258AbgKQNQL (ORCPT ); Tue, 17 Nov 2020 08:16:11 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 DF448221EB; Tue, 17 Nov 2020 13:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618969; bh=QYyaOXSd0eKMFSKWkG83c+g8K5KcFa/XwJ/YmR8wgiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hnz+oliqHZ/ksY5mDkp48zV5Osmcv9CR4ma99JDQ76WNq/owsSCuraAwp+iHzM6/k zhS9tPvFCfI6xr6pwpmxcX2LJ79SAeriJ9U4e16TdjmaY9rWv8vBhPnCDMtZ79b7YT qRaPolMQpNHBmA/6k8Yr2mUD+kqbvFUW4WFO/cmw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Darrick J. Wong" , Christoph Hellwig , Sasha Levin Subject: [PATCH 4.14 39/85] xfs: fix rmap key and record comparison functions Date: Tue, 17 Nov 2020 14:05:08 +0100 Message-Id: <20201117122112.940725240@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122111.018425544@linuxfoundation.org> References: <20201117122111.018425544@linuxfoundation.org> User-Agent: quilt/0.66 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: Darrick J. Wong [ Upstream commit 6ff646b2ceb0eec916101877f38da0b73e3a5b7f ] Keys for extent interval records in the reverse mapping btree are supposed to be computed as follows: (physical block, owner, fork, is_btree, is_unwritten, offset) This provides users the ability to look up a reverse mapping from a bmbt record -- start with the physical block; then if there are multiple records for the same block, move on to the owner; then the inode fork type; and so on to the file offset. However, the key comparison functions incorrectly remove the fork/btree/unwritten information that's encoded in the on-disk offset. This means that lookup comparisons are only done with: (physical block, owner, offset) This means that queries can return incorrect results. On consistent filesystems this hasn't been an issue because blocks are never shared between forks or with bmbt blocks; and are never unwritten. However, this bug means that online repair cannot always detect corruption in the key information in internal rmapbt nodes. Found by fuzzing keys[1].attrfork = ones on xfs/371. Fixes: 4b8ed67794fe ("xfs: add rmap btree operations") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_rmap_btree.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rmap_btree.c b/fs/xfs/libxfs/xfs_rmap_btree.c index 9d9c9192584c9..cd689d21d3af8 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -262,8 +262,8 @@ xfs_rmapbt_key_diff( else if (y > x) return -1; - x = XFS_RMAP_OFF(be64_to_cpu(kp->rm_offset)); - y = rec->rm_offset; + x = be64_to_cpu(kp->rm_offset); + y = xfs_rmap_irec_offset_pack(rec); if (x > y) return 1; else if (y > x) @@ -294,8 +294,8 @@ xfs_rmapbt_diff_two_keys( else if (y > x) return -1; - x = XFS_RMAP_OFF(be64_to_cpu(kp1->rm_offset)); - y = XFS_RMAP_OFF(be64_to_cpu(kp2->rm_offset)); + x = be64_to_cpu(kp1->rm_offset); + y = be64_to_cpu(kp2->rm_offset); if (x > y) return 1; else if (y > x) @@ -400,8 +400,8 @@ xfs_rmapbt_keys_inorder( return 1; else if (a > b) return 0; - a = XFS_RMAP_OFF(be64_to_cpu(k1->rmap.rm_offset)); - b = XFS_RMAP_OFF(be64_to_cpu(k2->rmap.rm_offset)); + a = be64_to_cpu(k1->rmap.rm_offset); + b = be64_to_cpu(k2->rmap.rm_offset); if (a <= b) return 1; return 0; @@ -430,8 +430,8 @@ xfs_rmapbt_recs_inorder( return 1; else if (a > b) return 0; - a = XFS_RMAP_OFF(be64_to_cpu(r1->rmap.rm_offset)); - b = XFS_RMAP_OFF(be64_to_cpu(r2->rmap.rm_offset)); + a = be64_to_cpu(r1->rmap.rm_offset); + b = be64_to_cpu(r2->rmap.rm_offset); if (a <= b) return 1; return 0; -- 2.27.0