From patchwork Wed Nov 3 09:02:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 12600433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CA41C433EF for ; Wed, 3 Nov 2021 09:04:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EE31761101 for ; Wed, 3 Nov 2021 09:04:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EE31761101 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+fjI+HHmZuo+jlqN5Mwz9DF1/rYDj1PF2JCKQ7L1wbY=; b=39w3ncRyi4I+pM 8KgHQN0eLM5JrCw6CS6bQK1mXYFL3kx8S0qw0lGuSxKbq1MnMuVX4fyMcQXrmerHkfRz3vPTfDUnB igg5NT7xay6w9FWSUGGccsmbfmA5cXKJ4Nu/f9O+Yl2hJU1YO5QrcYUJ3Tss7lVoIfcC1lseFGeRV doF6vSNWUC6IlJqGOktJLHj1N5jz4D+/M+jhu/BZIhxLdSYGeb5X1fvfnkUmkqkMHC2NK64gmby/M UEtbmd9Uss4hQaHl8oXRmW3FsexsEh3h0Un9n0gxE77fGC9InW9gpIx+1+Inm4EExcAnNBaBa5zoi 477GrlaXKdfuUpC4Ovcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1miCAn-004cSS-BI; Wed, 03 Nov 2021 09:03:09 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1miCAj-004cO5-5r for linux-arm-kernel@lists.infradead.org; Wed, 03 Nov 2021 09:03:06 +0000 Received: by mail-lj1-x22b.google.com with SMTP id j5so2589564lja.9 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=LinbbOnyoj+9rJJupaI6vyNrGQw+SMJavBUvIBkzV1nkRR5TPb66IPi/EhZyZJ22oq 1BYvPAV5c61V3OjZWbiewBktsgwN2/UEoAiYuhWDI1x0UQ1lbPiWOgaZmR+xYWaTwrCg Oc9EjGNyFq5qaHM5SnIWJ/L3HNccTLabVitDdnQ0BBMHcdZk0j7lcHG1ZquP55jIx0HE NkVy5XL5jN7i/YAqXYLguAAOYTUEzNnZfmB3mffmy/3K63bE7nGj3A2iX45MSEW9rlTa uDKyLJDyisYGipwKpeveJVvMwL7Kbl6oGZBTaADwzYjtR/0PjwLozGgguhv72e3hXzW7 G+fQ== X-Gm-Message-State: AOAM530yrEdmaqpaayYHEFJzTs4iwqA0TcEF875v7e/UA4zxV0Xr1ZZd Y+aiA/4imw0AsCUKNMgYd0Xarw== X-Google-Smtp-Source: ABdhPJy2IrqOF3ogwb+7EqZn1rFu3bhrk8vJtGRNZ5plknFzvRDWYEdyK53VxBLOuXPASCA5Skn+bQ== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211103_020305_280975_8F8680C7 X-CRM114-Status: GOOD ( 12.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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)