Skip to contentSkip to conversation

drm/i915/gvt/fb_decoder: Fix out-of-bounds read

PATCH Applied Gustavo A. R. Silva 2 participants 3 messages Dec 9, 2017 – Dec 12, 2017

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

PATCH 1/1 drm/i915/gvt/fb_decoder: Fix out-of-bounds read

In case function skl_format_to_drm returns -EINVAL, fmt turns into a huge number as fmt is of type u32, hence there is an out-of-bounds read when using fmt as an index for array skl_pixel_formats at line 225:
plane->bpp = skl_pixel_formats[fmt].bpp;

Fix this by comparing the value returned by function skl_format_to_drm against the size of array skl_pixel_formats, so in case it is greater than or equal to the number of items contained in skl_pixel_formats, print an error message and return -EINVAL.

Addresses-Coverity-ID: 1462495
Addresses-Coverity-ID: 1462502 ("Out-of-bounds read")

Fixes 9f31d1063b43 ("drm/i915/gvt: Add framebuffer decoder support")
---
 drivers/gpu/drm/i915/gvt/fb_decoder.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/gvt/fb_decoder.c +6 -0
index 72f4217..aed578b 100644
@@ -222,6 +222,12 @@ int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu,
 			val & PLANE_CTL_ORDER_RGBX,
 			val & PLANE_CTL_ALPHA_MASK,
 			val & PLANE_CTL_YUV422_ORDER_MASK);
+
+		if (fmt >= ARRAY_SIZE(skl_pixel_formats)) {
+			gvt_vgpu_err("Out-of-bounds pixel format index\n");
+			return -EINVAL;
+		}
+
 		plane->bpp = skl_pixel_formats[fmt].bpp;
 		plane->drm_format = skl_pixel_formats[fmt].drm_format;
 	} else {
Signature · 1 line
2.7.4
Applied
#1 lore raw
Quoted 26 lines · Gustavo A. R. Silva

In case function skl_format_to_drm returns -EINVAL, fmt turns into a huge number as fmt is of type u32, hence there is an out-of-bounds read when using fmt as an index for array skl_pixel_formats at line 225:
plane->bpp = skl_pixel_formats[fmt].bpp;

Fix this by comparing the value returned by function skl_format_to_drm against the size of array skl_pixel_formats, so in case it is greater than or equal to the number of items contained in skl_pixel_formats, print an error message and return -EINVAL.

Addresses-Coverity-ID: 1462495
Addresses-Coverity-ID: 1462502 ("Out-of-bounds read")

Fixes 9f31d1063b43 ("drm/i915/gvt: Add framebuffer decoder support")
---
 drivers/gpu/drm/i915/gvt/fb_decoder.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/gvt/fb_decoder.c +0 -0
index 72f4217..aed578b 100644
@@ -222,6 +222,12 @@ int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu,
 			val & PLANE_CTL_ORDER_RGBX,
 			val & PLANE_CTL_ALPHA_MASK,

drivers/gpu/drm/i915/gvt/fb_decoder.c int intel_vgpu_decode_primary_plane(struct intel_vgpu *vgpu, · line 233

Quoted 10 lines
drivers/gpu/drm/i915/gvt/fb_decoder.c +6 -0
 			val & PLANE_CTL_YUV422_ORDER_MASK);
+
+		if (fmt >= ARRAY_SIZE(skl_pixel_formats)) {
+			gvt_vgpu_err("Out-of-bounds pixel format index\n");
+			return -EINVAL;
+		}
+
 		plane->bpp = skl_pixel_formats[fmt].bpp;
 		plane->drm_format = skl_pixel_formats[fmt].drm_format;
 	} else {

Applied this, thanks!

Signature · 3 lines
Open Source Technology Center, Intel ltd.

$gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#2 lore raw

Hi Zhenyu,

Quoting Zhenyu Wang <[email protected]>:

Quoted 32 lines · Gustavo A. R. Silva
Quoted 31 lines

In case function skl_format_to_drm returns -EINVAL, fmt turns into a huge number as fmt is of type u32, hence there is an out-of-bounds read when using fmt as an index for array skl_pixel_formats at line 225:
plane->bpp = skl_pixel_formats[fmt].bpp;

Fix this by comparing the value returned by function skl_format_to_drm against the size of array skl_pixel_formats, so in case it is greater than or equal to the number of items contained in skl_pixel_formats, print an error message and return -EINVAL.

Addresses-Coverity-ID: 1462495
Addresses-Coverity-ID: 1462502 ("Out-of-bounds read")

Fixes 9f31d1063b43 ("drm/i915/gvt: Add framebuffer decoder support")
---
 drivers/gpu/drm/i915/gvt/fb_decoder.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/i915/gvt/fb_decoder.c +4 -0
index 72f4217..aed578b 100644
@@ -222,6 +222,12 @@ int intel_vgpu_decode_primary_plane(struct  
 intel_vgpu *vgpu,
 			val & PLANE_CTL_ORDER_RGBX,
 			val & PLANE_CTL_ALPHA_MASK,
 			val & PLANE_CTL_YUV422_ORDER_MASK);
+
+		if (fmt >= ARRAY_SIZE(skl_pixel_formats)) {
+			gvt_vgpu_err("Out-of-bounds pixel format index\n");
+			return -EINVAL;
Quoted 9 lines
Quoted 6 lines
drivers/gpu/drm/i915/gvt/fb_decoder.c +2 -0
+		}
+
 		plane->bpp = skl_pixel_formats[fmt].bpp;
 		plane->drm_format = skl_pixel_formats[fmt].drm_format;

} else {
--

Applied this, thanks!

Glad to help. :)

Thanks
--
Gustavo A. R. Silva