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: 12538775 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 6D865C433EF for ; Wed, 6 Oct 2021 07:18:57 +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 3964561100 for ; Wed, 6 Oct 2021 07:18:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3964561100 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=sE70lEnp4+d9XvD4hbYzIUazpFziEZHZGB9dg4ab5s0=; b=DSOGP7Din5I9FL MjI2yhbsokvcLG/mvLoI130SELa1g/O3I42n9jJB4srFLw788KhN7x9NoaMNd8pHmGiYDmtENibc5 DK+/3iKfRYDFspherNguuayUHVX12QJr8q+CzG01W2DdAI7CLhH0+rEmW7TLOrSTZWh0CHhk1jal6 n+sMsh71KKvR77d7UlhPFRKXTsQ8CG5zbmxeXK6axs0smgakpfoYS1dX76q1IiFUm6XJL70NmtDGf phvheDCKdZ+9bIDjGpvhx8QISqZu0LOFM1bTXL3lrJm+e86Je1SBYCEJkS/OnBoqCBFgJ8SeMzuD3 aQRI0gEJgrpqkstkuU5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mY1Af-00DAmr-2q; Wed, 06 Oct 2021 07:16:57 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mY19l-00DAWj-UO for linux-arm-kernel@lists.infradead.org; Wed, 06 Oct 2021 07:16:03 +0000 Received: by mail-lf1-x12e.google.com with SMTP id i24so6198013lfj.13 for ; Wed, 06 Oct 2021 00:16:01 -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=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=Msk9uG+L4Om3lr9rQHIJM1LofFeYeU2zySF1X16zm29fvl1mX6+CRL4W7GNCdUEzM8 wnwiehCkLQgsxPZFAbVav+iCJ7+Vkae8P02AzuTrCjSFeovFdRkTLvndgixmLUciT3WZ Cw22cNnzsSjlAMT8oyznIWpbv+ixQwSkLq9FwOSkqxDkBe6MTgEXsfePRnuh6I89jMP1 N4fMzJFLeRbmMdBTMbzLrLEpDwgFaGYd39BSDRA5qcBUG1Y2bwz80a4FpRuzw54D8EBk h4bTBTa7Di6LlhcYavg0aQK0U70AEFv5FNx7iBoG5Vh3c8bPdEzcaC37AiYOVAj44iOV FDfw== X-Gm-Message-State: AOAM5303bB16deyN1+iczQkbKgNydCZ9N2QFiJ6F2eWLR1BF2sMV4MJQ qD/vTvqY6DGdjeQ051shi3BGoQ== 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) 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211006_001602_083033_E79D2549 X-CRM114-Status: GOOD ( 12.83 ) 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") Signed-off-by: Jens Wiklander Reviewed-by: Sumit Garg --- 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)