From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90C98C433DF for ; Mon, 3 Aug 2020 12:55:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6ED6020738 for ; Mon, 3 Aug 2020 12:55:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596459314; bh=e+enH1SlKMh71tdxFgewJDn4qhoU0rZPeAcCeN+PIQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WDgorMtGwMU9fK934ZoURvQzq/7aqG/PMu0dhnd/Mk2iyRNheYOn9t5x1IZjmTywT ulvEwZ7N99V1bo9VvF+/+3/uSbyzh9jBYvdAWmhLwD1iu3Cu/ForgdJ82fIabDMlza eyCfB+kIFrY0SYHp6mhqTmVlvLcps9a3Voiska9Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728690AbgHCMzF (ORCPT ); Mon, 3 Aug 2020 08:55:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:46832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727789AbgHCMW7 (ORCPT ); Mon, 3 Aug 2020 08:22:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A60F720738; Mon, 3 Aug 2020 12:22:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1596457378; bh=e+enH1SlKMh71tdxFgewJDn4qhoU0rZPeAcCeN+PIQ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KG0cErbm6q7frThRPdwweUz2tFQqnRwBPEPlKoBmg8ZnN6CCG9MBh3I4HABy/yWUb Hxq8j4RrKmkxHr2ozHWCbaPAVtjrTRj3hLLmjTt0tRxI9g6D/frJ8+WtlFIc8E5QFE Dfqi67I9HxmEjJUT3bxhELj1teXgpNRSxHJTn4+Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve Cohen , Daniel Vetter Subject: [PATCH 5.7 028/120] drm: hold gem reference until object is no longer accessed Date: Mon, 3 Aug 2020 14:18:06 +0200 Message-Id: <20200803121904.208406251@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200803121902.860751811@linuxfoundation.org> References: <20200803121902.860751811@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Steve Cohen commit 8490d6a7e0a0a6fab5c2d82d57a3937306660864 upstream. A use-after-free in drm_gem_open_ioctl can happen if the GEM object handle is closed between the idr lookup and retrieving the size from said object since a local reference is not being held at that point. Hold the local reference while the object can still be accessed to fix this and plug the potential security hole. Signed-off-by: Steve Cohen Cc: stable@vger.kernel.org Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/1595284250-31580-1-git-send-email-cohens@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_gem.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -872,9 +872,6 @@ err: * @file_priv: drm file-private structure * * Open an object using the global name, returning a handle and the size. - * - * This handle (of course) holds a reference to the object, so the object - * will not go away until the handle is deleted. */ int drm_gem_open_ioctl(struct drm_device *dev, void *data, @@ -899,14 +896,15 @@ drm_gem_open_ioctl(struct drm_device *de /* drm_gem_handle_create_tail unlocks dev->object_name_lock. */ ret = drm_gem_handle_create_tail(file_priv, obj, &handle); - drm_gem_object_put_unlocked(obj); if (ret) - return ret; + goto err; args->handle = handle; args->size = obj->size; - return 0; +err: + drm_gem_object_put_unlocked(obj); + return ret; } /**