]> git.baikalelectronics.ru Git - kernel.git/commit
ext4: avoid potential data overflow in next_linear_group
authorKemeng Shi <shikemeng@huaweicloud.com>
Tue, 1 Aug 2023 14:31:56 +0000 (22:31 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:42:46 +0000 (09:42 +0200)
commite0f5698757ab786830a59a80dc8054b08c7cd400
tree65c1e932aec92df6c54503a4662f5d072474f588
parent772ca4bc1d0d21320ef2ecc0f9e4f90ea85a035d
ext4: avoid potential data overflow in next_linear_group

[ Upstream commit 60c672b7f2d1e5dd1774f2399b355c9314e709f8 ]

ngroups is ext4_group_t (unsigned int) while next_linear_group treat it
in int. If ngroups is bigger than max number described by int, it will
be treat as a negative number. Then "return group + 1 >= ngroups ? 0 :
group + 1;" may keep returning 0.
Switch int to ext4_group_t in next_linear_group to fix the overflow.

Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning")
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Link: https://lore.kernel.org/r/20230801143204.2284343-3-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/ext4/mballoc.c