From: Daniel Vetter Subject: [PATCH] drm/i915: fix reference counting in i915_gem_create Date: Wed, 24 Jul 2013 14:02:20 +0200 Message-ID: <1374667340-7786-1-git-send-email-daniel.vetter@ffwll.ch> References: <1374663659-3073-1-git-send-email-daniel.vetter@ffwll.ch> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) by gabe.freedesktop.org (Postfix) with ESMTP id 6669DE6A07 for ; Wed, 24 Jul 2013 06:17:49 -0700 (PDT) Received: by mail-ee0-f53.google.com with SMTP id e53so236366eek.26 for ; Wed, 24 Jul 2013 06:17:48 -0700 (PDT) In-Reply-To: <1374663659-3073-1-git-send-email-daniel.vetter@ffwll.ch> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: Intel Graphics Development Cc: Daniel Vetter List-Id: intel-gfx@lists.freedesktop.org This function is called without the dev->struct_mutex held, hence we need to use the _unlocked unreference variants. As soon as the object is registered userspace can sneak in here with a gem_close ioctl call, so the object can (and with my new evil tests actually does) get the final unreference in this place. The lack of locking then results in hilarity and some good leakage. v2: We need to make the trace call _before_ we drop our ref - the object might very well be gone by then already. Signed-off-by: Daniel Vetter --- drivers/gpu/drm/i915/i915_gem.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 49592d6..56abcd1f 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -226,10 +226,11 @@ i915_gem_create(struct drm_file *file, return ret; } - /* drop reference from allocate - handle holds it now */ - drm_gem_object_unreference(&obj->base); trace_i915_gem_object_create(obj); + /* drop reference from allocate - handle holds it now */ + drm_gem_object_unreference_unlocked(&obj->base); + *handle_p = handle; return 0; } -- 1.8.1.4