ext4: avoid to access uninitialized block_cluster

Message ID 20230320212106.4164212-1-shikemeng@huaweicloud.com
State New
Headers
Series ext4: avoid to access uninitialized block_cluster |

Commit Message

Kemeng Shi March 20, 2023, 9:21 p.m. UTC
  If inode bitmap block and block bitmap block are in different group,
there is a risk to access uninitialized block_cluster in
ext4_num_overhead_clusters. Initialize block_cluster to -1 to fix this.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Link: https://lore.kernel.org/r/202303171446.eLEhZzAu-lkp@intel.com/
Fixes: e3c70113e2cb ("ext4: improve inode table blocks counting in ext4_num_overhead_clusters")
---
 fs/ext4/balloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Theodore Ts'o March 23, 2023, 2:18 p.m. UTC | #1
On Tue, Mar 21, 2023 at 05:21:06AM +0800, Kemeng Shi wrote:
> If inode bitmap block and block bitmap block are in different group,
> there is a risk to access uninitialized block_cluster in
> ext4_num_overhead_clusters. Initialize block_cluster to -1 to fix this.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Reported-by: Dan Carpenter <error27@gmail.com>
> Link: https://lore.kernel.org/r/202303171446.eLEhZzAu-lkp@intel.com/
> Fixes: e3c70113e2cb ("ext4: improve inode table blocks counting in ext4_num_overhead_clusters")

Thanks for the fix-up and to Dan and the zero-day test bot for noting
the problem.  Since I've needed to rebase the ext4 dev tree to pick up
an urgent fixup as well as deal with some other problematic commits,
I've merged this fix into the base commit "ext4: improve inode table
blocks counting in ext4_num_overhead_clusters".

Cheers,

					- Ted
  

Patch

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 49fdb758b0e4..094269488183 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -89,7 +89,7 @@  static unsigned ext4_num_overhead_clusters(struct super_block *sb,
 					   struct ext4_group_desc *gdp)
 {
 	unsigned base_clusters, num_clusters;
-	int block_cluster, inode_cluster;
+	int block_cluster = -1, inode_cluster;
 	int itbl_cluster_start = -1, itbl_cluster_end = -1;
 	ext4_fsblk_t start = ext4_group_first_block_no(sb, block_group);
 	ext4_fsblk_t end = start + EXT4_BLOCKS_PER_GROUP(sb) - 1;