]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
drm/radeon/evergreen_cs: fix int overflow errors in cs track offsets
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Tue, 6 Aug 2024 17:19:04 +0000 (10:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:10:52 +0000 (15:10 +0200)
commite8a4a2e45ddfc7197f1eefb61fba65cfd7844c3f
tree5b0f6a38a9a4a3839a9f05b4df311b58ab5639c4
parent4d871e3e8dfea0bdc8dca8780168b304ff5c756f
drm/radeon/evergreen_cs: fix int overflow errors in cs track offsets

[ Upstream commit 3fbaf475a5b8361ebee7da18964db809e37518b7 ]

Several cs track offsets (such as 'track->db_s_read_offset')
either are initialized with or plainly take big enough values that,
once shifted 8 bits left, may be hit with integer overflow if the
resulting values end up going over u32 limit.

Same goes for a few instances of 'surf.layer_size * mslice'
multiplications that are added to 'offset' variable - they may
potentially overflow as well and need to be validated properly.

While some debug prints in this code section take possible overflow
issues into account, simply casting to (unsigned long) may be
erroneous in its own way, as depending on CPU architecture one is
liable to get different results.

Fix said problems by:
 - casting 'offset' to fixed u64 data type instead of
 ambiguous unsigned long.
 - casting one of the operands in vulnerable to integer
 overflow cases to u64.
 - adjust format specifiers in debug prints to properly
 represent 'offset' values.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: 285484e2d55e ("drm/radeon: add support for evergreen/ni tiling informations v11")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/radeon/evergreen_cs.c