Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp172211pxb; Wed, 3 Nov 2021 02:05:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbQEK7sADAYgUDppEnRiSVY+bQEFgIpweUYhEUcbgdmexedbZC4pLTtMkJeJNKfbtcKhUT X-Received: by 2002:a02:22c8:: with SMTP id o191mr31219099jao.31.1635930355209; Wed, 03 Nov 2021 02:05:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635930355; cv=none; d=google.com; s=arc-20160816; b=hLFKZE6TNlCkdixzNZdWIcrGhcKkPjzTOGFjgAbSE4DLzFE7AqeO30U8PJbk4ze9eD Lh502sgZrA3wzFdcQWQXt3oR93qvKY2bSryylQwSjt+QSo7/3TWPsAsGF3kvlDIlSmLX +m2IIFoCeeO5KrB3E7RqRr8ltSFMgMCINrFVHk3iQUjKPDr7JZYgogBKdeUeTk/Tua7t 2VlUxCuHAY54Mc+s3A/gJ9SxLgKz2x7Sj3jfsYVeqkbQtBZTs1+hT9FJM9OjISI1DnE6 pOpAX/te9QvcKbqIpKf8qb7bSYoQ1YW22HzVm0Nq/qBeBIYKjHqZRDTFwkkJdizDur+6 bWMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wDFhL54jBz3G05V/OraPaakr11gEhiPI9haVEV4Ys5E=; b=k4KfERHE4UMVfIbxnqnb4jYIxcY0NNNqZPiRPoAR1LJfGKKd3EuWNRHsW+mCEXvwUx HyoO9MDRnn6BQOTSCXphGT9UwbMYX71+aHxG16Iyau+//p74rq33kymd0BLiNFWYqRuy ZwbUOrYnY/gs2AazZUuZVxgVtMLqbUVCCWPsvHVJBsaact/EhVRTk6vcIXx8/z+jenK3 4zi09J9RZ0ncJ889uell0FKU3vt8L9SCjru9GwHpmxgo0bTDsXAjOfYaL9Z4l4N92Bh7 EBUE3hFG1o70X/COVpL1hh2v83Z33wVQD+LGsKzirNFI6O35aBRuxP+R21ovJH3NifSM j8eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JrbkOJN0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a4si2096430ili.64.2021.11.03.02.05.39; Wed, 03 Nov 2021 02:05:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JrbkOJN0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbhKCJFt (ORCPT + 99 others); Wed, 3 Nov 2021 05:05:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231903AbhKCJFm (ORCPT ); Wed, 3 Nov 2021 05:05:42 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90A21C061205 for ; Wed, 3 Nov 2021 02:03:05 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id g3so2595273ljm.8 for ; Wed, 03 Nov 2021 02:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wDFhL54jBz3G05V/OraPaakr11gEhiPI9haVEV4Ys5E=; b=JrbkOJN0AVTm6aU03vDx3RA7J3nBQq4dZa143tOdEgrSo7btHpTOx99WIZ/Ux9cVAI P4y1XDNIgA+r0IulEXK4zuoXLG5PAPr5bc9n6widMRrpCG+vIrQIkNOlIimZgXPkgsZq tG7os6N3rCTTTlwnplk24JpP02zL/aP6hFgKgtJdb8kmF/yM/Qxx10WXQz4GSsXcuH76 OXlNleVoGGpr1KaXJdrMvws8NoRfIoxTcPVYbHGHSkTZUC8Pt+WzWxi79zukB3Swp+SF 1Ul/eZQRyUinBps9OsfaaQrMNS+AwOiskYcVb9gyowMOWDyGhF6wBIHTH6mjoehruamB zyzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wDFhL54jBz3G05V/OraPaakr11gEhiPI9haVEV4Ys5E=; b=2NEFP4e4ck5calaU1KJiW4iNeFzzAbA2IoN4nkpuMyMSG7TCfHnxlilI58XHheSDiM 8dKT+HKbEYcTOEDgh10ZRnqmMjZXF1rHoQPixMfAkqICKyuwopOKUX/1sEtBMIV1ZUnt 5D+YC436X1qf3t0m44vX618TpAXCX9fUVQf8WSyGmvA6qNhoZKasJf0P6vkWDp4Hllvi 199DhLFDaYKZDUCEQwB8meCnoeSGuBO92WOAdbrDZ1vFPgKhb5rXkmH9/d/+f1PeOUri o5ZbczenZqTofQVcE49zKFI95uRVLmfsi8pTT6hJg9L600sfH4b+fHEOfBVK5UytQ/YU PbDw== X-Gm-Message-State: AOAM533kEZQfEeLBEZN5MkAiUJgJpCiu38We5FK5pkuTWpsKihs2/5Xz gZmIKxeumT7XKhMn4+JuXlLQ7vf7DMxBu7zoc0M= X-Received: by 2002:a2e:9e13:: with SMTP id e19mr45531615ljk.494.1635930183843; Wed, 03 Nov 2021 02:03:03 -0700 (PDT) Received: from jade.urgonet (h-94-254-48-165.A175.priv.bahnhof.se. [94.254.48.165]) by smtp.gmail.com with ESMTPSA id w16sm124373lfr.233.2021.11.03.02.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 02:03:03 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, op-tee@lists.trustedfirmware.org, devicetree@vger.kernel.org, linux-doc@vger.kernel.org Cc: Jerome Forissier , Etienne Carriere , Sumit Garg , Vincent Guittot , Rob Herring , Jonathan Corbet , Ard Biesheuvel , Marc Zyngier , jens.vankeirsbilck@kuleuven.be, Jens Wiklander Subject: [PATCH v8 3/6] tee: fix put order in teedev_close_context() Date: Wed, 3 Nov 2021 10:02:52 +0100 Message-Id: <20211103090255.998070-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103090255.998070-1-jens.wiklander@linaro.org> References: <20211103090255.998070-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prior to this patch was teedev_close_context() calling tee_device_put() before teedev_ctx_put() leading to teedev_ctx_release() accessing ctx->teedev just after the reference counter was decreased on the teedev. Fix this by calling teedev_ctx_put() before tee_device_put(). Fixes: 217e0250cccb ("tee: use reference counting for tee_context") Reviewed-by: Sumit Garg Signed-off-by: Jens Wiklander --- drivers/tee/tee_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 2b37bc408fc3..85102d12d716 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -98,8 +98,10 @@ void teedev_ctx_put(struct tee_context *ctx) static void teedev_close_context(struct tee_context *ctx) { - tee_device_put(ctx->teedev); + struct tee_device *teedev = ctx->teedev; + teedev_ctx_put(ctx); + tee_device_put(teedev); } static int tee_open(struct inode *inode, struct file *filp) -- 2.31.1