Skip to contentSkip to conversation

drm/amdgpu/vce: Add overflow checks for size

PATCH In review Benjamin Cheng 2 participants 2 messages May 20 – May 21

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

PATCH 1/1 drm/amdgpu/vce: Add overflow checks for size

Although VCE has HW limits much smaller than this and should fail without causing damage, prevent the overflow just in case.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +9 -3
index efdebd9c0a1f..d73be4d7eff2 100644
@@ -877,9 +877,15 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p,
 				goto out;
 			}
 
-			*size = amdgpu_ib_get_value(ib, idx + 8) *
-				amdgpu_ib_get_value(ib, idx + 10) *
-				8 * 3 / 2;
+			if (check_mul_overflow(amdgpu_ib_get_value(ib, idx + 8),
+					       amdgpu_ib_get_value(ib, idx + 10),
+					       &tmp) ||
+			    check_mul_overflow(tmp, 8 * 3 / 2, size)) {
+				DRM_ERROR("enc size overflow!\n");
+				r = -EINVAL;
+				goto out;
+			}
+
 			break;
 
 		case 0x04000001: /* config extension */
Signature · 1 line
2.54.0
Reviewed-by on v1 1/1
#1 lore raw

AMD General

Thanks,
Ruijing

-----Original Message-----
From: Benjamin Cheng <[email protected]>
Sent: Wednesday, May 20, 2026 7:36 PM
To: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: Wu, David <[email protected]>; Dong, Ruijing <[email protected]>; Liu, Leo <[email protected]>; Cheng, Benjamin <[email protected]>
Subject: [PATCH] drm/amdgpu/vce: Add overflow checks for size

Although VCE has HW limits much smaller than this and should fail without causing damage, prevent the overflow just in case.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +9 -3
index efdebd9c0a1f..d73be4d7eff2 100644
@@ -877,9 +877,15 @@ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p,
                                goto out;
                        }
 
-                       *size = amdgpu_ib_get_value(ib, idx + 8) *
-                               amdgpu_ib_get_value(ib, idx + 10) *
-                               8 * 3 / 2;
+                       if (check_mul_overflow(amdgpu_ib_get_value(ib, idx + 8),
+                                              amdgpu_ib_get_value(ib, idx + 10),
+                                              &tmp) ||
+                           check_mul_overflow(tmp, 8 * 3 / 2, size)) {
+                               DRM_ERROR("enc size overflow!\n");
+                               r = -EINVAL;
+                               goto out;
+                       }
+
                        break;
 
                case 0x04000001: /* config extension */

--
2.54.0