From patchwork Mon Mar 11 19:27:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 2250751 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 227E63FCF6 for ; Mon, 11 Mar 2013 20:30:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0500DE61DD for ; Mon, 11 Mar 2013 13:30:55 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.outflux.net (smtp.outflux.net [198.145.64.163]) by gabe.freedesktop.org (Postfix) with ESMTP id 34511E5CD3 for ; Mon, 11 Mar 2013 12:27:19 -0700 (PDT) Received: from www.outflux.net (serenity-end.outflux.net [10.2.0.2]) by vinyl.outflux.net (8.14.4/8.14.4/Debian-2ubuntu2) with ESMTP id r2BJRGHD008499; Mon, 11 Mar 2013 12:27:16 -0700 Date: Mon, 11 Mar 2013 12:27:16 -0700 From: Kees Cook To: linux-kernel@vger.kernel.org Subject: [PATCH] drm/i915: bounds check execbuffer relocations Message-ID: <20130311192716.GA18244@www.outflux.net> MIME-Version: 1.0 Content-Disposition: inline X-MIMEDefang-Filter: outflux$Revision: 1.316 $ X-HELO: www.outflux.net X-Scanned-By: MIMEDefang 2.71 on 10.2.0.1 X-Mailman-Approved-At: Mon, 11 Mar 2013 13:27:49 -0700 Cc: Daniel Vetter , dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org It is possible to wrap the counter used to allocate the buffer for relocation copies. This could lead to heap writing overflows. Signed-off-by: Kees Cook Reported-by: Pinkie Pie Cc: stable@vger.kernel.org --- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c index 752e399..62eaa99 100644 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c @@ -585,7 +585,8 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, struct drm_i915_gem_object *obj; bool need_relocs; int *reloc_offset; - int i, total, ret; + int ret; + unsigned int i, total; int count = args->buffer_count; /* We may process another execbuffer during the unlock... */ @@ -600,8 +601,13 @@ i915_gem_execbuffer_relocate_slow(struct drm_device *dev, mutex_unlock(&dev->struct_mutex); total = 0; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { + if (exec[i].relocation_count > UINT_MAX - total) { + mutex_lock(&dev->struct_mutex); + return -ENOMEM; + } total += exec[i].relocation_count; + } reloc_offset = drm_malloc_ab(count, sizeof(*reloc_offset)); reloc = drm_malloc_ab(total, sizeof(*reloc));