Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1211593pxv; Fri, 23 Jul 2021 02:47:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcrj2NPgrYdGWtdIjJDNhqp5Js1iYBtaDppTcpTjZ4Xf/klHLHEZhXRdSg0figZbZx+EeT X-Received: by 2002:a92:d8cf:: with SMTP id l15mr2910537ilo.227.1627033648465; Fri, 23 Jul 2021 02:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627033648; cv=none; d=google.com; s=arc-20160816; b=jHVMPIh3R8F8mvfg+B+BLdQH/I1jn/UeJQpDqa7u8ghRIvJ6Gn8OwjZ89dfaSnUXgI A2hmD3RGP5KYofLF0wSqsUQak2IvpT+4Ype9hRXWEghuIgEHsEalzSk2WsxofWXu/EC0 Vj/Jyw6ojUbTNtRr6f+LysUwfH0f+5koPjbRda4cL9qMxFZv9zFCwxXjPoCy/5pLBvYY fWKFfkAFpdea0jYoNrpO0qIzK8YDOw5VkJYd2ZTE7UnCwY5nUC9gIMxkyDVvy5bRurFr 5FS83rhyU+GS2UPcUzsf4s/ra2cJ9gD+aZDQM9sYvhyN8c3EVaxlNHm1CZUk1+9Scnkq Si5Q== 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=Hggo38v7eTGK/6iSrtvtP47fg+mMdY0zerO2aSlkH5oUGKv9nQ9yu0fx/Uap6Hr//2 jVDUD8dPjUW0SqwPjVzkCort27EtMo7akAU974pi5LHYNdYHYaVSYOJ8/SIy8IMMlq1A B1H8ol0rqHSbxjGhISxsG7fzIxCij5/DEEaL7GbZfE1Fn/nO1habmF2amHDeU5Bjjv7y I/gZTWjE+EJhAsIxy83FrlZcCekc/6+aGcuO84aiU3nyj1YmMKQWqgBSjH7OUO1Z23tu vlbqXGlkijnGBPWgcgrQ0Qloq3U7y3PtMK91TXj87atHU3eTJO+hGFJ5EHtgL8DqpvTq fJvQ== 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 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 p31si36816333jac.95.2021.07.23.02.47.15; Fri, 23 Jul 2021 02:47:28 -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=IQupQu09; 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 S231542AbhGWJE4 (ORCPT + 99 others); Fri, 23 Jul 2021 05:04:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbhGWJEC (ORCPT ); Fri, 23 Jul 2021 05:04:02 -0400 Received: from mail-lj1-x22c.google.com (mail-lj1-x22c.google.com [IPv6:2a00:1450:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF40C06179A for ; Fri, 23 Jul 2021 02:44:35 -0700 (PDT) Received: by mail-lj1-x22c.google.com with SMTP id h11so933480ljo.12 for ; Fri, 23 Jul 2021 02:44:35 -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=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=otAJWy4gRNgyKFbqkQo9DvNkJKTw/sa0gt+Z8zYCB3cuICOLwuJRRWpvrSMhDZviDj zLCG760rBEYWABJ/jfFhu9t3NYZ+dlpKPWu0m90o/bqCtS6U7OtlTr54x20MiRfylL7+ EfRZaxfFRRiZtAwpyq0FJZweQRjO7TY3aT4aj1uwVC0zDQdd9J31qXQLCVll9bCp9UhP T252RMYWawM0RhwLHDrIaxfP7c9zq7O7Uz/n53sTqag7q9gLG1yVj2+HM9exJsyoO9Nn 0CNa+LiT+PNjmIElrwjn5ImVPE3JiPEy1aCnLKu+OZBd3c+7XWM3tRtau3QtXKk0AVZ6 nIhg== X-Gm-Message-State: AOAM533GMJlVoWhGCf+hivXe3cMQsKmO5J6MDq3n0QGd9dnm65OwSElb tBnwcGpziRm6ppxedA92Oxf9JCJylUhizFjU X-Received: by 2002:a2e:9b10:: with SMTP id u16mr2747522lji.228.1627033473706; Fri, 23 Jul 2021 02:44:33 -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 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 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