DragonFlyBSD Kernel Audit
DF-1595 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/dev/drm/amd/amdgpu/amdgpu_uvd.c b/sys/dev/drm/amd/amdgpu/amdgpu_uvd.c
--- a/sys/dev/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/sys/dev/drm/amd/amdgpu/amdgpu_uvd.c
@@ -528,6 +528,19 @@
 	unsigned image_size, tmp, min_dpb_size, num_dpb_buffer;
 	unsigned min_ctx_size = ~0;
 
+	/*
+	 * DF-1595: width/height come from user-controlled msg[6]/msg[7].
+	 * If either is < 16, width_in_mb or height_in_mb is 0 and fs_in_mb
+	 * is 0; the switch below computes `8100 / fs_in_mb` etc. and #DE
+	 * traps the kernel.  Reject before the switch (the existing
+	 * width > pitch check fires too late).
+	 */
+	if (!width || !height || width < 16 || height < 16 || !fs_in_mb) {
+		DRM_ERROR("Invalid UVD decoding target dimensions %dx%d!\\n",
+			  width, height);
+		return -EINVAL;
+	}
+
 	image_size = width * height;
 	image_size += image_size / 2;
 	image_size = ALIGN(image_size, 1024);