Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Fix integer overflow tests
@ 2017-08-17  6:23 Dan Carpenter
  2017-08-17  6:42 ` ✓ Fi.CI.BAT: success for " Patchwork
                   ` (5 more replies)
  0 siblings, 6 replies; 15+ messages in thread
From: Dan Carpenter @ 2017-08-17  6:23 UTC (permalink / raw)
  To: Daniel Vetter, Jason Ekstrand, Chris Wilson
  Cc: David Airlie, intel-gfx, kernel-janitors, dri-devel

There are some potential integer overflows here on 64 bit systems.

The condition "if (nfences > SIZE_MAX / sizeof(*fences))" can only be
true on 32 bit systems, it's a no-op on 64 bit, so let's ignore the
check for now and look a couple lines after:

	if (!access_ok(VERIFY_READ, user, nfences * 2 * sizeof(u32)))
                                          ^^^^^^^^^^^
"nfences" is an unsigned int, so if we set it to UINT_MAX and multiply
by two, it's going to have an integer overflow.  The "args->buffer_count"
is also an unsigned int so it could overflow if it's set to UINT_MAX
when we do:

	exec2_list = kvmalloc_array(args->buffer_count + 1, sz,
                                    ^^^^^^^^^^^^^^^^^^^^^^
Fixes: 2889caa92321 ("drm/i915: Eliminate lots of iterations over the execobjects array")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 15ab3e6792f9..f569721aad1a 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -2152,7 +2152,7 @@ get_fence_array(struct drm_i915_gem_execbuffer2 *args,
 	if (!(args->flags & I915_EXEC_FENCE_ARRAY))
 		return NULL;
 
-	if (nfences > SIZE_MAX / sizeof(*fences))
+	if (nfences > UINT_MAX / sizeof(*fences))
 		return ERR_PTR(-EINVAL);
 
 	user = u64_to_user_ptr(args->cliprects_ptr);
@@ -2520,7 +2520,7 @@ i915_gem_execbuffer(struct drm_device *dev, void *data,
 	unsigned int i;
 	int err;
 
-	if (args->buffer_count < 1 || args->buffer_count > SIZE_MAX / sz - 1) {
+	if (args->buffer_count < 1 || args->buffer_count > UINT_MAX / sz - 1) {
 		DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count);
 		return -EINVAL;
 	}
@@ -2609,7 +2609,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
 	struct drm_syncobj **fences = NULL;
 	int err;
 
-	if (args->buffer_count < 1 || args->buffer_count > SIZE_MAX / sz - 1) {
+	if (args->buffer_count < 1 || args->buffer_count > UINT_MAX / sz - 1) {
 		DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count);
 		return -EINVAL;
 	}
_______________________________________________
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:[~2017-08-18  8:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-17  6:23 [PATCH] drm/i915: Fix integer overflow tests Dan Carpenter
2017-08-17  6:42 ` ✓ Fi.CI.BAT: success for " Patchwork
2017-08-17  9:37 ` [PATCH] " Imre Deak
2017-08-17  9:50   ` Dan Carpenter
2017-08-17  9:56     ` Imre Deak
2017-08-17 14:16       ` Jason Ekstrand
2017-08-17 14:32         ` Dan Carpenter
2017-08-18  7:07         ` [PATCH v2] " Dan Carpenter
2017-08-18  7:46           ` Chris Wilson
2017-08-18  8:01             ` Dan Carpenter
2017-08-17 10:00 ` [PATCH] drm/i915: Prevent overflow of execbuf.buffer_count and num_cliprects Chris Wilson
2017-08-17 10:36   ` [PATCH v2] " Chris Wilson
2017-08-17 10:26 ` ✓ Fi.CI.BAT: success for drm/i915: Fix integer overflow tests (rev2) Patchwork
2017-08-17 11:00 ` ✓ Fi.CI.BAT: success for drm/i915: Fix integer overflow tests (rev3) Patchwork
2017-08-18  7:40 ` ✓ Fi.CI.BAT: success for drm/i915: Fix integer overflow tests (rev4) Patchwork

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