Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1976331rwe; Fri, 2 Sep 2022 06:53:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR5rTrwpGr8jTuONR2NSK3S2MI7V6EFHamaqBXsV0POSHSb9WpDjzQBa6PZIdn7SpF9QUkGU X-Received: by 2002:a63:86c6:0:b0:42b:329d:de3f with SMTP id x189-20020a6386c6000000b0042b329dde3fmr31579565pgd.258.1662126783763; Fri, 02 Sep 2022 06:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662126783; cv=none; d=google.com; s=arc-20160816; b=TcKoFQuy/D0cVnMO1LCl5ELPnXUjqDmeePvfdxjGmefP9MgSSan0MxzPsRO3XcPlKe 6YPmTKocpN1f7idXjUoMxwchBXHTp+tsAOTzNUhSoEfjPrD8QgehjTxyDe7/Ok0ydO8Y h9/FH9V4A2jvytMJlJpqNwgIyqsIcqJxIVVMX8cMeOhnVFsgYGq4aBDHJgMq6Fd8y4fx FjExPpSuNUbhqrC5IDHRcbwl1aHtZSkE8fQjm94sGzwCt5zdVgqFkwxudMgfG5kQ5b4z +sCcRd9laus7EMc87rHT3B7fy9vu02wam5Prx8SFANX0bUWQYMe5Ozf01Y5+fhs75AeZ Gs8A== 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=hQ0SAIL6m0neFXOrjALitv5DWPqXLjgVrO8OvPlQXK4=; b=I3evxeaeFUC9VIcE2jCE0qKYFE2WeiyMiC8KJP4quSyKE78AHDH33D+DURJJvXF5XI CzWwJWFcjTGxD9YLgcVCL4XFUL8HrlUZJ6uJkb1ECiRm27TK5yqaXy/6tTe/2PFL6OKF zRIYhK6qHnWa1Yiw0S6XIAOKd9dZHajEHzUlzkb+QD3xWgqeOKzQVRQ7RCBzAXadwzEx gt3Tyck6LHe+axrObWyPH7KygJfjHsXV5JY4gryIGaOY0hDtCiMHmmUpjteIinuBcEA/ jPLBgUXN7STvccYeKJqBeVLhByvRFoGTXXRr2i6B1P6dd3uWdE8Xp/wmDsUe9w30pNZD cbeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bu3zpcl1; 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 i1-20020aa78d81000000b00535c451053esi2179426pfr.296.2022.09.02.06.52.51; Fri, 02 Sep 2022 06:53:03 -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=bu3zpcl1; 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 S238121AbiIBM43 (ORCPT + 99 others); Fri, 2 Sep 2022 08:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238189AbiIBMyD (ORCPT ); Fri, 2 Sep 2022 08:54:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18C95FB0DF; Fri, 2 Sep 2022 05:38:28 -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 BEB8662190; Fri, 2 Sep 2022 12:37:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5391C433C1; Fri, 2 Sep 2022 12:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662122274; bh=OcfyeE3fbS7IKNlI13n5GlUJOEXKlKESfM6h74E8J5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bu3zpcl1nax5wazQoxI5/gf/Ap5Z9r8d6es/DLp/jHVOBRciXFAcQfIvoGYv9LrLe hB7TFb5rm8w7ccR0c+u8vjIb9pYAy2Kp8VSRqk9YeMdPfK44LiToi130dd6by7hnlv BOhLQzt7EHcek459AEtevqMcyVjmASRuAMEjGEiw= 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.19 68/72] btrfs: tree-checker: check for overlapping extent items Date: Fri, 2 Sep 2022 14:19:44 +0200 Message-Id: <20220902121407.032552411@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220902121404.772492078@linuxfoundation.org> References: <20220902121404.772492078@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(-) --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1233,7 +1233,8 @@ static void extent_err(const struct exte } 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; @@ -1453,6 +1454,26 @@ static int check_extent_item(struct exte 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; } @@ -1621,7 +1642,7 @@ static int check_leaf_item(struct extent 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: