From patchwork Fri Jul 10 22:40:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Cohen X-Patchwork-Id: 11657483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A528213B4 for ; Fri, 10 Jul 2020 22:40:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 832EE2065F for ; Fri, 10 Jul 2020 22:40:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="rdWz+rIb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726510AbgGJWkl (ORCPT ); Fri, 10 Jul 2020 18:40:41 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:48677 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726407AbgGJWkl (ORCPT ); Fri, 10 Jul 2020 18:40:41 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1594420840; h=Message-Id: Date: Subject: Cc: To: From: Sender; bh=vtmcg9y3utHjV10IFgZiIry9hswQAoCk/nvV3VJg7Cw=; b=rdWz+rIbl61+I/7/CMfR3JT5zhhzW33/TJV+9BHTePVE9KCuCSBLT4g+zvB/wBLioHQEGEXk 5HSiyrGf7W0iJ9ss8OAolGx7ZG3Mxp4Wpt9GBeJC75IPg4toj2G7DNw7Zpgeh6XjZUtYydUd 5TxG4gB6MTF6R7O+IX4SkRZmkig= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyI1MzIzYiIsICJsaW51eC1hcm0tbXNtQHZnZXIua2VybmVsLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n01.prod.us-east-1.postgun.com with SMTP id 5f08ee67427cd5576602e032 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Fri, 10 Jul 2020 22:40:39 GMT Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 288EEC433CA; Fri, 10 Jul 2020 22:40:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from cohens-linux.qualcomm.com (Global_NAT1_IAD_FW.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cohens) by smtp.codeaurora.org (Postfix) with ESMTPSA id A39CDC433C8; Fri, 10 Jul 2020 22:40:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A39CDC433C8 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=cohens@codeaurora.org From: Steve Cohen To: dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org Cc: Steve Cohen , seanpaul@chromium.org, pdhaval@codeaurora.org, jsanka@codeaurora.org, adelva@google.com Subject: [PATCH] drm: hold gem reference until object is no longer accessed Date: Fri, 10 Jul 2020 18:40:26 -0400 Message-Id: <1594420826-4897-1-git-send-email-cohens@codeaurora.org> X-Mailer: git-send-email 2.7.4 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org BUG: KASAN: use-after-free in drm_gem_open_ioctl There is potential for use-after-free here if the GEM object handle is closed between the idr lookup and retrieving the size from the object since a local reference is not being held at that point. Hold the local reference while the object can still be accessed to resolve this. Signed-off-by: Steve Cohen Reviewed-by: Sam Ravnborg --- drivers/gpu/drm/drm_gem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 7bf628e..4b2891c 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -898,14 +898,15 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data, /* 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 out; args->handle = handle; args->size = obj->size; - return 0; +out: + drm_gem_object_put_unlocked(obj); + return ret; } /**