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 75E2C1D5AD7; Wed, 6 Nov 2024 12:10:18 +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=1730895018; cv=none; b=fcVjENV/7deOpQ7MZ3u8N4NIYLibmvn6aBfsUZnu8+0/roU3ILersEhzExzKC7E1LzP5ofIcM0fM/cnzp6KKdNADf4h/wZn+ARRN5S0ABTC3EQXY517QOwa9mLmfz+aau8Q77CF8y3cIxiCHrJerB15VD6gmntPdXFStcd3cLvg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730895018; c=relaxed/simple; bh=fcQl3aXJ5zwedk0NV/1/URzCPud+7E2lpZsZEFE2D80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sbk+/BcUxmRfvLSDUjUt+Q7ZbsncYtzK1+eQcv/ngvkvWSBbnLKL3dMTVgOLTv5ODS0/zc1xeYh0679+3MZ/hNxpgMi2baRl/PdFZDa8L5RXw71J4Rw0olkz85Yq92QwDJ1GGu0/6soU/CJJkzRZJcYMEnfXaO6n8mdJuZSEvyY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N5PJqEuv; 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="N5PJqEuv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF027C4CECD; Wed, 6 Nov 2024 12:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1730895018; bh=fcQl3aXJ5zwedk0NV/1/URzCPud+7E2lpZsZEFE2D80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5PJqEuv5tQZckAS94wvKbO5qYa5IE6dk7r+4wRVCITfRGDP3grevRVekeFaQI//m NAShXpHGKkAOoMBnwp12KUFgeAcxuFOgFL+k73Ff6ASZCetZnlfAU5/9GRX7M3MYre te1YIzhEWIEWDGuST7YUGgercSNgQUHtBahhKTOA= 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 4.19 077/350] nilfs2: determine empty node blocks as corrupted Date: Wed, 6 Nov 2024 13:00:05 +0100 Message-ID: <20241106120322.797317123@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106120320.865793091@linuxfoundation.org> References: <20241106120320.865793091@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 4.19-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