From patchwork Wed Oct 6 07:15:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 515301 Delivered-To: patches@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp232068imy; Wed, 6 Oct 2021 00:16:00 -0700 (PDT) X-Received: by 2002:a05:6512:31cb:: with SMTP id j11mr3149678lfe.368.1633504559927; Wed, 06 Oct 2021 00:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633504559; cv=none; d=google.com; s=arc-20160816; b=pauT0mZ6ZiP+JS11DNTL4n6X/7LcVwKT7eVQcR/zGFqxN36TsGnm8Qk0JvZxRXSiNq lif9mhIeIzTfPcKg7ZMfkOSMXjIvcDkke8GbwhXmcMSFj89Ame7M2rXy1JOP4lQF/qCY U8gQCMr3LXXwiA/OH9yKOGU7/TdoXiXIc/q2vfukcW9U8+GVTpDsuiDhPh9VZ7cK0VmV /WYVOkEf1ycKmgI4PCNCJVqvGUag4rnV76irfiCybI3dzmx1DuILJK/ObamQ34SDSfpW SwJj5RY5i51b8CatB9CE4CsBSqclDD/OxngZNaDidwItefI2vEKVdcNBQVOLi9VNnaak YARg== 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=lHE8l/pHKVnhvXjo2Nq0rmvh1k/OuF4k3XeCkI0uLjXtU/KvJCkdCX502Roee8SCLe ahru7gUSGaia04puxYoodaNNzdjTh7Dc8ufNy1P537uf1w02H/joqYsMfpQmky4ORJ7K keOPkA4Kw8qPhA/Bx4xh17+QMBLKPiTMhHuWx7bnS5tgVYHwz1shhs9aQuwG0KX8D6No ZGkLKSr5EbBnaHaqOb7SPZBt+rNbzx0Y4A05kkgCuMZV8Dv96FcYpUZXAwhTeIC+EZE5 Wvl08wyw1G7b90CB6CKfhfWrA1n7TpPqyhHWwrUx0F2rxh9sjq3ArPBrL3GNDy7ecR7E 9L7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qLQ1B0Xb; 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 t25sor5081840lfr.25.2021.10.06.00.15.59 for (Google Transport Security); Wed, 06 Oct 2021 00:15:59 -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=qLQ1B0Xb; 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=qLQ1B0XbhoR27QcdtLieBrU3iXl/MRVIKP5D+RBZ+zZI3rpJ4YAduePW5RAFnMwWtY IzEcaXV+jq4nTwZ+78yRdxll/2yB5fGI1CZm6guqkVNAAo8jFXzkSBjSIpEHgu9oxNmQ 49tF/YrA8FI8qxxUZe5jfdLb+vOfb85XExNYT2CwvyQhMkTlSRNgATXtlzrgemmWMgPv n4Mio/t9meJCoefgGLDjvz6t+pm/4OmRhtUJFNLfxmVvZDZqzXjpKANqxeZZejuEgbqT vm8ulcvGC2myrRHg/oRsoPVz/A2MBngKMXxTI89DwAXP+fhpIYflXufqInSgXEJsG2Qb 1t/g== 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=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=zNkK/q4AF4BzD3aDc2bf7NgDnXy/x9YWQZJ8payPPMdBqbZttXV6dhGThhLRkQfNBH KOJYed0He8FkOLmbPIpi19D76e5R9tlNWZI9BdYcSeXNGLXDGx6mY1tAcZ2uwmaAPq9w KdWSUfFuFrqvCF9BYX+Eza9T3nYcAFXSqOHCAUrXMGjQYSVbDnhPvFf9mW7AzDlkVUNc kXswAJgueZ5MxUeJwJL/9sl+7P/F2kDOxZ4M9P2ho6clY7m2WCbmieXPiD4Cz1siDUyw 2yohxjgrU4zFSdBr/y04/pgGMP9lSGEyaV6hwCeKI6UcZOBXHnQWR53ztgH8DlHB+aro ERtg== X-Gm-Message-State: AOAM531gyvudOjWnf3mKWi9WJhJKzltND3ypFY9SAYfEWBsqO7KTn25e 5+bIF5oA+TUXgZdidKLXywzIC4zw X-Google-Smtp-Source: ABdhPJx8JCV8rcwVFwjsP9B+UkHcLTmCs0PuzEQqQFbB4E7Z32nm6qHW8yNbtzF1LVXtIqs45hUj4g== X-Received: by 2002:ac2:4285:: with SMTP id m5mr7719567lfh.343.1633504559560; Wed, 06 Oct 2021 00:15:59 -0700 (PDT) Return-Path: Received: from jade.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y7sm960376lfk.143.2021.10.06.00.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 00:15:59 -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 v6 3/6] tee: fix put order in teedev_close_context() Date: Wed, 6 Oct 2021 09:15:43 +0200 Message-Id: <20211006071546.2540920-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211006071546.2540920-1-jens.wiklander@linaro.org> References: <20211006071546.2540920-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)