Skip to contentSkip to conversation

drm/amdgpu: fix mmhub client id out-of-bounds access

PATCH In review Lang Yu 2 participants 4 messages Mar 7, 2024 – Mar 8, 2024

Subsystems (2)
lore
Share & tools
lore

Lang Yu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: fix mmhub client id out-of-bounds access

Fixes aba2be41470a ("drm/amdgpu: add mmhub 3.3.0 support")
---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c +3 -4
index b3961968c10c..238ea40c2450 100644
@@ -99,16 +99,15 @@ mmhub_v3_3_print_l2_protection_fault_status(struct amdgpu_device *adev,
 	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
 	case IP_VERSION(3, 3, 0):
 	case IP_VERSION(3, 3, 1):
-		mmhub_cid = mmhub_client_ids_v3_3[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_3) ?
+			    mmhub_client_ids_v3_3[cid][rw] :
+			    cid == 0x140 ? "UMSCH" : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
 		break;
 	}
 
-	if (!mmhub_cid && cid == 0x140)
-		mmhub_cid = "UMSCH";
-
 	dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",
 		mmhub_cid ? mmhub_cid : "unknown", cid);
 	dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",
Signature · 1 line
2.25.1
#1 lore raw

[AMD Official Use Only - General]

Can we just add cid 0x140 "UMSCH" to mmhub_client_ids_v3_3 structure ?

-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Thursday, March 7, 2024 10:49 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Yifan <[email protected]>; Yu, Lang <[email protected]>
Subject: [PATCH] drm/amdgpu: fix mmhub client id out-of-bounds access

Fixes aba2be41470a ("drm/amdgpu: add mmhub 3.3.0 support")
---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c +3 -4
index b3961968c10c..238ea40c2450 100644
@@ -99,16 +99,15 @@ mmhub_v3_3_print_l2_protection_fault_status(struct amdgpu_device *adev,
        switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
        case IP_VERSION(3, 3, 0):
        case IP_VERSION(3, 3, 1):
-               mmhub_cid = mmhub_client_ids_v3_3[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_3) ?
+                           mmhub_client_ids_v3_3[cid][rw] :
+                           cid == 0x140 ? "UMSCH" : NULL;
                break;
        default:
                mmhub_cid = NULL;
                break;
        }
 
-       if (!mmhub_cid && cid == 0x140)
-               mmhub_cid = "UMSCH";
-
        dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",
                mmhub_cid ? mmhub_cid : "unknown", cid);
        dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",

--
2.25.1

author
#2 lore raw

[Public]

Quoted 10 lines

-----Original Message-----
From: Zhang, Yifan <[email protected]>
Sent: Thursday, March 7, 2024 11:11 AM
To: Yu, Lang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix mmhub client id out-of-bounds access

[AMD Official Use Only - General]

Can we just add cid 0x140 "UMSCH" to mmhub_client_ids_v3_3 structure ?

Yes, we can. Then mmhub_client_ids_v3_3's capacity will change from 31 to 320 and most of the space are unused.

Regards,
Lang

Quoted 44 lines

-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Thursday, March 7, 2024 10:49 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Yifan <[email protected]>; Yu, Lang <[email protected]>
Subject: [PATCH] drm/amdgpu: fix mmhub client id out-of-bounds access

Fixes aba2be41470a ("drm/amdgpu: add mmhub 3.3.0 support")

---
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c | 7 +++----

1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c +3 -4
index b3961968c10c..238ea40c2450 100644
@@ -99,16 +99,15 @@
 mmhub_v3_3_print_l2_protection_fault_status(struct amdgpu_device *adev,
       switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
       case IP_VERSION(3, 3, 0):
       case IP_VERSION(3, 3, 1):
-               mmhub_cid = mmhub_client_ids_v3_3[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_3) ?
+                           mmhub_client_ids_v3_3[cid][rw] :
+                           cid == 0x140 ? "UMSCH" : NULL;
               break;
       default:
               mmhub_cid = NULL;
               break;
       }
 
-       if (!mmhub_cid && cid == 0x140)
-               mmhub_cid = "UMSCH";
-
       dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",
               mmhub_cid ? mmhub_cid : "unknown", cid);
       dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",

--
2.25.1

Reviewed-by
#3 lore raw

[Public]

Yes, this is a trade-off b/w readability and code size. it is a nit-pick. Feel free to add:

Best Regards,
Yifan

-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Thursday, March 7, 2024 2:06 PM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix mmhub client id out-of-bounds access

[Public]

Quoted 11 lines

-----Original Message-----
From: Zhang, Yifan <[email protected]>
Sent: Thursday, March 7, 2024 11:11 AM
To: Yu, Lang <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: RE: [PATCH] drm/amdgpu: fix mmhub client id out-of-bounds access

[AMD Official Use Only - General]

Can we just add cid 0x140 "UMSCH" to mmhub_client_ids_v3_3 structure ?

Yes, we can. Then mmhub_client_ids_v3_3's capacity will change from 31 to 320 and most of the space are unused.

Regards,
Lang

Quoted 44 lines

-----Original Message-----
From: Yu, Lang <[email protected]>
Sent: Thursday, March 7, 2024 10:49 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Zhang, Yifan <[email protected]>; Yu, Lang <[email protected]>
Subject: [PATCH] drm/amdgpu: fix mmhub client id out-of-bounds access

Fixes aba2be41470a ("drm/amdgpu: add mmhub 3.3.0 support")

---
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c | 7 +++----

1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_3.c +3 -4
index b3961968c10c..238ea40c2450 100644
@@ -99,16 +99,15 @@
 mmhub_v3_3_print_l2_protection_fault_status(struct amdgpu_device *adev,
       switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
       case IP_VERSION(3, 3, 0):
       case IP_VERSION(3, 3, 1):
-               mmhub_cid = mmhub_client_ids_v3_3[cid][rw];
+               mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_3) ?
+                           mmhub_client_ids_v3_3[cid][rw] :
+                           cid == 0x140 ? "UMSCH" : NULL;
               break;
       default:
               mmhub_cid = NULL;
               break;
       }
 
-       if (!mmhub_cid && cid == 0x140)
-               mmhub_cid = "UMSCH";
-
       dev_err(adev->dev, "\t Faulty UTCL2 client ID: %s (0x%x)\n",
               mmhub_cid ? mmhub_cid : "unknown", cid);
       dev_err(adev->dev, "\t MORE_FAULTS: 0x%lx\n",

--
2.25.1