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 08B45646; Wed, 6 Nov 2024 13:00:38 +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=1730898040; cv=none; b=HnZF/sewuNpXodR92bXuc7Ag8P7FhBo6vBoff35cDcEGriwfZpFQuJPJWqrUZ/QWGPjAjWVZrHkg/teKNHCWhPlVr1gh2eEzjquq2dEesJIQ7BqQkS14q24MUdELIwjB3be1gSFRM7n4mySMwDZlIGrA+NYpvkrasEtD1CTF4wU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730898040; c=relaxed/simple; bh=ws58NmmqC6vWhO19gBd7BTvXgi7GV2QZmqTjd4XIiDI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k/HfI/nuWKdL11HYbznIcQ/Suwms8yl2RFrRSHdCITJ+bxSI/EVp+bRlAQvDkSfxWa3/NlqUUkWG5gsSbaylsUyBJS60NHiy7IjAs7/aeqMNfdWlkcDtJduGkMVQkzl2nCOvHDarKbzqkFaYMzj3o+8zKsznjnB3xnhXYmnWMks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jV488KLR; 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="jV488KLR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F932C4CECD; Wed, 6 Nov 2024 13:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730898038; bh=ws58NmmqC6vWhO19gBd7BTvXgi7GV2QZmqTjd4XIiDI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jV488KLRn9ztD4Ga7eDLnf5ZIfOc4tDZhxpjaCKtY0oHGuWkh1F7MlhiCn+LFXhBQ sRxJI+g2/82wLzGtmCBp25KdntBrAvTa/ermWeorml0Fbw+evu0iMYwHpiBPooeLIt ca50HWYtISpkdum0DHQfkSS2UqremMJJiRr66LEY= 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 5.4 102/462] nilfs2: determine empty node blocks as corrupted Date: Wed, 6 Nov 2024 12:59:55 +0100 Message-ID: <20241106120334.025370762@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120331.497003148@linuxfoundation.org> References: <20241106120331.497003148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-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 c2aca9cd78644..7cfff27b4b4a5 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