3a02752
From:       Vladis Dronov <vdronov@redhat.com>
3a02752
Subject:    [PATCH] drm/vmwgfx: Check check that number of mip levels is above zero in vmw_surface_define_ioctl()
3a02752
Date:       2017-03-24 15:37:10
3a02752
3a02752
In vmw_surface_define_ioctl(), a num_sizes parameter is assigned a
3a02752
user-controlled value which is not checked for zero. It is used in
3a02752
a call to kmalloc() which returns ZERO_SIZE_PTR. Later ZERO_SIZE_PTR
3a02752
is dereferenced which leads to a GPF and possibly to a kernel panic.
3a02752
Add the check for zero to avoid this.
3a02752
3a02752
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1435719
3a02752
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
3a02752
---
3a02752
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 4 ++--
3a02752
 1 file changed, 2 insertions(+), 2 deletions(-)
3a02752
3a02752
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
3a02752
index b445ce9..42840cc 100644
3a02752
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
3a02752
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c
3a02752
@@ -716,8 +716,8 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
3a02752
 	for (i = 0; i < DRM_VMW_MAX_SURFACE_FACES; ++i)
3a02752
 		num_sizes += req->mip_levels[i];
3a02752
 
3a02752
-	if (num_sizes > DRM_VMW_MAX_SURFACE_FACES *
3a02752
-	    DRM_VMW_MAX_MIP_LEVELS)
3a02752
+	if (num_sizes <= 0 ||
3a02752
+	    num_sizes > DRM_VMW_MAX_SURFACE_FACES * DRM_VMW_MAX_MIP_LEVELS)
3a02752
 		return -EINVAL;
3a02752
 
3a02752
 	size = vmw_user_surface_size + 128 +
3a02752
-- 
3a02752
2.9.3