From patchwork Mon Jul 23 08:27:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 1227001 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 649D53FCFC for ; Mon, 23 Jul 2012 09:35:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 427DE9F5D8 for ; Mon, 23 Jul 2012 02:35:09 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=sBF8p7bjOk4mmJRwf9mZ7FPJeQgpGJ/RTeGgRli+IGg=; b=Q/C/7J+kDTzyNZkbg9M7cEjocz398TAaHc/zm9vzKiOkmto4rF20yIgsPs6FUp8H7Q D80hOmWFidDmhmYt6+qc6qug58PHEsF5Dw3ZxyU0byr8gsvz3RAnkJcHzDz4bnktBPfp 4cgEkvCO6w2cg7rMS7uSGzN9bqBWeTqAmSZx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=sBF8p7bjOk4mmJRwf9mZ7FPJeQgpGJ/RTeGgRli+IGg=; b=ghb27SgJhDxZjtzPuZOnSw2JZ9MgNWzJhH4wyUa3fTIh23Q6Eznig+tJQBNBhkjbCO lem8nFqJ/+97xGhKmeXVcj+l/2JI4iYRW01mS87MamqgPdUgixmmmnUEOakhlFr5DDjg RQh/aoHo3NJfLNtm6M4GpyXGLgPchSxDPgCayJ9EbCOeqKsWklmJ2DCLjvyVqTUYuBki HSPGtw4LoaIMbqm/JZXlGW9g09GmHHQJoDmfZxeLpcUHm5inV2k2DS402aG8tOIIYaG9 WMYcltJ7vegQpfBjPkuqHeDnSBKTevR6dwGSEJvaV9awMNEsoQ2ggmHzBMvkTVF44/jH L0mg== Received: by 10.204.152.27 with SMTP id e27mr7181992bkw.56.1343036028493; Mon, 23 Jul 2012 02:33:48 -0700 (PDT) Received: from wespe.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPS id 14sm6626763bkq.12.2012.07.23.02.33.47 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 Jul 2012 02:33:47 -0700 (PDT) From: Daniel Vetter To: DRI Development 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> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343032047-5713-1-git-send-email-daniel.vetter@ffwll.ch> References: <1343032047-5713-1-git-send-email-daniel.vetter@ffwll.ch> X-Gm-Message-State: ALoCoQnl7wdqddyNuiyGLKnVrIW6zgFVPElmcAl/5+V5cuY8tOQPx1CtDPiCoF8FncbzqRJuWuD6 Cc: Daniel Vetter 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: , MIME-Version: 1.0 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 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);