]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
drm: integer overflow in drm_mode_dirtyfb_ioctl()
authorXi Wang <xi.wang@gmail.com>
Wed, 23 Nov 2011 06:12:01 +0000 (01:12 -0500)
committerPaul Gortmaker <paul.gortmaker@windriver.com>
Fri, 17 Aug 2012 19:34:59 +0000 (15:34 -0400)
commit a5cd335165e31db9dbab636fd29895d41da55dd2 upstream.

There is a potential integer overflow in drm_mode_dirtyfb_ioctl()
if userspace passes in a large num_clips.  The call to kmalloc would
allocate a small buffer, and the call to fb->funcs->dirty may result
in a memory corruption.

Reported-by: Haogang Chen <haogangchen@gmail.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
drivers/gpu/drm/drm_crtc.c
include/drm/drm_mode.h

index 1a224f83a2d81a1523cfdbd73bb60f5208218bd3..819d0dc4f2fada09eba8e8ec98341d55bf05a911 100644 (file)
@@ -1833,6 +1833,10 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
        }
 
        if (num_clips && clips_ptr) {
+               if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
+                       ret = -EINVAL;
+                       goto out_err1;
+               }
                clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
                if (!clips) {
                        ret = -ENOMEM;
index c5ba1636613c0baac637fb169b28a17fb6a08aa0..9cf639cb2f86af1110e98c85b418e814f735edc9 100644 (file)
@@ -232,6 +232,8 @@ struct drm_mode_fb_cmd {
 #define DRM_MODE_FB_DIRTY_ANNOTATE_FILL 0x02
 #define DRM_MODE_FB_DIRTY_FLAGS         0x03
 
+#define DRM_MODE_FB_DIRTY_MAX_CLIPS     256
+
 /*
  * Mark a region of a framebuffer as dirty.
  *