From: Daniel Vetter Subject: [PATCH 2/3] drm/gem: fix up flink name create race Date: Mon, 23 Jul 2012 10:27:26 +0200 Message-ID: <1343032047-5713-2-git-send-email-daniel.vetter@ffwll.ch> References: <1343032047-5713-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-bk0-f49.google.com (mail-bk0-f49.google.com [209.85.214.49]) by gabe.freedesktop.org (Postfix) with ESMTP id 7F9759EF92 for ; Mon, 23 Jul 2012 02:33:49 -0700 (PDT) Received: by bkcji2 with SMTP id ji2so4803128bkc.36 for ; Mon, 23 Jul 2012 02:33:48 -0700 (PDT) In-Reply-To: <1343032047-5713-1-git-send-email-daniel.vetter@ffwll.ch> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: DRI Development Cc: Daniel Vetter List-Id: dri-devel@lists.freedesktop.org If userspace does stupid things and closes the last GEM handle while calling the flink ioctl, we might end up with and object with obj->handle_count == 0, but an flink name lying around. And that flink name must hold a reference on the underlying gem objects, leading to a neat resource leak (because we only reap these flink names when obj->handle_count drops to zero). Noticed while fixing up the prime import/export locking, which had similar issues. Signed-Off-by: Daniel Vetter --- drivers/gpu/drm/drm_gem.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index a9e169a..6aa30b8 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -298,6 +298,11 @@ again: } } + /* Check whether someone sneaky dropped the last userspace gem handle, + * clean up the mess if so. */ + if (atomic_read(&obj->handle_count) == 0) + drm_gem_object_handle_free(obj); + return 0; } EXPORT_SYMBOL(drm_gem_handle_create); -- 1.7.10.4