public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: add sanity check for partial view creation
@ 2016-02-29 17:11 Matthew Auld
  2016-02-29 17:25 ` ✗ Fi.CI.BAT: warning for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Matthew Auld @ 2016-02-29 17:11 UTC (permalink / raw)
  To: intel-gfx

When binding pages for a partial view we should check that the offset +
size is valid relative to the size of the gem object.

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 49e4f26..a477bb2 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -3500,6 +3500,10 @@ intel_partial_pages(const struct i915_ggtt_view *view,
 	struct sg_page_iter obj_sg_iter;
 	int ret = -ENOMEM;
 
+	if (view->params.partial.offset + view->params.partial.size >
+	    obj->pages->nents)
+		return ERR_PTR(-EINVAL);
+
 	st = kmalloc(sizeof(*st), GFP_KERNEL);
 	if (!st)
 		goto err_st_alloc;
-- 
2.4.3

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

^ permalink raw reply related	[flat|nested] 15+ messages in thread
* [PATCH] drm/i915: add sanity check for partial view creation
@ 2016-03-02 14:33 Matthew Auld
  2016-03-02 14:42 ` Chris Wilson
  0 siblings, 1 reply; 15+ messages in thread
From: Matthew Auld @ 2016-03-02 14:33 UTC (permalink / raw)
  To: intel-gfx

When binding pages for a partial view we should check that the offset +
size is valid relative to the size of the gem object.

v2: Don't use pages->nents to determine the page count (Tvrtko Ursulin)

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 7b8de85..2c49d043 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -3493,6 +3493,10 @@ intel_partial_pages(const struct i915_ggtt_view *view,
 	struct sg_page_iter obj_sg_iter;
 	int ret = -ENOMEM;
 
+	if (view->params.partial.offset + view->params.partial.size >
+	    obj->base.size >> PAGE_SHIFT)
+		return ERR_PTR(-EINVAL);
+
 	st = kmalloc(sizeof(*st), GFP_KERNEL);
 	if (!st)
 		goto err_st_alloc;
-- 
2.4.3

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

^ permalink raw reply related	[flat|nested] 15+ messages in thread
* [PATCH] drm/i915: add sanity check for partial view creation
@ 2016-03-04 10:11 Matthew Auld
  2016-03-04 10:53 ` Chris Wilson
  0 siblings, 1 reply; 15+ messages in thread
From: Matthew Auld @ 2016-03-04 10:11 UTC (permalink / raw)
  To: intel-gfx

When binding pages for a partial view we should check that the offset +
size is valid relative to the size of the gem object.

v2: Don't use pages->nents to determine the page count (Tvrtko Ursulin)
v3: Handle potential overflow (Chris Wilson)

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index 7b8de85..596692b 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -3493,6 +3493,13 @@ intel_partial_pages(const struct i915_ggtt_view *view,
 	struct sg_page_iter obj_sg_iter;
 	int ret = -ENOMEM;
 
+	if (U64_MAX - view->params.partial.offset < view->params.partial.size)
+		return ERR_PTR(-ERANGE);
+
+	if (view->params.partial.offset + view->params.partial.size >
+	    obj->base.size >> PAGE_SHIFT)
+		return ERR_PTR(-EINVAL);
+
 	st = kmalloc(sizeof(*st), GFP_KERNEL);
 	if (!st)
 		goto err_st_alloc;
-- 
2.4.3

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

^ permalink raw reply related	[flat|nested] 15+ messages in thread
* [PATCH] drm/i915: add sanity check for partial view creation
@ 2016-03-18 15:51 Matthew Auld
  0 siblings, 0 replies; 15+ messages in thread
From: Matthew Auld @ 2016-03-18 15:51 UTC (permalink / raw)
  To: intel-gfx

Upon creating a partial view we should check that the offset + size is
valid relative to the size of the gem object.

v2:
(Tvrtko Ursulin)
    - Don't use pages->nents to determine the page count
v3:
(Chris Wilson)
    - Handle potential overflow
v4:
(Chris Wilson)
    - Idiomatically handle overflow
    - Less idiotic placement
    - Treat as programmer error

Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_gem_gtt.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index fb0f963..593eb15 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -3356,6 +3356,14 @@ i915_gem_obj_lookup_or_create_ggtt_vma(struct drm_i915_gem_object *obj,
 	if (WARN_ON(!view))
 		return ERR_PTR(-EINVAL);
 
+	if (view->type == I915_GGTT_VIEW_PARTIAL) {
+		unsigned int page_count = obj->base.size >> PAGE_SHIFT;
+		if (WARN_ON(view->params.partial.offset > page_count ||
+			    view->params.partial.size > page_count  -
+			    view->params.partial.offset))
+			return ERR_PTR(-EINVAL);
+	}
+
 	vma = i915_gem_obj_to_ggtt_view(obj, view);
 
 	if (IS_ERR(vma))
-- 
2.4.3

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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-03-18 15:51 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-29 17:11 [PATCH] drm/i915: add sanity check for partial view creation Matthew Auld
2016-02-29 17:25 ` ✗ Fi.CI.BAT: warning for " Patchwork
2016-02-29 17:57 ` [PATCH] " Ville Syrjälä
2016-03-02 13:37   ` Joonas Lahtinen
2016-03-02 13:29 ` Joonas Lahtinen
2016-03-02 13:35   ` Chris Wilson
2016-03-02 13:33 ` Tvrtko Ursulin
  -- strict thread matches above, loose matches on Subject: below --
2016-03-02 14:33 Matthew Auld
2016-03-02 14:42 ` Chris Wilson
2016-03-03 11:27   ` Auld, Matthew
2016-03-03 11:45     ` Chris Wilson
2016-03-04 10:11 Matthew Auld
2016-03-04 10:53 ` Chris Wilson
2016-03-09 18:31   ` Matthew Auld
2016-03-18 15:51 Matthew Auld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox