Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3768173pxt; Tue, 10 Aug 2021 10:52:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxG8YUpL/mUzfWPbzW0NVb6xfFwsWa6b0QjdP+Dh9ki54gCv7OLg3Ll0ZSx76BUlIzCvcMg X-Received: by 2002:a17:906:72c8:: with SMTP id m8mr14822247ejl.508.1628617951718; Tue, 10 Aug 2021 10:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617951; cv=none; d=google.com; s=arc-20160816; b=YZEu9Ke6WcsSslUeZ/zSm+aQo8sNGcgum4PWo5eaY08dvQIRBzLsjcYtcxUbBv9/nJ W/parx6ckrtt1mjDN1O5BmDXjMEeQlcZJfmI7hETzTruRkdp9eT19rk/UIJcwSVzB8SB TdBqJxK6eNBK5tkDZ8F4MMWtbNnSK0ZBy+63ykaUc662B7cdQ5hDc4FpGbAOeuMJRuUO 8CU9k2Wy2KFqWw5ZviDEXVLteCfES9xOQUVXiF9+9q9B9tYsUj3DgIVyvYj1+bWEZ2ak rTvxuJ+Lf7lRsnLj7Mmh62iV9Clq7LPS3ebkWnt3RdSms/5vDhFyBwoifZKP23f5tjdd Z/SA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=frZ291rcjnY+1a1NCHu/3Lkpd7xDv4H2X/CVxOQRIi0=; b=We2+dWTiTE81+U/OF/TUA1I6U9ylC8N346Zgd3HK4Suil1gDxcWQE6GEi+oUrwiTza XjFg256EJxtloHf1JxKI9sJt0oIDk2GB4njTYpwwtkZ9R3YxUURNlmqz9Y3F0gSNaFf2 dBXTrQ/O3/gA0sR79I7Yj2vvNPPeV3kYCcltQL9r3f/4gsgkP4SmC2rrmc6NPwOtUK77 E2yD26cLtWYZPqGB76hwCt2tshPvIVmddpriP/Q1ZbWaD1PWQy2Vkb3qM6+Py2+7qZFw bDwfiZiYUhKhwG5RZO3PD2+LIJVl2DKYrHABf7Xjs+ZFvaCCfMFy/CgxA+0zVHIjFNtR SgLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=T5Fceeb+; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds5si9451424ejc.437.2021.08.10.10.52.07; Tue, 10 Aug 2021 10:52:31 -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=@linuxfoundation.org header.s=korg header.b=T5Fceeb+; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235554AbhHJRsA (ORCPT + 99 others); Tue, 10 Aug 2021 13:48:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:40876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236432AbhHJRou (ORCPT ); Tue, 10 Aug 2021 13:44:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 30ECB60EBD; Tue, 10 Aug 2021 17:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617191; bh=SgdEzm93F5mtxhKSIBUxyhXnKpQX5fjHSsZuNqdxQkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T5Fceeb+6y/7ztCowCB2UO14rtnUpKm2YsTJDJQEouBY7Bmer4ZXGhGN39KSM3g4S dKUiM0TyKDLGkGDYN2MwNYOtLLhN6kaRsdFVfaqzjMwnGCNAnbD4pACyabSDoO0Ws4 yhQyLlPFtBH8+xX/ug/KppiGzAfJs3yHV52Xp6es= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tyler Hicks , Sumit Garg , Jarkko Sakkinen , Jens Wiklander Subject: [PATCH 5.10 086/135] tpm_ftpm_tee: Free and unregister TEE shared memory during kexec Date: Tue, 10 Aug 2021 19:30:20 +0200 Message-Id: <20210810172958.668054234@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tyler Hicks commit dfb703ad2a8d366b829818a558337be779746575 upstream. dma-buf backed shared memory cannot be reliably freed and unregistered during a kexec operation even when tee_shm_free() is called on the shm from a .shutdown hook. The problem occurs because dma_buf_put() calls fput() which then uses task_work_add(), with the TWA_RESUME parameter, to queue tee_shm_release() to be called before the current task returns to user mode. However, the current task never returns to user mode before the kexec completes so the memory is never freed nor unregistered. Use tee_shm_alloc_kernel_buf() to avoid dma-buf backed shared memory allocation so that tee_shm_free() can directly call tee_shm_release(). This will ensure that the shm can be freed and unregistered during a kexec operation. Fixes: 09e574831b27 ("tpm/tpm_ftpm_tee: A driver for firmware TPM running inside TEE") Fixes: 1760eb689ed6 ("tpm/tpm_ftpm_tee: add shutdown call back") Cc: stable@vger.kernel.org Signed-off-by: Tyler Hicks Reviewed-by: Sumit Garg Acked-by: Jarkko Sakkinen Signed-off-by: Jens Wiklander Signed-off-by: Greg Kroah-Hartman --- drivers/char/tpm/tpm_ftpm_tee.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/drivers/char/tpm/tpm_ftpm_tee.c +++ b/drivers/char/tpm/tpm_ftpm_tee.c @@ -254,11 +254,11 @@ static int ftpm_tee_probe(struct device pvt_data->session = sess_arg.session; /* Allocate dynamic shared memory with fTPM TA */ - pvt_data->shm = tee_shm_alloc(pvt_data->ctx, - MAX_COMMAND_SIZE + MAX_RESPONSE_SIZE, - TEE_SHM_MAPPED | TEE_SHM_DMA_BUF); + pvt_data->shm = tee_shm_alloc_kernel_buf(pvt_data->ctx, + MAX_COMMAND_SIZE + + MAX_RESPONSE_SIZE); if (IS_ERR(pvt_data->shm)) { - dev_err(dev, "%s: tee_shm_alloc failed\n", __func__); + dev_err(dev, "%s: tee_shm_alloc_kernel_buf failed\n", __func__); rc = -ENOMEM; goto out_shm_alloc; }