drm/amdgpu: Fix UBSAN shift-out-of-bounds for gfx v9_0
Subsystems (2)
PATCH 1/1 drm/amdgpu: Fix UBSAN shift-out-of-bounds for gfx v9_0
Check shift number to avoid doing a shift operation when the number of bits shifted equal to or greater than number of bits in the operand.
Signed-off-by Candice Li <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +5 -3
@@ -2494,7 +2494,7 @@ static u32 gfx_v9_0_get_rb_active_bitmap(struct amdgpu_device *adev)static void gfx_v9_0_setup_rb (struct amdgpu_device *adev) {int i, j; -u32 data; +u32 data, shift_num;u32 active_rbs =0 ;u32 rb_bitmap_width_per_sh = adev->gfx.config.max_backends_per_se / adev->gfx.config.max_sh_per_se;
@@ -2504,8 +2504,10 @@ static void gfx_v9_0_setup_rb(struct amdgpu_device *adev)for (j =0 ; j < adev->gfx.config.max_sh_per_se; j++) {gfx_v9_0_select_se_sh (adev, i, j,0xffffffff ); data =gfx_v9_0_get_rb_active_bitmap (adev); - active_rbs |= data << ((i * adev->gfx.config.max_sh_per_se + j) * - rb_bitmap_width_per_sh); + shift_num =min (((i * adev->gfx.config.max_sh_per_se + j) * + rb_bitmap_width_per_sh),__builtin_clz (data)); +if (data) + active_rbs |= data << shift_num; } }gfx_v9_0_select_se_sh (adev,0xffffffff ,0xffffffff ,0xffffffff );
Signature · 1 line
2.17.1