Skip to contentSkip to conversation

drm/i915: bounds check execbuffer relocation count

PATCH Applied Kees Cook 5 participants 6 messages Mar 12, 2013 – Mar 15, 2013

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH v3 1/1 drm/i915: bounds check execbuffer relocation count

It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows.

CVE-2013-0913

v3: collapse test, improve comment
v2: move check into validate_exec_list

Reported-by Pinkie Pie
---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/i915_gem_execbuffer.c +8 -3
index b3a40ee..094ba41 100644
@@ -732,6 +732,8 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
 		   int count)
 {
 	int i;
+	int relocs_total = 0;
+	int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
 
 	for (i = 0; i < count; i++) {
 		char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
@@ -740,10 +742,13 @@ validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
 		if (exec[i].flags & __EXEC_OBJECT_UNKNOWN_FLAGS)
 			return -EINVAL;
 
-		/* First check for malicious input causing overflow */
-		if (exec[i].relocation_count >
-		    INT_MAX / sizeof(struct drm_i915_gem_relocation_entry))
+		/* First check for malicious input causing overflow in
+		 * the worst case where we need to allocate the entire
+		 * relocation tree as a single array.
+		 */
+		if (exec[i].relocation_count > relocs_max - relocs_total)
 			return -EINVAL;
+		relocs_total += exec[i].relocation_count;
 
 		length = exec[i].relocation_count *
 			sizeof(struct drm_i915_gem_relocation_entry);
Signature · 6 lines
1.7.9.5


-- 
Kees Cook
Chrome OS Security
Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Kees Cook

It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows.

CVE-2013-0913

v3: collapse test, improve comment
v2: move check into validate_exec_list

Reported-by Pinkie Pie

Looks good to me. The only bikeshed that remains is whether we should just collapse the two variables into one, but the current 'max - count' is more idiomatic and so preferrable.

-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#2 lore raw
Quoted 9 lines · Chris Wilson
Quoted 8 lines · Kees Cook

It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows.

CVE-2013-0913

v3: collapse test, improve comment
v2: move check into validate_exec_list

Quoted 8 lines
Quoted 3 lines
Reported-by Pinkie Pie

Looks good to me. The only bikeshed that remains is whether we should just collapse the two variables into one, but the current 'max - count' is more idiomatic and so preferrable.

Picked up for -fixes, thanks for the patch.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#3 lore raw
Quoted 14 lines · Daniel Vetter
Quoted 13 lines · Chris Wilson
Quoted 11 lines · Kees Cook

It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows.

CVE-2013-0913

v3: collapse test, improve comment
v2: move check into validate_exec_list

Reported-by Pinkie Pie
Quoted 6 lines
Quoted 4 lines

Looks good to me. The only bikeshed that remains is whether we should just collapse the two variables into one, but the current 'max - count' is more idiomatic and so preferrable.

Picked up for -fixes, thanks for the patch.

I've forgotten to dump my wishlist: Can I have an i-g-t for this? For this bug here specifically an execbuf with just one buffer with too many relocs plus another execbuf with two buffers with relocation so that the 2nd relocation list will overflow should be sufficient.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#4 lore raw
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Daniel Vetter
Quoted 17 lines · Chris Wilson
Quoted 11 lines · Kees Cook

It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows.

CVE-2013-0913

v3: collapse test, improve comment
v2: move check into validate_exec_list

Reported-by Pinkie Pie

Looks good to me. The only bikeshed that remains is whether we should just collapse the two variables into one, but the current 'max - count' is more idiomatic and so preferrable.

Quoted 6 lines
Quoted 1 line

Picked up for -fixes, thanks for the patch.

I've forgotten to dump my wishlist: Can I have an i-g-t for this? For this bug here specifically an execbuf with just one buffer with too many relocs plus another execbuf with two buffers with relocation so that the 2nd relocation list will overflow should be sufficient.

Sure thing. Where do these live? (Or what docs should I read for this?) I'm assuming i-g-t means "intel graphics test"? :)

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
#5 lore raw
Quoted 23 lines · Kees Cook
Quoted 22 lines · Daniel Vetter
Quoted 20 lines · Daniel Vetter
Quoted 9 lines · Chris Wilson
Quoted 8 lines · Kees Cook

It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows.

CVE-2013-0913

v3: collapse test, improve comment
v2: move check into validate_exec_list

Quoted 8 lines
Quoted 3 lines
Reported-by Pinkie Pie

Looks good to me. The only bikeshed that remains is whether we should just collapse the two variables into one, but the current 'max - count' is more idiomatic and so preferrable.

Picked up for -fixes, thanks for the patch.

Quoted 7 lines
Quoted 4 lines

I've forgotten to dump my wishlist: Can I have an i-g-t for this? For this bug here specifically an execbuf with just one buffer with too many relocs plus another execbuf with two buffers with relocation so that the 2nd relocation list will overflow should be sufficient.

Sure thing. Where do these live? (Or what docs should I read for this?) I'm assuming i-g-t means "intel graphics test"? :)

Close :) GPU Tools. The tests lives in the tests directory of:
http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/

Signature · 1 line
Damien