From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Cc: stable@vger.kernel.org
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Sanity check mmap length against object size
Date: Thu, 14 Mar 2019 11:33:43 +0000 [thread overview]
Message-ID: <5572a2bf-1398-04e9-e681-5f7d4e8b9df9@linux.intel.com> (raw)
In-Reply-To: <20190314075829.16838-1-chris@chris-wilson.co.uk>
On 14/03/2019 07:58, Chris Wilson wrote:
> We assumed that vm_mmap() would reject an attempt to mmap past the end of
> the filp (our object), but we were wrong.
>
> 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
> ---
> drivers/gpu/drm/i915/i915_gem.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
> index b38c9531b5e8..b7086c8d4726 100644
> --- a/drivers/gpu/drm/i915/i915_gem.c
> +++ b/drivers/gpu/drm/i915/i915_gem.c
> @@ -1639,8 +1639,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,
> @@ -1654,8 +1659,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))
> @@ -1673,12 +1678,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;
> }
>
>
Patch is good, and certainly for our use cases we can afford to check at
this level.
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
I am only wondering what happens to reads/write to the trailing area?
Does shmemfs expands the backing store for this mmap and we just end up
with otherwise unused chunk at the end?
Regards,
Tvrtko
next prev parent reply other threads:[~2019-03-14 11:33 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 7:58 [PATCH] drm/i915: Sanity check mmap length against object size Chris Wilson
2019-03-14 8:43 ` ✓ Fi.CI.BAT: success for " Patchwork
2019-03-14 11:33 ` Tvrtko Ursulin [this message]
2019-03-14 11:44 ` [Intel-gfx] [PATCH] " Chris Wilson
2019-03-18 12:10 ` Chris Wilson
2019-03-18 12:16 ` Chris Wilson
2019-03-14 17:41 ` ✗ Fi.CI.IGT: failure for " Patchwork
2019-03-15 18:24 ` ✓ Fi.CI.BAT: success for drm/i915: Sanity check mmap length against object size (rev2) Patchwork
2019-03-15 20:44 ` ✓ Fi.CI.IGT: " Patchwork
2019-03-18 12:17 ` [PATCH] drm/i915: Sanity check mmap length against object size Chris Wilson
2019-03-18 12:55 ` Joonas Lahtinen
2019-03-18 12:55 ` Joonas Lahtinen
2019-03-25 0:38 ` Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5572a2bf-1398-04e9-e681-5f7d4e8b9df9@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=intel-gfx@lists.freedesktop.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.