Skip to contentSkip to conversation

drm/amdgpu/vce: fix integer overflow in image size

PATCH In review [email protected] 2 participants 2 messages May 26 – May 27

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

PATCH 1/1 drm/amdgpu/vce: fix integer overflow in image size

From: Boyuan Zhang <[email protected]>

Fix a security vulnerability where malicious VCE command streams with oversized dimensions (e.g. 65536×65536) cause 32-bit integer overflow, wrapping the calculated buffer size to 0. This bypasses validation and allows GPU firmware to perform out-of-bound memory access.

The fix uses 64-bit arithmetic to detect overflow and rejects invalid dimensions before they reach the hardware.
V2: remove redundant check
V3: modify max height value

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +15 -3
index efdebd9c0a1f..bf7184dc7c7c 100644
@@ -877,9 +877,21 @@ 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;
+			uint32_t width = amdgpu_ib_get_value(ib, idx + 8);
+			uint32_t height = amdgpu_ib_get_value(ib, idx + 10);
+			uint64_t size64;
+
+			if (width == 0 || height == 0 ||
+			    width > 4096 || height > 2304) {
+				DRM_ERROR("invalid VCE image size: %ux%u\n",
+					  width, height);
+				r = -EINVAL;
+				goto out;
+			}
+
+			size64 = (uint64_t)width * (uint64_t)height * 12ULL;
+			*size = (uint32_t)size64;
+
 			break;
 
 		case 0x04000001: /* config extension */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 32 lines · On 2026-05-26 12:32, [email protected] wrote:

From: Boyuan Zhang <[email protected]>

Fix a security vulnerability where malicious VCE command streams with oversized dimensions (e.g. 65536×65536) cause 32-bit integer overflow, wrapping the calculated buffer size to 0. This bypasses validation and allows GPU firmware to perform out-of-bound memory access.

The fix uses 64-bit arithmetic to detect overflow and rejects invalid dimensions before they reach the hardware.
V2: remove redundant check
V3: modify max height value

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +3 -3
index efdebd9c0a1f..bf7184dc7c7c 100644
@@ -877,9 +877,21 @@ 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;
+			uint32_t width = amdgpu_ib_get_value(ib, idx + 8);
+			uint32_t height = amdgpu_ib_get_value(ib, idx + 10);
+			uint64_t size64;

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, · line 892

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +10 -0
+
+			if (width == 0 || height == 0 ||
+			    width > 4096 || height > 2304) {
+				DRM_ERROR("invalid VCE image size: %ux%u\n",
+					  width, height);
+				r = -EINVAL;
+				goto out;
+			}
+
+			size64 = (uint64_t)width * (uint64_t)height * 12ULL;

There is no need for size64 since width * height * 12 is now guaranteed to never overflow.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +2 -0
+			*size = (uint32_t)size64;
+
 			break;
 
 		case 0x04000001: /* config extension */