Skip to contentSkip to conversation

drm/amdgpu/mmhub2.0: add bounds checking for cid

PATCH In review Alex Deucher 4 participants 11 messages Mar 4 – Mar 16

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/7 drm/amdgpu/mmhub2.0: add bounds checking for cid

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +6 -3
index a0cc8e218ca1e..534cb4c544dc4 100644
@@ -154,14 +154,17 @@ mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
 	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
 	case IP_VERSION(2, 0, 0):
 	case IP_VERSION(2, 0, 2):
-		mmhub_cid = mmhub_client_ids_navi1x[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_navi1x) ?
+			mmhub_client_ids_navi1x[cid][rw] : NULL;
 		break;
 	case IP_VERSION(2, 1, 0):
 	case IP_VERSION(2, 1, 1):
-		mmhub_cid = mmhub_client_ids_sienna_cichlid[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_sienna_cichlid) ?
+			mmhub_client_ids_sienna_cichlid[cid][rw] : NULL;
 		break;
 	case IP_VERSION(2, 1, 2):
-		mmhub_cid = mmhub_client_ids_beige_goby[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_beige_goby) ?
+			mmhub_client_ids_beige_goby[cid][rw] : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 2/7 drm/amdgpu/mmhub2.3: add bounds checking for cid

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v2_3.c +2 -1
index 5a071a788d933..3e0f147edbb9a 100644
@@ -96,7 +96,8 @@ mmhub_v2_3_print_l2_protection_fault_status(struct amdgpu_device *adev,
 	case IP_VERSION(2, 3, 0):
 	case IP_VERSION(2, 4, 0):
 	case IP_VERSION(2, 4, 1):
-		mmhub_cid = mmhub_client_ids_vangogh[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_vangogh) ?
+			mmhub_client_ids_vangogh[cid][rw] : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
Signature · 1 line
2.53.0
author maintainer
#2 lore raw

PATCH 3/7 drm/amdgpu/mmhub3.0.1: add bounds checking for cid

In reply to Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_0_1.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_0_1.c +2 -1
index 910337dc28d10..14a742d3a99d7 100644
@@ -117,7 +117,8 @@ mmhub_v3_0_1_print_l2_protection_fault_status(struct amdgpu_device *adev,
 
 	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
 	case IP_VERSION(3, 0, 1):
-		mmhub_cid = mmhub_client_ids_v3_0_1[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_0_1) ?
+			mmhub_client_ids_v3_0_1[cid][rw] : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
Signature · 1 line
2.53.0
author maintainer
#3 lore raw

PATCH 4/7 drm/amdgpu/mmhub3.0.2: add bounds checking for cid

In reply to Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_0_2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_0_2.c +2 -1
index f0f182f033b98..e1f07f2a18527 100644
@@ -108,7 +108,8 @@ mmhub_v3_0_2_print_l2_protection_fault_status(struct amdgpu_device *adev,
 		"MMVM_L2_PROTECTION_FAULT_STATUS:0x%08X\n",
 		status);
 
-	mmhub_cid = mmhub_client_ids_v3_0_2[cid][rw];
+	mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_0_2) ?
+		mmhub_client_ids_v3_0_2[cid][rw] : NULL;
 	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.53.0
author maintainer
#4 lore raw

PATCH 5/7 drm/amdgpu/mmhub3.0: add bounds checking for cid

In reply to Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v3_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_0.c +2 -1
index 7d5242df58a51..ab966e69a342a 100644
@@ -110,7 +110,8 @@ mmhub_v3_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
 	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
 	case IP_VERSION(3, 0, 0):
 	case IP_VERSION(3, 0, 1):
-		mmhub_cid = mmhub_client_ids_v3_0_0[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v3_0_0) ?
+			mmhub_client_ids_v3_0_0[cid][rw] : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
Signature · 1 line
2.53.0
author maintainer
#5 lore raw

PATCH 6/7 drm/amdgpu/mmhub4.1.0: add bounds checking for cid

In reply to Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v4_1_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v4_1_0.c +2 -1
index 951998454b257..88bfe321f83aa 100644
@@ -102,7 +102,8 @@ mmhub_v4_1_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
 		status);
 	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
 	case IP_VERSION(4, 1, 0):
-		mmhub_cid = mmhub_client_ids_v4_1_0[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v4_1_0) ?
+			mmhub_client_ids_v4_1_0[cid][rw] : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
Signature · 1 line
2.53.0
author maintainer
#6 lore raw

PATCH 7/7 drm/amdgpu/mmhub4.2.0: add bounds checking for cid

In reply to Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
 drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v4_2_0.c +2 -1
index a72770e3d0e99..2532ca80f7356 100644
@@ -688,7 +688,8 @@ mmhub_v4_2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
 		status);
 	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
 	case IP_VERSION(4, 2, 0):
-		mmhub_cid = mmhub_client_ids_v4_2_0[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_v4_2_0) ?
+			mmhub_client_ids_v4_2_0[cid][rw] : NULL;
 		break;
 	default:
 		mmhub_cid = NULL;
Signature · 1 line
2.53.0
#7 lore raw
In reply to Alex Deucher
Quoted 14 lines · Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +0 -0
index a0cc8e218ca1e..534cb4c544dc4 100644

drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev, · line 157

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +1 -1
@@ -154,14 +154,17 @@ mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
  	switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
  	case IP_VERSION(2, 0, 0):
  	case IP_VERSION(2, 0, 2):
-		mmhub_cid = mmhub_client_ids_navi1x[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_navi1x) ?

Does this introduce speculation and requirement to use array_index_nospec?

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +5 -2
+			mmhub_client_ids_navi1x[cid][rw] : NULL;
  		break;
  	case IP_VERSION(2, 1, 0):
  	case IP_VERSION(2, 1, 1):
-		mmhub_cid = mmhub_client_ids_sienna_cichlid[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_sienna_cichlid) ?
+			mmhub_client_ids_sienna_cichlid[cid][rw] : NULL;
  		break;
  	case IP_VERSION(2, 1, 2):
-		mmhub_cid = mmhub_client_ids_beige_goby[cid][rw];
+		mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_beige_goby) ?
+			mmhub_client_ids_beige_goby[cid][rw] : NULL;
  		break;
  	default:
  		mmhub_cid = NULL;
#8 lore raw
Quoted 13 lines · Lijo
Quoted 9 lines · Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev, · line 157

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +1 -1
index a0cc8e218ca1e..534cb4c544dc4 100644
@@ -154,14 +154,17 @@ mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
      switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
      case IP_VERSION(2, 0, 0):
      case IP_VERSION(2, 0, 2):
-             mmhub_cid = mmhub_client_ids_navi1x[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_navi1x) ?

Does this introduce speculation and requirement to use array_index_nospec?

I don't think so, but I'm not really an expert on side channel attacks.

Alex

Quoted 20 lines

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +5 -2
+                     mmhub_client_ids_navi1x[cid][rw] : NULL;
              break;
      case IP_VERSION(2, 1, 0):
      case IP_VERSION(2, 1, 1):
-             mmhub_cid = mmhub_client_ids_sienna_cichlid[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_sienna_cichlid) ?
+                     mmhub_client_ids_sienna_cichlid[cid][rw] : NULL;
              break;
      case IP_VERSION(2, 1, 2):
-             mmhub_cid = mmhub_client_ids_beige_goby[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_beige_goby) ?
+                     mmhub_client_ids_beige_goby[cid][rw] : NULL;
              break;
      default:
              mmhub_cid = NULL;
#9 lore raw

Ping on this series.

Alex

Quoted 52 lines · Alex Deucher
Quoted 13 lines · Lijo
Quoted 9 lines · Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 12 lines

drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev, · line 157

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +1 -1
index a0cc8e218ca1e..534cb4c544dc4 100644
@@ -154,14 +154,17 @@ mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
      switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
      case IP_VERSION(2, 0, 0):
      case IP_VERSION(2, 0, 2):
-             mmhub_cid = mmhub_client_ids_navi1x[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_navi1x) ?

Does this introduce speculation and requirement to use array_index_nospec?

I don't think so, but I'm not really an expert on side channel attacks.

Alex

Quoted 20 lines

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +5 -2
+                     mmhub_client_ids_navi1x[cid][rw] : NULL;
              break;
      case IP_VERSION(2, 1, 0):
      case IP_VERSION(2, 1, 1):
-             mmhub_cid = mmhub_client_ids_sienna_cichlid[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_sienna_cichlid) ?
+                     mmhub_client_ids_sienna_cichlid[cid][rw] : NULL;
              break;
      case IP_VERSION(2, 1, 2):
-             mmhub_cid = mmhub_client_ids_beige_goby[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_beige_goby) ?
+                     mmhub_client_ids_beige_goby[cid][rw] : NULL;
              break;
      default:
              mmhub_cid = NULL;
Reviewed-by
#10 lore raw
In reply to Alex Deucher
Quoted 24 lines · Alex Deucher
Quoted 12 lines · Lijo
Quoted 9 lines · Alex Deucher

The value should never exceed the array size as those are the only values the hardware is expected to return, but add checks anyway.

---
  drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c | 9 ++++++---
  1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev, · line 157

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +1 -1
index a0cc8e218ca1e..534cb4c544dc4 100644
@@ -154,14 +154,17 @@ mmhub_v2_0_print_l2_protection_fault_status(struct amdgpu_device *adev,
      switch (amdgpu_ip_version(adev, MMHUB_HWIP, 0)) {
      case IP_VERSION(2, 0, 0):
      case IP_VERSION(2, 0, 2):
-             mmhub_cid = mmhub_client_ids_navi1x[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_navi1x) ?

Does this introduce speculation and requirement to use array_index_nospec?

Quoted 3 lines

I don't think so, but I'm not really an expert on side channel attacks.

Alex

Also not an expert here but I don't think this can be used as an exploit. The cid is read from HW and is not controllable by users.

This series is:

Quoted 19 lines
Quoted 19 lines

Thanks,
Lijo

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/mmhub_v2_0.c +5 -2
+                     mmhub_client_ids_navi1x[cid][rw] : NULL;
              break;
      case IP_VERSION(2, 1, 0):
      case IP_VERSION(2, 1, 1):
-             mmhub_cid = mmhub_client_ids_sienna_cichlid[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_sienna_cichlid) ?
+                     mmhub_client_ids_sienna_cichlid[cid][rw] : NULL;
              break;
      case IP_VERSION(2, 1, 2):
-             mmhub_cid = mmhub_client_ids_beige_goby[cid][rw];
+             mmhub_cid = cid < ARRAY_SIZE(mmhub_client_ids_beige_goby) ?
+                     mmhub_client_ids_beige_goby[cid][rw] : NULL;
              break;
      default:
              mmhub_cid = NULL;