Skip to contentSkip to conversation

drm/amdgu: fix Unintentional integer overflow for mall size

PATCH In review Jesse Zhang 2 participants 2 messages May 30, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/8 drm/amdgu: fix Unintentional integer overflow for mall size

Potentially overflowing expression mall_size_per_umc * adev->gmc.num_umc with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic,and then used in a context that expects an expression of type u64 (64 bits, unsigned).

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
index 98e8f30824c3..9e0cfe06c8b1 100644
@@ -1639,7 +1639,7 @@ static int amdgpu_discovery_get_mall_info(struct amdgpu_device *adev)
 		break;
 	case 2:
 		mall_size_per_umc = le32_to_cpu(mall_info->v2.mall_size_per_umc);
-		adev->gmc.mall_size = mall_size_per_umc * adev->gmc.num_umc;
+		adev->gmc.mall_size = (uint64_t)mall_size_per_umc * adev->gmc.num_umc;
 		break;
 	default:
 		dev_err(adev->dev,
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Am 30.05.24 um 05:46 schrieb Jesse Zhang:

Quoted 2 lines

Potentially overflowing expression mall_size_per_umc * adev->gmc.num_umc with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic,and then used in a context that expects an expression of type u64 (64 bits, unsigned).

Maybe better change the type of the local variable instead?

On the other hand feel free to add Reviewed-by: Christian König <[email protected]> to this one as well.

Regards,
Christian.

Quoted 19 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +1 -1
index 98e8f30824c3..9e0cfe06c8b1 100644
@@ -1639,7 +1639,7 @@ static int amdgpu_discovery_get_mall_info(struct amdgpu_device *adev)
  		break;
  	case 2:
  		mall_size_per_umc = le32_to_cpu(mall_info->v2.mall_size_per_umc);
-		adev->gmc.mall_size = mall_size_per_umc * adev->gmc.num_umc;
+		adev->gmc.mall_size = (uint64_t)mall_size_per_umc * adev->gmc.num_umc;
  		break;
  	default:
  		dev_err(adev->dev,