From patchwork Thu Aug 20 09:19:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 265770 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=-9.8 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=ham 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 7E61AC433E1 for ; Thu, 20 Aug 2020 09:56:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F0AD2067C for ; Thu, 20 Aug 2020 09:56:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917389; bh=YwZJ9W+XJlZjVI5HfWYlwaHFRfhwEswTi5fcPpoXoI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=e/kZZI/7mT5mPL0RJv/b0IitvFKKN69xVErWNfiI8jHG2ccziyDvfcEZgj9QmAqUP 8eX0prv2X/WP71MXMvt0qFrnOObIhSM3g/YEvHLH1jsyLyQSfclG+/V/kvHrip8AaR +F0IS0i0rCXHHauz1yy2o5vYPQ/im7Z2zKk2haHI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729088AbgHTJ41 (ORCPT ); Thu, 20 Aug 2020 05:56:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:39770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730256AbgHTJ4X (ORCPT ); Thu, 20 Aug 2020 05:56:23 -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 D4C8320885; Thu, 20 Aug 2020 09:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917381; bh=YwZJ9W+XJlZjVI5HfWYlwaHFRfhwEswTi5fcPpoXoI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GdhPfefC2DSs+KxmhHbKYYg4oYX4qKgwKqZHXIdfSKfT0EFdguVSI/ky2Uo0NtD3T lnw0T4fr7+XrBW0TIvYO02QiS7WA0wMQGhM8zatJhO1BEaVLsmLCA6zWOM2zGjyGfN R8QcVRxt97GJbJox/XE/NxkA4NrOW8eFGcb70Vmk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve Cohen , Daniel Vetter Subject: [PATCH 4.9 012/212] drm: hold gem reference until object is no longer accessed Date: Thu, 20 Aug 2020 11:19:45 +0200 Message-Id: <20200820091602.949207208@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 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 @@ -694,9 +694,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, @@ -721,14 +718,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_unreference_unlocked(obj); if (ret) - return ret; + goto err; args->handle = handle; args->size = obj->size; - return 0; +err: + drm_gem_object_unreference_unlocked(obj); + return ret; } /**