Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2028839rwe; Fri, 2 Sep 2022 07:33:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7oT9K903Za4d8sGRX4zkpInru5k24YmykPBpZCG3XwXl7eIWYct4qLlCgBpQ4dP7kYWGWP X-Received: by 2002:a17:906:9bf0:b0:741:362a:3ff1 with SMTP id de48-20020a1709069bf000b00741362a3ff1mr22954688ejc.275.1662129221292; Fri, 02 Sep 2022 07:33:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662129221; cv=none; d=google.com; s=arc-20160816; b=gBoASl0ovxkiCJH14W/I9MrNmwlSu+Y4E19ZZ9HFexwJtrJMsbP7XPsQXoZgn+3a76 V8wAyb0qW5wbfwepAplnEf05MPcOjJVam7HP59c6n8xCJpswaL2chzdXYhVe7nKOgloI Qo0ygJSxWbfOiFlDlC4i1ogKKRyskALfJQocbiptcDzxEfUR3ZgFooETCjgNW5i2KGPu 5BrzN0dNkhp269qTaeptWjfTBjTF+DXnfGYxAHRYNj5GYutXA7+Xib9e7zu0rLkIMjgf aiyhLLzfOo+gUnwO7m3eGi8/Hh3Jvsel76473Kus7PQRitOaZq1kRFKEw0/2DhDQbiAb yxBQ== 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=7XierpdCun+riw/7eK0WUdbuqhevixPLv8OXO/VRMuE=; b=V+PWcFi4mVX0TDuCFZNWoJftjEsKVvqR+QF3XfJMKJ9w5TK8/0SIMcxEJkKIflptLP Oe+yVezTjGO9sNnxuA4Dc25vUtUO0sRad+f5pt9kc+Xir5SkJnYQjiNq6vLqZXNzRR7o eHDQwzW6CCfoZ/a/qAJUmn4F8+tfPrTqrvgQcgmGkvAY9LaDMdtbcv0ESnYlGaLyrQGb 6n3S1LrIRpTuA2Ez1NTsYpDZDO9dTZ1TOgRF9PXa/6Ot3kgO7zNghlFSHlV0j4ZCUYLP EyJaaksqJbvAFYLNIae7mWlvwJ+aBINKL3nnbv/X1M7EqT4X3MXwf1VQOFZiBUvnqm2K R7kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n/xyY4Vu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a1709062d4900b0073dce13c643si1757386eji.872.2022.09.02.07.33.10; Fri, 02 Sep 2022 07:33:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="n/xyY4Vu"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S236294AbiIBNhZ (ORCPT + 99 others); Fri, 2 Sep 2022 09:37:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236934AbiIBNgb (ORCPT ); Fri, 2 Sep 2022 09:36:31 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FCFC0E61; Fri, 2 Sep 2022 06:15:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0753D621B3; Fri, 2 Sep 2022 12:34:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B11BC43140; Fri, 2 Sep 2022 12:34:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662122081; bh=FadrqUdVsz2jlLOfSCllylWQHjBpsfMwpCQB/vkl2lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n/xyY4VuatCgkVbNd7d6yxonhBvE/YJOPh3Njproj27lOVOdsLGOD453QPLh3A73l YOT/DRAZr84uI0YNwerPRokm28YiK3MYeg2BgOslqQRxIErXluF3l/3x8QZ8mkWJg7 BpKdvF//qSGipGDAgguaA9mBK8g+v1yZbsT6LdAc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , Josef Bacik , David Sterba , Sasha Levin Subject: [PATCH 5.15 68/73] btrfs: tree-checker: check for overlapping extent items Date: Fri, 2 Sep 2022 14:19:32 +0200 Message-Id: <20220902121406.640584762@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121404.435662285@linuxfoundation.org> References: <20220902121404.435662285@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik [ Upstream commit 899b7f69f244e539ea5df1b4d756046337de44a5 ] We're seeing a weird problem in production where we have overlapping extent items in the extent tree. It's unclear where these are coming from, and in debugging we realized there's no check in the tree checker for this sort of problem. Add a check to the tree-checker to make sure that the extents do not overlap each other. Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/tree-checker.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 51382d2be3d44..a84d2d4895104 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1216,7 +1216,8 @@ static void extent_err(const struct extent_buffer *eb, int slot, } static int check_extent_item(struct extent_buffer *leaf, - struct btrfs_key *key, int slot) + struct btrfs_key *key, int slot, + struct btrfs_key *prev_key) { struct btrfs_fs_info *fs_info = leaf->fs_info; struct btrfs_extent_item *ei; @@ -1436,6 +1437,26 @@ static int check_extent_item(struct extent_buffer *leaf, total_refs, inline_refs); return -EUCLEAN; } + + if ((prev_key->type == BTRFS_EXTENT_ITEM_KEY) || + (prev_key->type == BTRFS_METADATA_ITEM_KEY)) { + u64 prev_end = prev_key->objectid; + + if (prev_key->type == BTRFS_METADATA_ITEM_KEY) + prev_end += fs_info->nodesize; + else + prev_end += prev_key->offset; + + if (unlikely(prev_end > key->objectid)) { + extent_err(leaf, slot, + "previous extent [%llu %u %llu] overlaps current extent [%llu %u %llu]", + prev_key->objectid, prev_key->type, + prev_key->offset, key->objectid, key->type, + key->offset); + return -EUCLEAN; + } + } + return 0; } @@ -1604,7 +1625,7 @@ static int check_leaf_item(struct extent_buffer *leaf, break; case BTRFS_EXTENT_ITEM_KEY: case BTRFS_METADATA_ITEM_KEY: - ret = check_extent_item(leaf, key, slot); + ret = check_extent_item(leaf, key, slot, prev_key); break; case BTRFS_TREE_BLOCK_REF_KEY: case BTRFS_SHARED_DATA_REF_KEY: -- 2.35.1