]> 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>
Fri, 4 Oct 2024 14:29:09 +0000 (16:29 +0200)
commitfa94d60546d2ba8c55f3c87483404162f1fbe863
tree43d54ae863608bd6e88e13ecd3c7ff3bd6b787c9
parent656803ab1ad2f0eb8f26bdf99f35decd224d0b8a
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