From patchwork Wed Jun 16 10:36:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 461388 Delivered-To: patches@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp487158jae; Wed, 16 Jun 2021 03:37:13 -0700 (PDT) X-Received: by 2002:ac2:5396:: with SMTP id g22mr3238486lfh.84.1623839833559; Wed, 16 Jun 2021 03:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623839833; cv=none; d=google.com; s=arc-20160816; b=X8OChfW8AYUAi1DVzpF8yTZpKyvNkqY7p6sgxD0OGGSb2DHscLs5F+0xQrqLirir1t hcKELbS5L3LX94jl7ETskmsonx0g6nB3fZsEkScoispL7D9U3scJHANc6NEC0h6UQHh/ uKYaKlfhGg6RtLK0mjScYIrlckeZqL+JtwJunThBaYW7hsp9lOOdBB6ZwMKFtjH+KzoL tjSP3UrvzyyIWn6upOE8XzeYQ1qT8rNJxXON8yjju5gt8+y5M9D1FMKDrOoYSqvZdT9T fit227ps5+GfdoQ541B2jNx6pZxKFCWxpw0Vrh1CPGByNR/JA9lV6NnYvggISA4Yjmnr I53Q== 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=/f1rY0k6EQWoltoVI239rx9YFVi0YDoyX+ARCpEzBL8=; b=OvWoYFROxmNgyHmyAIM4cO2ReFWevFmUtj7nI8JOSEnPd2tcHMF4iCGmhotoo6KVzY yptO6Un9LcvBo2zgRPOTgnjDRxJAGE+eiW380M7vwa26RiENvQIHzfES7C/NgEWKK7fo ewX+LG4MSKeMn/lVDBOpH85QUf2WPhMaJfTNz+XEPszzUsyPB1HxtY6HuVqUt6hrV7tp jo5+gkYB3IRI0v4KAowKxoiDFnPorhg6J2aMgJmzL/51rYLLk2AFthWNRpS2r8Mt+R/A u/PdmM1tZsaIOnyJtElWJuUHDGvPhAWL+weIhHfo2serNcJBVu3YpVuL7O2b8UOKpZIc ZNog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=llG26ISb; 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 q11sor383854lfk.84.2021.06.16.03.37.13 for (Google Transport Security); Wed, 16 Jun 2021 03:37:13 -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=llG26ISb; 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=/f1rY0k6EQWoltoVI239rx9YFVi0YDoyX+ARCpEzBL8=; b=llG26ISbSHMQx9SAWWK0Ew5GahaWNLFUKYF3eJzC4p33bRd9Be60A93cKFvJyK4UOz zPO06ptAc1p3sQr86nkEQV8CU+83twF95m4ySOp2qgCoovEzCa6CV7PO8ZkWDLhgPps1 A+GHdG9jn2/J9PtUYjwcKSxCrFrp6ThpBnl0N9E2qlo00n53XZvUbugI9hIpCRlDBDg7 12rNUWk/l1v9+geVlXECny1yce1nLA1zjK/tyvFZ/dspVr+VBcfQmO7KIxe/fc/iVTeq 672zro9XoKRvv8/Q6nwkbWoNctEryLJwZW+t5S1qaS/IzciywYhp/zMpyQ4aduoFdfbc VQJw== 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=/f1rY0k6EQWoltoVI239rx9YFVi0YDoyX+ARCpEzBL8=; b=hW+foAxllyk3zsS5OU9GldYykC6RaTMxVM4OD5o3CrYAzwPKqPImgs6nVv6mQa7sRb T+u/1ZhYr2QEts+2uaPZ1QOg6sD/whEEJgtJtUkFKaj79XhGgpNygMFlprsa2Pb4Ar2/ 1mmZP+q1KxWEYNKG5w4+Aw9nkKUSh0qCivyfgsQk/OUVwy7onX1uWuUQWS44iu+PCEXG EUygrhGAfQAS5bLaY8Hi6tNzUnBi0XdZinXrcoeVE7DSOYNVsVfmhul/fJdHVEcL3rr3 Oa4QHRaQRhGBJlLUm4LcGq5hka/CLew4DK+CsV5BT/a60K9iVTgaOxHT0dYBgY+B4NpT h25A== X-Gm-Message-State: AOAM532lgneT1yoN6Od7Cg+eV4CBOBvgxGfQjxiayn6ubeXehmnh3uDK v9MRxXOy1QRle8IALgWfzRQWuJa5 X-Google-Smtp-Source: ABdhPJysfxzlZ2ZCBCeU6Y2xQDldKhQEt20KJ5s961GMZJdmsWDBpqHYUiF3UpWheyplkOkqFfgg8Q== X-Received: by 2002:a19:550f:: with SMTP id n15mr3209225lfe.660.1623839833192; Wed, 16 Jun 2021 03:37:13 -0700 (PDT) Return-Path: Received: from jade.urgonet (h-79-136-85-3.A175.priv.bahnhof.se. [79.136.85.3]) by smtp.gmail.com with ESMTPSA id m17sm205621lfh.288.2021.06.16.03.37.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 03:37:12 -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 v2 4/7] tee: fix put order in teedev_close_context() Date: Wed, 16 Jun 2021 12:36:46 +0200 Message-Id: <20210616103649.2662395-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210616103649.2662395-1-jens.wiklander@linaro.org> References: <20210616103649.2662395-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 480d294a23ab..f97d95b50773 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)