From patchwork Wed Jun 9 06:09:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 456797 Delivered-To: patches@linaro.org Received: by 2002:a02:735a:0:0:0:0:0 with SMTP id a26csp4730274jae; Tue, 8 Jun 2021 23:09:19 -0700 (PDT) X-Received: by 2002:a2e:9b8a:: with SMTP id z10mr11935801lji.159.1623218959287; Tue, 08 Jun 2021 23:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623218959; cv=none; d=google.com; s=arc-20160816; b=goOgueeb7cOFTzS8VH6ohhf8hrTN/gO+TEv2gB6q7/0m+hhgXLgwbq9fEqZjPHP9wG RqBhU9M0PFXIG3KwHeE+KF2h+OAO54o1WsxAgY4cnKGQ9DpSBkB3IIl9usKKdIivjeyW UtlvmOiRaoV55KKh/e04kJ5BNN2hRk2V5BHnd8aHwW4we3Zy4o2PbKeBcnLRiOsG6f8W PmQ0xwZNQCNd2V4W1oK9DZ1JOWW8Gp0FUfnSFO4ToxVKEKYVoDnJ+Wi1pCzQkXc5Mgyx mBUQCyMEl52VqasUMd3LCxsoyDdYMrvP4taDhef4T+NP3YB8UCfMK/dPcGgvI5c3bSYQ lJmA== 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=lidgJbwxsBTtDjGrgXxQVsAgcSl1SDhtXh5Jv6adUDTJsR4Y7MzKFyht/RHszgZ/Ac VO+lGpDRfKaRYifuX0H+1phD5MdODyOUQYHv34FGzH23i338YsmpfB5pRwjiZf956Aq0 4J/5FbJ1zWCweXLVEMBsPtJ9Q+dBz9i/NxQ6MO1U2lVUhhAwCZvZShKnIYMTaZPiebus ZfPxb0shmAsTxDr0HjeLnv7e8fYBdFPosGcjJbAy5pqGC/V8ESecRTotpMiiJdeFChEG UPfREyMh2fZ0C9OLOpSA/Mjfn7KnTYAFFWmwLQNBmZ4g1i9qXYgZ1NNBHqFLBR4cXR9L l8Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nr0mzq62; 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 d15sor482732lfq.57.2021.06.08.23.09.19 for (Google Transport Security); Tue, 08 Jun 2021 23:09:19 -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=Nr0mzq62; 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=Nr0mzq62bjXdj4oL45yRrqwFuW+HGvFzMbQMIzEFoUaSs+cxX+fpKa7AgBKhx3MiAm 1uJ3/jC+BKZioL6fZ/Oc0TWauJHtvthu868NYnqT4v8xEbOJOCOwBZzbbmfCa9Ou6EWT IXXUbE5LNGnstLVBt/icT8AuhXmyT29B6OFf1MlIJWGQiS6YhMx3JvW4qv35/0m4U9nN 8+L4iJWz+nve2IXifP8QOrywJzFI75m0kZtoQWfC9mNi6RtjRV1aV7Ach5Aaumz7EftU LECkiDxh1Wsa168PTiTCewCHwnbO6xERms9QkJkLjwWqcpO4vdPOr27fxeksBp0BFkN2 +ddA== 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=ZDnnA/XxJMyQRo0XWTPcNOcfbYWNb/Knx093rBC1I80X1DCrGbaKeMXH7TjFTBTRWe HLpmVuBjpzPOs040DaZrfHsh4sEtmf4JzTMsVzTCVA9r5zBSeS+heH9aI8j15Bhk7k+7 Wa49KKuL2kCLzz8OqG76BS/IymV+BNbDtQ0Ty7McAOXGxTYYVoHgeS3tXiNy+WC0CgfB San6LcptTABxSTLQcvGf8yuiBB2He8k3hrDVBSswUPhzYT6KA60LdDQGHFebOjvHawEr OxsrSHy6A2U/C7mFqEXftvV8+qaww1g5fxMOanEiLSokBS6Unz5lGjevJQmbN1Za0bhr +0+w== X-Gm-Message-State: AOAM5325gY8pp84vtMxjSo487lmiRGTopMzlhlKIfK/v+7M3KQnnxiCM vaZQQhbr3kJt/vNtTDI+HSUwoADZqxoRMTBM X-Google-Smtp-Source: ABdhPJwot25EKkCKM4HEq641t4VhpqW7RwDZWfJJuawi81MP3DhszivYqKpP78Ecs8By3CaqdLjPVw== X-Received: by 2002:a05:6512:3baa:: with SMTP id g42mr18023216lfv.195.1623218958910; Tue, 08 Jun 2021 23:09:18 -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 l26sm213735ljg.87.2021.06.08.23.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 23:09:18 -0700 (PDT) From: Jens Wiklander To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, op-tee@lists.trustedfirmware.org Cc: Jerome Forissier , Etienne Carriere , Sumit Garg , Vincent Guittot , Jens Wiklander Subject: [PATCH 1/4] tee: fix put order in teedev_close_context() Date: Wed, 9 Jun 2021 08:09:07 +0200 Message-Id: <20210609060910.1500481-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210609060910.1500481-1-jens.wiklander@linaro.org> References: <20210609060910.1500481-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)