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: 12309029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A521C48BCD for ; Wed, 9 Jun 2021 06:11: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 F35D660FF0 for ; Wed, 9 Jun 2021 06:11:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F35D660FF0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@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=C1SgjcputOt4xmB2LPvlP4Bh8D7cRk2hVh1UTgOLv3o=; b=VHHFCf3oHpwMAS joJ4AQ6xWimIkNHZfjiiIJdEQifuB/jpjtdANEogP0SwNUfipzInc5I1AIDxmTebhu6GGdhTE0vr8 NteCyGSnNuKhW8IARxvpRjajEdcnnDY6nmwa5iMieS0ZXTYWG9GyoSu6TkHKq3UdIrxfT0MiJYPhk j1VW3jfCOh8wGWAYHbn05oiAidX75C+UKJsxc0GsI2kXw8Dpr8Yzl7xltFmRTtC7MpGzpCBVnjCgO fIw/MRjT33kecSgXxeKSr1+YBooDfRbvsQT/Y4oxniC3IVpNA8rsbaic9sDasyUdxA6o5eiKBt2Em aGhTtCR3d4BnLzuzJlhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqrQ1-00Brwc-Cw; Wed, 09 Jun 2021 06:10:25 +0000 Received: from mail-lf1-f49.google.com ([209.85.167.49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lqrPx-00BrnU-8q for linux-arm-kernel@lists.infradead.org; Wed, 09 Jun 2021 06:10:22 +0000 Received: by mail-lf1-f49.google.com with SMTP id a1so26387518lfr.12 for ; Tue, 08 Jun 2021 23:10:20 -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=/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=UPnJmu02x4kPBa4YHs9+ZFhF6AqVkrncZJdsYSjuFjxrTpvggvM0wq3ArGZNH2X1fY OrCVckZH2U2wovQvQhg0LDYsRfJf2unwZOYusm06FhuppYnBc9DKK2avCrikiNHohK35 facDkXM1j832QZoRIgLqGm1Pr5zR56RkowyDB6tBxCXxYYuC/vcUJg0kCsqaTS/nsEcP ALneCVAB1/pcSVzZos+vxdiCu3gvo74Z/BvZanRFz/KIg5n0cRQZSPgFR5c/P26FXmLV E/A0cF8tLhXKITaY3EM/jE52HGV9vmZunb8kGhrKrofydou1ObHdbu+7BeMvNp67DSXj 4bkA== X-Gm-Message-State: AOAM530JkuQiARp5ZpsFXht+I2xoP35Zc96qMJlzicl2kQunr2FCaq1u bbGTH7beZZq5ve7//F4wX0lmPA== 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) 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210608_231021_376233_327C8C11 X-CRM114-Status: GOOD ( 12.23 ) 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 --- 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 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)