Skip to content

Commit 794a11c

Browse files
committed
drm/i915: Sanity check mmap length against object size
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 <antonio.argenziano@intel.com> Testcase: igt/gem_mmap/bad-size Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Antonio Argenziano <antonio.argenziano@intel.com> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Cc: stable@vger.kernel.org Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20190314075829.16838-1-chris@chris-wilson.co.uk
1 parent 535d8d2 commit 794a11c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

drivers/gpu/drm/i915/i915_gem.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,13 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
16391639
* pages from.
16401640
*/
16411641
if (!obj->base.filp) {
1642-
i915_gem_object_put(obj);
1643-
return -ENXIO;
1642+
addr = -ENXIO;
1643+
goto err;
1644+
}
1645+
1646+
if (range_overflows(args->offset, args->size, (u64)obj->base.size)) {
1647+
addr = -EINVAL;
1648+
goto err;
16441649
}
16451650

16461651
addr = vm_mmap(obj->base.filp, 0, args->size,
@@ -1654,8 +1659,8 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
16541659
struct vm_area_struct *vma;
16551660

16561661
if (down_write_killable(&mm->mmap_sem)) {
1657-
i915_gem_object_put(obj);
1658-
return -EINTR;
1662+
addr = -EINTR;
1663+
goto err;
16591664
}
16601665
vma = find_vma(mm, addr);
16611666
if (vma && __vma_matches(vma, obj->base.filp, addr, args->size))
@@ -1673,12 +1678,10 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data,
16731678
i915_gem_object_put(obj);
16741679

16751680
args->addr_ptr = (u64)addr;
1676-
16771681
return 0;
16781682

16791683
err:
16801684
i915_gem_object_put(obj);
1681-
16821685
return addr;
16831686
}
16841687

0 commit comments

Comments
 (0)