Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3874988pxb; Tue, 17 Nov 2020 05:59:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuFE/RRNpaiEeFL3I7FUR/m620jRniE7Isgr/m+lTX11BCACDjSXvcx9+8m7PpV/roQo/8 X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr18853185ejb.323.1605621581542; Tue, 17 Nov 2020 05:59:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621581; cv=none; d=google.com; s=arc-20160816; b=Ja9qWseUORuhN8HfcBftPLLe6RxRc0cr1vxqlwggHcEG6fWwRARnl3Q0TIPqtAdVrq Kfholg8CNvQw1gfYtZm63fQZyf5M86xCotGINhqZOa9mtCe/oHFG22Z/q9wrYBXrKZGW I+oru6eRDZf7XVihlq6S7akWEUVpfxbHAYAeXeEgC4MLfqzbCYncdMM72fcU0KnXYAti sOE2kdpw4p85xMhAqcpDZquw4x+p5guRZtAPhzOARPW7+K+yxFrX86SGRaFdyzS/Q5sn JKwVwXLa0k6/fIKDbOUkChbEZVVr1NJr/bJ5sJBLQn8gmyNTmp1pnJqTURQReqN/gY7F 1yHQ== 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=1aSr+FlDCCrk0LqrmmpHtPBkH4CzWNMxKUWhshd79VM=; b=Xs+WGiSVeEg5xxwY6hBCAnN4ql1CpD10gbdpX+tLXqZeHu7meVNvp1qTPRAKsTTcpn 828EIUdM6qAdRwMhe9fxRv18BNRaVUyNklr+iOuvIxOxjc3y2Q+wcmKB6h95LkN09OeY pXxYwPW+cXFYayoFY8ucMLRCHq4hrPJgaR6Z+v6YpV6kmdFoxVRcOHEmmME1Mt5LdD4s NEptDsNKbIsrs2Kjrd30UYOb2cjvk+yrCrUZ3BlqNNFMBS8QFWHdRp8K0kUUcbaHFVi4 CSuG6Qf3IoEJux9Omgo3LqYPZlx8gMH6RpCQRS1xQ5bVT7FSljuipurttcLVBqUiZsFo 5hhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vJQQEIKT; 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 h13si13233523ejy.499.2020.11.17.05.59.18; Tue, 17 Nov 2020 05:59:41 -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=vJQQEIKT; 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 S1731321AbgKQN5l (ORCPT + 99 others); Tue, 17 Nov 2020 08:57:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:52796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730308AbgKQNTn (ORCPT ); Tue, 17 Nov 2020 08:19:43 -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 B894324631; Tue, 17 Nov 2020 13:19:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619182; bh=KwYkJC3COhSWJHnWUdpaelGcfET4+71FmFtMFzMMIr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vJQQEIKTP/GFPtNwjxIqUJeMkn4QjwpqX5LA/+bPFsuaeef+DNhBYp4azPWuXLnJl teT81NjxXF6u0MMgcvAGcL13M6LvSxg6I8r4BoL2UzpGUhh9JefMlOn95fHjNKWXed a3jhFJq/nxvWg/gmm/6QeGVojKSRhTMpCFcdGJDk= 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.19 056/101] xfs: fix rmap key and record comparison functions Date: Tue, 17 Nov 2020 14:05:23 +0100 Message-Id: <20201117122115.827859082@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@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 f79cf040d7450..77528f413286b 100644 --- a/fs/xfs/libxfs/xfs_rmap_btree.c +++ b/fs/xfs/libxfs/xfs_rmap_btree.c @@ -247,8 +247,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) @@ -279,8 +279,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) @@ -393,8 +393,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; @@ -423,8 +423,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