From patchwork Fri Jul 23 09:44:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 484595 Delivered-To: patches@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1161689jao; Fri, 23 Jul 2021 02:44:34 -0700 (PDT) X-Received: by 2002:a05:651c:1590:: with SMTP id h16mr2747930ljq.147.1627033474072; Fri, 23 Jul 2021 02:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627033474; cv=none; d=google.com; s=arc-20160816; b=CzDnS53LTfVQQwyYRH3hewDM/3dN1O3iUu2gSpDRoA0+/pHkOvlconfmicEr9a61cW ihktpCDYh8lBSJhFEJUrHcOTDIJle+3RuDIcRpcilYANkt0aWa8m6XTN7zznxDBATMSa 8XkxcYn9gpr+r9Y2ojN3pdUspQ6tmcQ3vbv5qkVWPBR8qRptoFNYJPmWym4z27bw42OS LZeVQKlmRJetQ/xtlsxO5+9iex8tOTElHRfd5grW4rKbTpO+AZxhiK4QP5/40u00cAyS 55upJAdzm5Uy58UC0DEyIxyYWuh6nE+7xvOF/WpKDHHkH783OlNtKyFHWkQRc5rrekZp Kqyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=JoodeoEbWA8KFPSDaqBt6HBmf+JeOe0hbWt7ocF/yag=; b=T5v3TRC+SPWDut9/DXy9H7vCvgi29w/uZdA67Y3TZbaqcl2Xs7UiZZxaUckrzdA2qg 5rtuJ1BHmoCQIpIKmsw9UTysaZ552AQWqkAL8VcJ2mU8wq77s5YguMErdJEpfp+E7F/T LBesMrAagL6OIT2bwGuICU1Dt/9SYySSCXJ47LUHSl/0/HRo84+gMcFArL2QgTVcypMa rOFWVyHlc5YDu/hg5tW+dOGTOmMU4B59bN73NHbo2iBt1KWdZYiw2UKTmzPrfwj6xdiU K8opxcb4W63GLj3oQw64Qjni7+wo2sG8F0heYfHR/8n+R4tDjAs2vE2R50/lkr79w2Rt yeCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQupQu09; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id k10sor4011301lji.5.2021.07.23.02.44.33 for (Google Transport Security); Fri, 23 Jul 2021 02:44:34 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IQupQu09; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=IQupQu096dOf2RXy1dTEeXIOMGbe6WjJhcaIEXhbvkmYHJXjdMb0znsum0XkoEfm0b oZAyT0no0mbv1QNkEJCIL8Ycp+A2wxAnySr21P6vwmTnbM0x54jAaRuSlsmJSsk9KvIc 3+lzExnUxYmBgMM6D2awrRdlxwmCx0eFrn77sO8iolEDUBqktiTOwi+QBv6ve/3SK65f welVLkY/7gXxj/KGu52/SQBYzf7iXLxHHs5Ovc7izB3FaJhmLEwKcyT/7PTU41IsPpqu XvEPhAOHUMGRifagj7+ZhmEkZsJdF9rYyoUuXIHuqVnL/DUQ4h6w1oeymhdrXUOT6laJ 6eQg== 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=YkMKH06uWg/oKuobZmgsiIBXYBARZcbbb9Gkw4yvHIrDNqHsLbNxZHgKY59GJGocOc gwI+/dlbU776FCz5DbX6wtp5QV1RhEvSNXDSBA7c8ZZTvPWMlAcHrg/S/xg49znx6wHi HQnP0fWw6jcHJ510NrWHQeO5NkRk8GiaMUAy0XfpJSUt/eXMFvo8HXBAz8h6urUIL9/x WyLKVbXNfiYmzmLJUxnnAabCBlDevReVb9MZ7Ggdhn9NLBFN3S09M6PfkJiL6idB1ov+ OpMbHsY74/hqdb/f2EM4+yFozYdiYmBR4N2dXI7tCf540+htDjPVGfcT7NBSga9gHQO2 W0jg== X-Gm-Message-State: AOAM5330Mqj4vSqEJDtEmfNIwSDVB8qdJN2jVzpLni+nFmZquA2ewLRe pAiWtYbF9PXVF6jwlF1Yp+7PSo6n X-Google-Smtp-Source: ABdhPJxthOMwVWH+D74X2QymqEcjwWIzgiPvVu2K8kpmy+fsoCGXSl6heRTr6xFDRTRKY7MJE5SvuA== X-Received: by 2002:a2e:9b10:: with SMTP id u16mr2747522lji.228.1627033473706; Fri, 23 Jul 2021 02:44:33 -0700 (PDT) Return-Path: Received: from jade.urgonet (h-94-254-48-165.A175.priv.bahnhof.se. [94.254.48.165]) by smtp.gmail.com with ESMTPSA id f2sm403808ljq.131.2021.07.23.02.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 02:44:33 -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 v3 3/6] tee: fix put order in teedev_close_context() Date: Fri, 23 Jul 2021 11:44:19 +0200 Message-Id: <20210723094422.2150313-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210723094422.2150313-1-jens.wiklander@linaro.org> References: <20210723094422.2150313-1-jens.wiklander@linaro.org> MIME-Version: 1.0 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(-) -- 2.31.1 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)