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 ADFDD1CF7D4; Wed, 2 Oct 2024 14:36:30 +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=1727879790; cv=none; b=JAJtBEg8kECOrJXztXpNEA3U+0ceSWLOgtzo4bfOOSTwG7W20oBwKbi/Kng3dP1jnvRxku9fZdyOXJSWDpvlNh8zsyGjLABFhCgwKHSZCeFop53+m5RwySFpBjxRoDhzoKx2dWaOt+bAtPjuweFEFL6TtarQcDn2pfNjHmT7NOs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727879790; c=relaxed/simple; bh=8N9lYnrJ1+uuN2kzeZrnqzT9yop7NMCBdH8uS0jTCdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GgGoIhk5XsL98pHsvysrP0QnpifowXLbo1mBzSTRwjr4IVHIZVR7P8/zLQHA8YajnmuZE358b3Tsjk34J98/KhW7F1ASym0m0xGuJMhsKkTkTKH1CouUqcxjnTeduWwhVLfKuJ8kqb9Zt5VDMxh8LKlfGqlOwLMc+aXv8/p7DAg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VFgqsSBb; 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="VFgqsSBb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26596C4CEC2; Wed, 2 Oct 2024 14:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1727879790; bh=8N9lYnrJ1+uuN2kzeZrnqzT9yop7NMCBdH8uS0jTCdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VFgqsSBbm8djIL8fL34pUPDBt6eQy3CWzG1UmroWTEH7Un/VpFUgQ9DzutnUrLZeI Hd0fdEEqWUKRCWUYeC2CsvZIJOtVgNi4m6KxnrEbfmW1gfZw2xBcLb6fk9CB+pbi5f XClBU4yNEAqNqDTO7y9ZEMEAtmfc8gc7lEodPYVs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ryusuke Konishi , Lizhi Xu , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 240/538] nilfs2: determine empty node blocks as corrupted Date: Wed, 2 Oct 2024 14:57:59 +0200 Message-ID: <20241002125801.723944354@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241002125751.964700919@linuxfoundation.org> References: <20241002125751.964700919@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: Ryusuke Konishi [ Upstream commit 111b812d3662f3a1b831d19208f83aa711583fe6 ] Due to the nature of b-trees, nilfs2 itself and admin tools such as mkfs.nilfs2 will never create an intermediate b-tree node block with 0 child nodes, nor will they delete (key, pointer)-entries that would result in such a state. However, it is possible that a b-tree node block is corrupted on the backing device and is read with 0 child nodes. Because operation is not guaranteed if the number of child nodes is 0 for intermediate node blocks other than the root node, modify nilfs_btree_node_broken(), which performs sanity checks when reading a b-tree node block, so that such cases will be judged as metadata corruption. Link: https://lkml.kernel.org/r/20240904081401.16682-3-konishi.ryusuke@gmail.com Fixes: 17c76b0104e4 ("nilfs2: B-tree based block mapping") Signed-off-by: Ryusuke Konishi Cc: Lizhi Xu Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/nilfs2/btree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c index fa51ed649968e..dac090c162a7a 100644 --- a/fs/nilfs2/btree.c +++ b/fs/nilfs2/btree.c @@ -350,7 +350,7 @@ static int nilfs_btree_node_broken(const struct nilfs_btree_node *node, if (unlikely(level < NILFS_BTREE_LEVEL_NODE_MIN || level >= NILFS_BTREE_LEVEL_MAX || (flags & NILFS_BTREE_NODE_ROOT) || - nchildren < 0 || + nchildren <= 0 || nchildren > NILFS_BTREE_NODE_NCHILDREN_MAX(size))) { nilfs_crit(inode->i_sb, "bad btree node (ino=%lu, blocknr=%llu): level = %d, flags = 0x%x, nchildren = %d", -- 2.43.0