From patchwork Wed Nov 3 09:02:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 516727 Delivered-To: patches@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp392898iml; Wed, 3 Nov 2021 02:03:04 -0700 (PDT) X-Received: by 2002:a05:6512:3d0b:: with SMTP id d11mr25499622lfv.481.1635930184190; Wed, 03 Nov 2021 02:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635930184; cv=none; d=google.com; s=arc-20160816; b=qJsm1QbM5t/iq8L6yxMjk7/8LGgrDIAY0Un1hRSNKZpsagxVjhSy1D7M+4unJsKGEs 6fvUBpwHthyCu9vS1PMCDe6dGQMOTHM5RjrHu3jzzGzq2lr9lsk0J/62kEvdozhn29e+ F7qLu4QoXdgFNzZoK2jhi+7JP5mbjyYQCA2M6uG0KFZoudjSooIXECUJgTNqKH2CK2J5 4KbfpxB48ui3qkBkkai5OTUnhG1z7rsKFj+YZwJKf2BExpEkwVs5HCHCWCIjPPSwcm97 oFCzUpeb2qcULDO2bcAXx49hHghn5/wK2T2bJSStZ69h294pQsmvzo7JMvpIKALudmE3 eBrw== 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=wDFhL54jBz3G05V/OraPaakr11gEhiPI9haVEV4Ys5E=; b=lkqD0dCMpcxgmd5E6YaBz2/PPuFB0lrcuOctUByWEb+iL0Smfn+TFC1Dd9MLBVSNA0 n2jisaSVue6VbaZthXWiIQoAGZ4OLslhGdejILs6R+MBuqWrPYkjkubx4n7scGVOcMNP tGk99jmcMc1iS4OCDMzNpu/ukZn83sxBJnPl7Pj1GtF47Zpo/TYgrESi1jzlO2dMWBTq lr7RE+db4k3VufubaXtoONDFRcXhV6buPBYqlFN24xPwNZMS/e/Qh060vRY4sZc2pu+j +i0bGPfZxKAHDDWPG4XXPJ/hs7x2Iy8Ce4sq7MBVRVGOuQYPsKHDHJ/Ax844EiVu7G10 5/xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JrbkOJN0; 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 a6sor745598ljq.29.2021.11.03.02.03.04 for (Google Transport Security); Wed, 03 Nov 2021 02:03:04 -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=JrbkOJN0; 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=wDFhL54jBz3G05V/OraPaakr11gEhiPI9haVEV4Ys5E=; b=JrbkOJN0AVTm6aU03vDx3RA7J3nBQq4dZa143tOdEgrSo7btHpTOx99WIZ/Ux9cVAI P4y1XDNIgA+r0IulEXK4zuoXLG5PAPr5bc9n6widMRrpCG+vIrQIkNOlIimZgXPkgsZq tG7os6N3rCTTTlwnplk24JpP02zL/aP6hFgKgtJdb8kmF/yM/Qxx10WXQz4GSsXcuH76 OXlNleVoGGpr1KaXJdrMvws8NoRfIoxTcPVYbHGHSkTZUC8Pt+WzWxi79zukB3Swp+SF 1Ul/eZQRyUinBps9OsfaaQrMNS+AwOiskYcVb9gyowMOWDyGhF6wBIHTH6mjoehruamB zyzg== 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=KJZH9P7iZRyYNHSjBQ1kklSQRvSSZshgqJZmo0WT7UKlRYBHUOeL6qQFnr5SiQsSHj 2EL8ea7y+b5HI6HG1ncZmDBv2XHftakV4gDsiFWsSD+Y2nhT7ahXVmJSgRSnkiABXI6+ O8JOFOfjCEbSDUf9i26iyrQIz2O0alXAK+ySsDqkaq+PNKVecoQ9ubt2qcTTa2Xy+HCe s0IxyIbskwk3PO3Zhw8tXUXnFKmM0wVFFP37xuHHJHM216tELt00v5wz0mcdnPNxNhAj g5HP9k8w+Z5qbOSq4vL2jwJiREsWdHN/2xuzx/R76jqaO8dNtt89/O8Ps/skocFlUl3V 9y1A== X-Gm-Message-State: AOAM5324Qg7KR/6rKOu/DbrZnhnrux3peMpM/AL3wGIUO7Tq8mvf3Zwj vJ6VewHQFJDXKWH6xMI4q3WN0Nmh X-Google-Smtp-Source: ABdhPJy2IrqOF3ogwb+7EqZn1rFu3bhrk8vJtGRNZ5plknFzvRDWYEdyK53VxBLOuXPASCA5Skn+bQ== X-Received: by 2002:a2e:9e13:: with SMTP id e19mr45531615ljk.494.1635930183843; Wed, 03 Nov 2021 02:03:03 -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 w16sm124373lfr.233.2021.11.03.02.03.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Nov 2021 02:03:03 -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 v8 3/6] tee: fix put order in teedev_close_context() Date: Wed, 3 Nov 2021 10:02:52 +0100 Message-Id: <20211103090255.998070-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211103090255.998070-1-jens.wiklander@linaro.org> References: <20211103090255.998070-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") Reviewed-by: Sumit Garg 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)