From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB56673466; Tue, 27 Aug 2024 14:43:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724769804; cv=none; b=kpIDP/R9xL/yBVo4fJxQt8meNtOy65OrTenUDyz3xW6kEFoaMkWEUHNCR/enKKVJPeGgatlcc25ghUw1XgLadivrElqcbitCI585JD5+0Sw8FfE1wzYxSp6oit7ROUgc1Al15zIZOuZxrHjt3PByhV4W7jKH5ZCQ1b+agkc6bMw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724769804; c=relaxed/simple; bh=HpG711cAxszgdcYZnLOgF41D/JU8kB/nElqAn6/d5z0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lK8o6u1OPtxtWYtWvDK7AfPkmwKmKTMo9V1usWQuFrLZmO6l+R2+cL1z/Fszlak5rioY3Vmi9t4WIAe7GW208kNuyBDYorUfEVa1paBDb/VbG3m44BDjmE6fr2czAgjZcfS+LBR83kNfzR49X1KkwapwjlMVCEwxMC5edsWm2k0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zCnx1MtP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zCnx1MtP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30F2AC61052; Tue, 27 Aug 2024 14:43:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1724769804; bh=HpG711cAxszgdcYZnLOgF41D/JU8kB/nElqAn6/d5z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zCnx1MtPL5h2ZwffPuLkEvFzX0twUUxg464XIUBdnrDUN/kibqux9ygmbB5Tvlwzs erQJU+gMllamqGi6L6YGsKtN+Q0Os5XyTxnTuqdT72xSOCMbvIdVVGQD3VN6eSnBvb uG+NRL0kTe97PB1kibwNXiFWXYLrc0mviDFTM6oU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kota , Qu Wenruo , David Sterba Subject: [PATCH 6.6 040/341] btrfs: tree-checker: reject BTRFS_FT_UNKNOWN dir type Date: Tue, 27 Aug 2024 16:34:31 +0200 Message-ID: <20240827143844.938083769@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240827143843.399359062@linuxfoundation.org> References: <20240827143843.399359062@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qu Wenruo commit 31723c9542dba1681cc3720571fdf12ffe0eddd9 upstream. [REPORT] There is a bug report that kernel is rejecting a mismatching inode mode and its dir item: [ 1881.553937] BTRFS critical (device dm-0): inode mode mismatch with dir: inode mode=040700 btrfs type=2 dir type=0 [CAUSE] It looks like the inode mode is correct, while the dir item type 0 is BTRFS_FT_UNKNOWN, which should not be generated by btrfs at all. This may be caused by a memory bit flip. [ENHANCEMENT] Although tree-checker is not able to do any cross-leaf verification, for this particular case we can at least reject any dir type with BTRFS_FT_UNKNOWN. So here we enhance the dir type check from [0, BTRFS_FT_MAX), to (0, BTRFS_FT_MAX). Although the existing corruption can not be fixed just by such enhanced checking, it should prevent the same 0x2->0x0 bitflip for dir type to reach disk in the future. Reported-by: Kota Link: https://lore.kernel.org/linux-btrfs/CACsxjPYnQF9ZF-0OhH16dAx50=BXXOcP74MxBc3BG+xae4vTTw@mail.gmail.com/ CC: stable@vger.kernel.org # 5.4+ Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/tree-checker.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -548,9 +548,10 @@ static int check_dir_item(struct extent_ /* dir type check */ dir_type = btrfs_dir_ftype(leaf, di); - if (unlikely(dir_type >= BTRFS_FT_MAX)) { + if (unlikely(dir_type <= BTRFS_FT_UNKNOWN || + dir_type >= BTRFS_FT_MAX)) { dir_item_err(leaf, slot, - "invalid dir item type, have %u expect [0, %u)", + "invalid dir item type, have %u expect (0, %u)", dir_type, BTRFS_FT_MAX); return -EUCLEAN; }