From patchwork Thu Aug 26 12:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 502856 Delivered-To: patches@linaro.org Received: by 2002:a17:906:f46:0:0:0:0 with SMTP id h6csp162472ejj; Thu, 26 Aug 2021 05:30:43 -0700 (PDT) X-Received: by 2002:a05:651c:553:: with SMTP id q19mr2795908ljp.320.1629981043232; Thu, 26 Aug 2021 05:30:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629981043; cv=none; d=google.com; s=arc-20160816; b=EwTZv45S3/0YKvLf98OzMl/4nofLWzRzmyUjQcFzV5RqP9oWC9lzZSMTUkJz5bIQ0Z swGu/zNn8QSY50tE8jx2ap4Op3vJHD9S7ob5iSyLods8MAe/STf3j/umAgoWbf+l83X+ HYtmwkA5+ID22t+N+0GTAnhqLHr2g8SUL4EuoMHvvOiHz2STEMjp+wCzXPn/WhyQ/L6b rJLv/kCRFgMaEXQquqKxdFXIq8Y/R0DexZr98+iQJZyqfuvh6Lqz23jGRi7kJOsaFaE6 CxHZBimOo99dlaiVHoYD/hP4tOBqUeL3ETQHigJHPg7B62UOcJ1Wc7v1R9KLtggAeNpj SzQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=Uz53pczr7o7l9a4POHw+zPk/RBZFCcKUPDcgjnnhW60w8qpXsIXbbMzuqRh6++d+PQ hYtogSF3nA8qQ/qymcrKyAescLWcBPwruQ6V95H0IJDEWFF0hyA8eCSogrOdWPyxgNRz IUIQ+dctxeKuMCrnlX3uhkq/H4ARhtiI5CxIMNkaWBkAuhN7r/BDirchdnwK8NPChjGt vfTpq+dojpWdpAaZOqfop9V9fRND62QsBn6NIfGPlu5R6JqMDu/mFHPRCNtfxKn0NO7q sfg8/ceZoUbqWYpGmgTAp2Za8kKkJZSdKzOjY8rD5QBncHV7c850Er+NAeR3GCtPTNDz mYRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZMisyRD; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id w32sor873700lfu.22.2021.08.26.05.30.43 for (Google Transport Security); Thu, 26 Aug 2021 05:30:43 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZMisyRD; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=gZMisyRDxgH5gaSMdaSrLWrVBgnJiieFFNBcmjDx33BBp2VM2mCTz9s8UTZi7/BJ54 pZgn93V8Mcb9S2QKsXTdwwOL7O1KDzQUt56MI1ztVplj6OREFy7JveICkKz//LHg2619 TqP9/aqM54aR3TctwTgrQdMcHL7XKWQ40vrUjM4eQthXogUG6POhttFg1AzilsGCE99i 9NRja4Jhksy+I5wQyzEaxpej5QAm8Cmh03E9KSgFIEpKAkOXKTnytB9i1hD/DBRWcqN0 eOpZbST42OrMEzQxDVHyfPLETKwSeUcLfBOzZe97pbX39jafv5Gh6/x7LdtRmWVmB37c pJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=KVelQcyPiMiAs9fxdqLl/5IXXwmvdh+/Nw25+eLbBLFKp5egm8H5wuzzuVRuXe0C+N GVPcpdu0EKtrSFv/Lwitz8siMM8evJRJc5gRlenhM9trYd53nPgyt6cPOzYvT/51Kzhi TepK4ZFqVo6bidZFEyRPIkyPv06HuSziRa82/Q06458JZxvXKBRSOyUcrKEvrnszUmj1 oOgFHoO89Tp9u3rEX0ttHARM1Y+xCHoTId++Y5C0hziuuO0ZMgtVvhxw+TCcDwuFRG3H BqZQuEmmo0jQeH+tiUCjO4GdXPme8yKeJDuw/fx2qguw9JEumXtziZf41Gf6U4xl9z8n GBgA== X-Gm-Message-State: AOAM532XhlHiIqY50mxlplUIaE684EDpvJs5BycDrJXP0x0amGD/Hl/V HKzrgCAtlmZDVP5damhZIRLZIFL1 X-Google-Smtp-Source: ABdhPJzPoA85sfVjo4hiwKhrFd0MZiun3ogANCDG9hsxjklStOkxEllbiklrHLRGsCcjvj3zrjuTig== X-Received: by 2002:a05:6512:ad6:: with SMTP id n22mr2695207lfu.532.1629981042914; Thu, 26 Aug 2021 05:30:42 -0700 (PDT) Return-Path: Received: from jade.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j21sm332283ljh.87.2021.08.26.05.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 05:30:42 -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 Wiklander Subject: [PATCH v5 3/6] tee: fix put order in teedev_close_context() Date: Thu, 26 Aug 2021 14:30:29 +0200 Message-Id: <20210826123032.1732926-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826123032.1732926-1-jens.wiklander@linaro.org> References: <20210826123032.1732926-1-jens.wiklander@linaro.org> MIME-Version: 1.0 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") Signed-off-by: Jens Wiklander --- drivers/tee/tee_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.31.1 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)