Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp380741pxb; Thu, 26 Aug 2021 05:32:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6CJ5ZAYMqjpS97ddn55x6pY9gah0t9RCNmcm76lB0qCqeyjWQRGUgezL944QN9/+iqn5G X-Received: by 2002:a05:6602:1493:: with SMTP id a19mr2759134iow.55.1629981134194; Thu, 26 Aug 2021 05:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629981134; cv=none; d=google.com; s=arc-20160816; b=Yy5RsSyfwRuO8785gOtUtSpT5mcAZ/8YzbErIjN8lc1KMYHasNKtGXI8ZtU9vtjOLO ePsEzoSkEX8f/2N+lmh9BoclnvI7Bi9FKY6573T3nEU+frIjF7aP1hKAOJ/3wAYcIL28 mzX+bJKYe0/rZ8wWFb0VT0IJHpErXJYMUEXB4w/9RfXFfdJkySHYU2lUk4wIE4eXRNnO oH3H73baPFGWAnmdiLmibfjz1lzVUaDKvPb2pTRlZ7AjZZg4J29UhccWD5fkR7wsBQOt 1MitBJYNQoWn0XO/wUB0D4IUvsmdEW5nWGhQlZ7uVx03RIp+jbfLsJ3/qXKQY3y1vcY9 vCKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=JOQkE3M5/FOKRKS40rB3a8jfKPUPRgskKkb6xv6yoxEMhn2GpFqCHCAySSUa0OA2Tu 3NmjHRan/TbR/HXSZaqPUHuecY8528ItIsglezrsUqS6Kqy6DE7rVpd2KF0kAX5TXtuz i6X+J0/+/4qZBNVDwJXcGqL7lyP4Lil7x4DNjMoJQ5lVjvSvlf5fiZDb594/be8QNV9e 5g8tlqLhTgSehJYw3YPCiRp7TPruWynXeDuLazJXhHq7k3TFCHWSYOSTGxx5wnmd/s1V SFCONNIgRyiRVSW/GqFLhA947EF9uhMuNjfD23RD/tuh29ss5S6l21DsLHbUxd2a+JxU HElw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZMisyRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si3355963iot.103.2021.08.26.05.32.01; Thu, 26 Aug 2021 05:32:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gZMisyRD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241859AbhHZMbf (ORCPT + 99 others); Thu, 26 Aug 2021 08:31:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241261AbhHZMbc (ORCPT ); Thu, 26 Aug 2021 08:31:32 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3CA3C061796 for ; Thu, 26 Aug 2021 05:30:44 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id i9so6442354lfg.10 for ; Thu, 26 Aug 2021 05:30:44 -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=gZMisyRDxgH5gaSMdaSrLWrVBgnJiieFFNBcmjDx33BBp2VM2mCTz9s8UTZi7/BJ54 pZgn93V8Mcb9S2QKsXTdwwOL7O1KDzQUt56MI1ztVplj6OREFy7JveICkKz//LHg2619 TqP9/aqM54aR3TctwTgrQdMcHL7XKWQ40vrUjM4eQthXogUG6POhttFg1AzilsGCE99i 9NRja4Jhksy+I5wQyzEaxpej5QAm8Cmh03E9KSgFIEpKAkOXKTnytB9i1hD/DBRWcqN0 eOpZbST42OrMEzQxDVHyfPLETKwSeUcLfBOzZe97pbX39jafv5Gh6/x7LdtRmWVmB37c pJag== 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=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=dUXwLv7AyimRqEsIFwrY5x93zYIPktMXK+zxRov5nWVDBCpfo/ZQV6ZtYCZ+qkUVcC LG9a/nfLpc8Bpv9/5VX8YBsQhoDw2p+BJEeqMD1fI3wltZzOGkxzC4IRxglz6H5KMWld HJUoWVs2rJ5JWRwk0XiRVL3ziasDfxvNIE4Se/RFSBOxZkZvjUktmn1NbxnCLv/VLWzp bJp4+6lEnJ39qL5CrIB2nG9m0eeatzODBPLLxowGDFhPV7gHm7C1VtHyvi8NUcV1DVaW Ts7uPTh23OdRuZwQL/HI44FokV5kNag9UqsfBUMvrDax6YQrj4I/1E6XAWnRDEIgfo/U amAw== X-Gm-Message-State: AOAM533yWYOShbh425N1tRj5/boOk4K7ReHVXWMOASNMrm7gEV2YdyYH rWOMcqe8eSQDdfXpxRC+3qx2dP399yWLbg== X-Received: by 2002:a05:6512:ad6:: with SMTP id n22mr2695207lfu.532.1629981042914; Thu, 26 Aug 2021 05:30:42 -0700 (PDT) Received: from jade.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id j21sm332283ljh.87.2021.08.26.05.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Aug 2021 05:30:42 -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 v5 3/6] tee: fix put order in teedev_close_context() Date: Thu, 26 Aug 2021 14:30:29 +0200 Message-Id: <20210826123032.1732926-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826123032.1732926-1-jens.wiklander@linaro.org> References: <20210826123032.1732926-1-jens.wiklander@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 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) -- 2.31.1