All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Subject: [Intel-gfx] [PATCH v2] drm/i915/gt: Validate rotated vma bounds are within the object
Date: Fri, 10 Jan 2020 15:53:34 +0000	[thread overview]
Message-ID: <20200110155334.1417942-1-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <20200109141152.975687-1-chris@chris-wilson.co.uk>

Quite understandably, we bug out when asked to find a page that doesn't
belong to the object. However, we should report the error back to the
user long before we attempt the out-of-bound access! In this case, it is
insufficient validation on the rotated vma, with the simplest/cheapest
point for us to insert a bound check when we are computing the rotated
page lookups.

Similarly, it might be wise to see if we can validate the user input
upon creating the rotated framebuffer.

v2: Skip empty planes

Closes: https://gitlab.freedesktop.org/drm/intel/issues/951
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Matthew Auld <matthew.auld@intel.com
---
 drivers/gpu/drm/i915/gt/intel_ggtt.c      | 25 +++++++++++++++++++----
 drivers/gpu/drm/i915/selftests/i915_vma.c |  1 +
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/intel_ggtt.c b/drivers/gpu/drm/i915/gt/intel_ggtt.c
index 79096722ce16..4a646d74327a 100644
--- a/drivers/gpu/drm/i915/gt/intel_ggtt.c
+++ b/drivers/gpu/drm/i915/gt/intel_ggtt.c
@@ -1266,6 +1266,7 @@ static noinline struct sg_table *
 intel_rotate_pages(struct intel_rotation_info *rot_info,
 		   struct drm_i915_gem_object *obj)
 {
+	const unsigned long npages = obj->base.size >> PAGE_SHIFT;
 	unsigned int size = intel_rotation_info_size(rot_info);
 	struct sg_table *st;
 	struct scatterlist *sg;
@@ -1285,9 +1286,26 @@ intel_rotate_pages(struct intel_rotation_info *rot_info,
 	sg = st->sgl;
 
 	for (i = 0 ; i < ARRAY_SIZE(rot_info->plane); i++) {
-		sg = rotate_pages(obj, rot_info->plane[i].offset,
-				  rot_info->plane[i].width, rot_info->plane[i].height,
-				  rot_info->plane[i].stride, st, sg);
+		const struct intel_remapped_plane_info *plane =
+			&rot_info->plane[i];
+		unsigned long last;
+
+		if (!plane->height || !plane->width)
+			continue;
+
+		last = plane->offset;
+		last += (plane->height - 1) * plane->stride;
+		last += plane->width - 1;
+		if (last >= npages) {
+			ret = -EINVAL;
+			goto err_sg_alloc;
+		}
+
+		sg = rotate_pages(obj,
+				  plane->offset,
+				  plane->width, plane->height,
+				  plane->stride,
+				  st, sg);
 	}
 
 	return st;
@@ -1295,7 +1313,6 @@ intel_rotate_pages(struct intel_rotation_info *rot_info,
 err_sg_alloc:
 	kfree(st);
 err_st_alloc:
-
 	DRM_DEBUG_DRIVER("Failed to create rotated mapping for object size %zu! (%ux%u tiles, %u pages)\n",
 			 obj->base.size, rot_info->plane[0].width, rot_info->plane[0].height, size);
 
diff --git a/drivers/gpu/drm/i915/selftests/i915_vma.c b/drivers/gpu/drm/i915/selftests/i915_vma.c
index 58b5f40a07dd..24e7806867ef 100644
--- a/drivers/gpu/drm/i915/selftests/i915_vma.c
+++ b/drivers/gpu/drm/i915/selftests/i915_vma.c
@@ -962,6 +962,7 @@ static int igt_vma_remapped_gtt(void *arg)
 						       *t == I915_GGTT_VIEW_ROTATED ? "Rotated" : "Remapped",
 						       val, exp);
 						i915_vma_unpin_iomap(vma);
+						err = -EINVAL;
 						goto out;
 					}
 				}
-- 
2.25.0.rc2

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2020-01-10 15:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 14:11 [Intel-gfx] [PATCH] drm/i915/gt: Validation rotated vma bounds are within the object Chris Wilson
2020-01-09 14:52 ` Ville Syrjälä
2020-01-09 18:37   ` Ville Syrjälä
2020-01-09 19:01     ` Ville Syrjälä
2020-01-09 23:28 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2020-01-09 23:53 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2020-01-10 15:53 ` Chris Wilson [this message]
2020-01-10 15:57   ` [Intel-gfx] [PATCH v2] drm/i915/gt: Validate " Chris Wilson
2020-01-10 20:21 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/gt: Validation rotated vma bounds are within the object (rev2) Patchwork
2020-01-10 20:51 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2020-01-14 14:41 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork

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=20200110155334.1417942-1-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.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.