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 E9B311C2DB1; Tue, 27 Aug 2024 15:03:35 +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=1724771016; cv=none; b=Omi5UCdeTAUw9G1mkICeSQuxjn1+5oyHZL/AVPLurgUdvnKGDTIsAEdlxnPSB3rM/Bk4KFMiXYJWwZvZ9fqkkAHmFFA5WUgEJ1Zol1stXA3Ir8mSGPbJH835L3O+XotUTaw4d4DvTBttSDlteZu35hwrhv96Mz1Vp9gxKMMfjrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724771016; c=relaxed/simple; bh=cW2AuZW5Kub98Bkvd3MeJRt7V7xmX2dE5KA6z0V35Ao=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T+8nvKuhZm9Zx/xagt/wHnXzXC19Dpmrb279Hsms6WUXqKB3KANzIWVDFQdmFqgQe8dPy+rSodZHRjz7AL8qv3LjLCQWl+2F6dSCeauHS/TMQapdjCmnO4n7vxcu0NOs65AsF3XuXMg7H1KlvUbO2nVzzi3iUAmgOsQrVkFPZlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LALDLwOf; 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="LALDLwOf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00BCFC6104C; Tue, 27 Aug 2024 15:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1724771015; bh=cW2AuZW5Kub98Bkvd3MeJRt7V7xmX2dE5KA6z0V35Ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LALDLwOfrmQ36lidQDG56WX4l/fmwBMkVuLNp6R5cu85RHTHcXrP9atsRNCN4SlRS Osr//Qqp2tadnoddGvYe8Ka1qto6AdbdEIk8MzsNpaNtbMZfE3XLTlzTNSjLllVSGS wRRqqK/w9JvH/tEGe0gRjX82z3TQhfa6z5hvElhQ= 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.10 060/273] btrfs: tree-checker: reject BTRFS_FT_UNKNOWN dir type Date: Tue, 27 Aug 2024 16:36:24 +0200 Message-ID: <20240827143835.686323433@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240827143833.371588371@linuxfoundation.org> References: <20240827143833.371588371@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.10-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 @@ -551,9 +551,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; }