From patchwork Tue Oct 26 08:31:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 12584153 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 2A176C433F5 for ; Tue, 26 Oct 2021 08:33:51 +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 C1A7160F46 for ; Tue, 26 Oct 2021 08:33:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C1A7160F46 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=iZeQif0H5hUO7u TqbjFKNenqDBAfQ/3VbyJhc5TVomTkyMRY/thGd+1/Hoz9Iuh/24aDDxKwsc12K6GIAoMzyKqSzfe 4dyBDkhRjzcN3N+vD31XGdj/ybBOMkpxMaHGf12eijH4xQ82yKJBpngtRHKfScsE9nQ0qoY2u7BEo K8xWLy2Cf4fya/0FMx7bIUe3HzI0TcmeO0KlTGZ8mw9CoANfgZPna8gWMZn0ss6NfusPWnDoWUT+q oxgb3Wx2c/QiVPd3hGPTbEKRV2i1pddvi1RlqcwP1pneDtuK/BgHlCIZ/y3ivN1WP5qHcWsFjmdUH 0Mk4TpEo7qeF41oiQlfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfHsq-0012nj-9R; Tue, 26 Oct 2021 08:32:36 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfHs4-0012VT-Iq for linux-arm-kernel@lists.infradead.org; Tue, 26 Oct 2021 08:31:50 +0000 Received: by mail-lj1-x231.google.com with SMTP id u5so17298157ljo.8 for ; Tue, 26 Oct 2021 01:31:47 -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=ZHi/y1ckyJDjwvb69REwPJQs4kGYBOXGfL3+pN25jVWAnTb2vKBp6jHF3eT3WtRHBM AUKxjjI9Y1MAMOa2cMBBmpQq1yWCcw5kPu6bxnNkHnVTvm6Od5nnp/Qz2Lw1il+AtgOJ UO2WlWEILwrTrxFEUQPtKcp2R3ZyKvGAktqwiJMEx+mlnbeavtRyiq4kUSBBiuVDRg5/ jtoV5pnrzqYaHP/2Ex/cQB9QnIeN3zq2KOpSX4MR80M4kdxOVAWd4Tt5u4jtFajw5QWd v6MCweJFr7CAwUr2g1r4qe/og5hMaHzWypDTsintIjJTYWttSWDIHgqYrSKG841m/fnG zYMQ== 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=3o2JXqW0AezqVSO3QF8ouikoWZl2OLe3hNGl1g3whA1s59Dzb0d7uC98HlODySGgzv KXIXffBVU1qOGZ/ugjHbGkXhg+/MV+cUppiuQBumd90AmMCVaH1HlViZVnlWgcXrO27+ j/b5GDK5wvpkygw8Ku9Gr6LaxtcZ2jKbQQlC9rd7aPVJJB2GbYVcMoLlhqE+jz8YMc1/ b5wUu0cIbn8xfEO0Q2S2NHGtgG5dYiSYjEM9AV77Ahj2los9HynQu9ouovvLDFL2kchk HzWuE+tX5gupjHTEsksgBwlBEf0y8/iaDffYOF+EkYcPCZnQb6r2iPgZzN6ow55WWoZn Uxtg== X-Gm-Message-State: AOAM532NMannBBTexyRADY4TJyjR0nBIClJ2dQskclsLqLF04BDKFt/D q7pzq64eVmltqxmriLedAS+k8g== X-Google-Smtp-Source: ABdhPJzBJhd2BrrH13cjClJSpD9eKt3Bq+FtJpQvAGc+zfqBSWAgY3ScNVoHesZAWSmLf0vhy2Fmnw== X-Received: by 2002:a05:651c:327:: with SMTP id b7mr4963654ljp.85.1635237106519; Tue, 26 Oct 2021 01:31:46 -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 e4sm1944598ljn.131.2021.10.26.01.31.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 01:31:46 -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 v7 3/6] tee: fix put order in teedev_close_context() Date: Tue, 26 Oct 2021 10:31:35 +0200 Message-Id: <20211026083138.1818705-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211026083138.1818705-1-jens.wiklander@linaro.org> References: <20211026083138.1818705-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-20211026_013148_642634_7363984F X-CRM114-Status: GOOD ( 12.39 ) 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)