Skip to content

Commit

Permalink
ext4: avoid negative min_clusters in find_group_orlov()
Browse files Browse the repository at this point in the history
[ Upstream commit bb0a12c3439b10d88412fd3102df5b9a6e3cd6dc ]

min_clusters is signed integer and will be converted to unsigned
integer when compared with unsigned number stats.free_clusters.
If min_clusters is negative, it will be converted to a huge unsigned
value in which case all groups may not meet the actual desired free
clusters.
Set negative min_clusters to 0 to avoid unexpected behavior.

Fixes: ac27a0e ("[PATCH] ext4: initial copy of files from ext3")
Signed-off-by: Kemeng Shi <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Kemeng Shi authored and simonami99 committed Oct 29, 2024
1 parent acc8f5b commit 9473f56
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fs/ext4/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
if (min_inodes < 1)
min_inodes = 1;
min_clusters = avefreec - EXT4_CLUSTERS_PER_GROUP(sb)*flex_size / 4;
if (min_clusters < 0)
min_clusters = 0;

/*
* Start looking in the flex group where we last allocated an
Expand Down

0 comments on commit 9473f56

Please sign in to comment.