Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd0bc5b7 authored by Kemeng Shi's avatar Kemeng Shi Committed by Greg Kroah-Hartman
Browse files

ext4: avoid negative min_clusters in find_group_orlov()



[ 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: ac27a0ec ("[PATCH] ext4: initial copy of files from ext3")
Signed-off-by: default avatarKemeng Shi <shikemeng@huaweicloud.com>
Link: https://patch.msgid.link/20240820132234.2759926-4-shikemeng@huaweicloud.com


Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent e8c1082c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -505,6 +505,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