]> Git Repo - linux.git/commitdiff
drm/i915: Sanity check mmap length against object size
authorChris Wilson <[email protected]>
Thu, 14 Mar 2019 07:58:29 +0000 (07:58 +0000)
committerRodrigo Vivi <[email protected]>
Mon, 18 Mar 2019 20:59:42 +0000 (13:59 -0700)
We assumed that vm_mmap() would reject an attempt to mmap past the end of
the filp (our object), but we were wrong.

Applications that tried to use the mmap beyond the end of the object
would be greeted by a SIGBUS. After this patch, those applications will
be told about the error on creating the mmap, rather than at a random
moment on later access.

Reported-by: Antonio Argenziano <[email protected]>
Testcase: igt/gem_mmap/bad-size
Signed-off-by: Chris Wilson <[email protected]>
Cc: Antonio Argenziano <[email protected]>
Cc: Joonas Lahtinen <[email protected]>
Cc: Tvrtko Ursulin <[email protected]>
Cc: [email protected]
Reviewed-by: Tvrtko Ursulin <[email protected]>
Reviewed-by: Joonas Lahtinen <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
(cherry picked from commit 794a11cb67201ad1bb61af510bb8460280feb3f3)
Signed-off-by: Rodrigo Vivi <[email protected]>
drivers/gpu/drm/i915/i915_gem.c

index 30d516e975c64697b2b45019ba747c6251b7ecf1..8558e81fdc2af85dd52486b7c8d55580fe997373 100644 (file)
@@ -1734,8 +1734,13 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
         * pages from.
         */
        if (!obj->base.filp) {
-               i915_gem_object_put(obj);
-               return -ENXIO;
+               addr = -ENXIO;
+               goto err;
+       }
+
+       if (range_overflows(args->offset, args->size, (u64)obj->base.size)) {
+               addr = -EINVAL;
+               goto err;
        }
 
        addr = vm_mmap(obj->base.filp, 0, args->size,
@@ -1749,8 +1754,8 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
                struct vm_area_struct *vma;
 
                if (down_write_killable(&mm->mmap_sem)) {
-                       i915_gem_object_put(obj);
-                       return -EINTR;
+                       addr = -EINTR;
+                       goto err;
                }
                vma = find_vma(mm, addr);
                if (vma && __vma_matches(vma, obj->base.filp, addr, args->size))
@@ -1768,12 +1773,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
        i915_gem_object_put(obj);
 
        args->addr_ptr = (u64)addr;
-
        return 0;
 
 err:
        i915_gem_object_put(obj);
-
        return addr;
 }
 
This page took 0.062304 seconds and 4 git commands to generate.