]> www.infradead.org Git - users/jedix/linux-maple.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)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 16 Aug 2024 18:23:10 +0000 (14:23 -0400)
commit3fbaf475a5b8361ebee7da18964db809e37518b7
treee9c62d3c3b3c84991d7aa4360d0c0814a185bfe2
parent89ec85d16eb8110d88c273d1d34f1fe5a70ba8cc
drm/radeon/evergreen_cs: fix int overflow errors in cs track offsets

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>
drivers/gpu/drm/radeon/evergreen_cs.c