From patchwork Thu Nov 4 13:59:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 516798 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp1962492iml; Thu, 4 Nov 2021 06:57:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjrJTb25vnfh/C6Td0e9jJDy53EShGfQTe56DBbKt3r8k/38Cb9pG0bbffXhRwzz2UGiei X-Received: by 2002:a50:e089:: with SMTP id f9mr69670690edl.290.1636034230198; Thu, 04 Nov 2021 06:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636034230; cv=none; d=google.com; s=arc-20160816; b=CThKirehaX1iWnMzLDQQNQz/n1oQr7Ph1UIZ46GHI9i+Biq7c+coVOyrsg41l7jk2A /9Jgfs5jRvlkE4nZEHEJcRBx9waAlA0WnIvrkJnLVo+tCkM3skPqZ1Soyd7J7CW0jfla fHe/UQQ2NsrojYG4swIfggyB4Idp4vRiBdJh9YyqxQjHSEXvqc9M8YbDlUdSqz1uTeOW Zf3iOD490H65PuCD3Rr8x1wgcwj81AIe28C6W1xVmrG+jhCgnl+WkY+DCQBuoaJJhAMQ qsg+ymEFfGu+Kp77rxZnR7fgokcwCNyJfpNlbqfdp+w9sSjrtygP1mZiuycmsyy8/pKX pPXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=9gDXGGx2/ZBNTqakch1HH+kUGPemZoUK90L7Bruty20=; b=CzzmOsJJ4kS8BFRam1owNRZYf+VUM02yyNCthhxYRr2m9510zJbJ576ppEBndsBeg/ KXbpAgF9TqdWA5UjhwDVBB9X51r9LbpBxRRGPElNPWPua2NUM0ujjCXOXwCo5UEF7FjJ 9pTp61vL4D1zJkARlkfDhbSWFiGx1fabsHoHbpfcZ/1e+XicDJW4qzfpoD2Me4KE86w6 lKbWl2ND96AUd2N/X1fRCuz53cLfv/hdwbMhoiPTKjJ95GkI0AaCFok0ELcB+vF5ge1e STHfJ46NF3jmKBiy0bYt1UIVxXq6qxpyJXf/H+9OASY74aHTxvjAPGRiSLPQbhVN7J52 Tqqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wypSD7Vl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id t12si8269448edd.590.2021.11.04.06.57.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 06:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wypSD7Vl; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6D075836B6; Thu, 4 Nov 2021 14:57:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wypSD7Vl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D804183661; Thu, 4 Nov 2021 14:57:04 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 583F28320C for ; Thu, 4 Nov 2021 14:57:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62e.google.com with SMTP id t11so7287034plq.11 for ; Thu, 04 Nov 2021 06:57:00 -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; bh=9gDXGGx2/ZBNTqakch1HH+kUGPemZoUK90L7Bruty20=; b=wypSD7VlFvhl/qrMx7Thbr7QF6ob9tfH7RtgR8ZA9aZKAFnn/EpRuMgVbPG3tAubay ZPabrwBcIyXOm78+oE5CXMAdfvAoSfogxZrRhaxb7QIpG0rk0l9nhVJMC8Fn2fwjfWc0 9OZwjld0eCYUiw36y1REGfeZM/cq37CVyJ1M1pEjWmVfdaIDNIpj+Lp4jBL0fF/E3N6s Qkl2FqxTRylcFtoFrHHySoqicM5IjSw5oTQKlYZWHAFNWOHWjQ17RHBWimH3ynYx7DPx iqhgYjmhCEiQ6UjkE0pXbqT/wuLhZhUq3rhkxZtPiTG0Ij/D0RS57Ic4hxsaLyzVikHe s6pA== 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; bh=9gDXGGx2/ZBNTqakch1HH+kUGPemZoUK90L7Bruty20=; b=cumFAu0UYqoGmeW+TTndEIoA4x1tJYpFXHYfbvBYgnLIxSHbxullNiZnvDO2iT3HEw GUym6BPlwUkAAwH6bKO5rPbxOk2OxHxQnFeabpof4r098kLJ6ZwLiUqX4jt7tgGManGx D/e/7Duy+kyDOZ7MaioYfmDOfcSr1F8JViXKhlNGOeZfN/r7XiosUk0C6+KmhqeEh/5B 81A2s+cX6FdAJeooNavGmUCz4Zu9Rp/Lk4cIGqnEBc+XQn1ZC0KYgI2po144CRGSXKj7 ++PysRmDIcY/lQK09OIQaJFWUC3FNFydLm65iy+GICNgI8zQdRbKiWkYFpSmqlnCzyFX igmw== X-Gm-Message-State: AOAM530G711vU5D23WUUCwp1KXeJCZgGqBy9qPlNGr72UkDTHAUNk73D jfavoTTGd2KznY/RNEdqSPshQsC5xv32KA== X-Received: by 2002:a17:902:d2ce:b0:141:f710:922 with SMTP id n14-20020a170902d2ce00b00141f7100922mr23040388plc.7.1636034218278; Thu, 04 Nov 2021 06:56:58 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id b1sm1673364pff.89.2021.11.04.06.56.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 06:56:57 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Masahisa Kojima , Alexander Graf Subject: [PATCH v3] efi_loader: add EFI_TCG2_PROTOCOL.SubmitCommand Date: Thu, 4 Nov 2021 22:59:16 +0900 Message-Id: <20211104135916.23532-1-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This commit adds the EFI_TCG2_PROTOCOL.SubmitCommand required in the TCG PC Client PFP spec. SubmitCommand enables to send the raw command to the TPM device. To implement this api, tpm2_submit_command() is added into tpm-v2.c. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- Changes in v3: - use ternary operation - update comment of the tpm2_submit_command() return value to follow other function comment in tpm-v2.h Changes in v2: - return EFI_OUT_OF_RESOURCES if the recv buffer is small - remove unused argument of tpm2_submit_command() include/tpm-v2.h | 13 +++++++++++++ lib/efi_loader/efi_tcg2.c | 38 ++++++++++++++++++++++++++++++++------ lib/tpm-v2.c | 6 ++++++ 3 files changed, 51 insertions(+), 6 deletions(-) -- 2.17.1 diff --git a/include/tpm-v2.h b/include/tpm-v2.h index e6b68769f3..ceff7d245e 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -642,4 +642,17 @@ u32 tpm2_write_lock(struct udevice *dev, u32 index); */ u32 tpm2_disable_platform_hierarchy(struct udevice *dev); +/** + * submit user specified data to the TPM and get response + * + * @dev TPM device + * @sendbuf: Buffer of the data to send + * @recvbuf: Buffer to save the response to + * @recv_size: Pointer to the size of the response buffer + * + * @return code of the operation + */ +u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, + u8 *recvbuf, size_t *recv_size); + #endif /* __TPM_V2_H */ diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index ec20530b6b..a33505bd0b 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -1033,13 +1033,39 @@ out: * Return: status code */ static efi_status_t EFIAPI -efi_tcg2_submit_command(__maybe_unused struct efi_tcg2_protocol *this, - u32 __maybe_unused input_param_block_size, - u8 __maybe_unused *input_param_block, - u32 __maybe_unused output_param_block_size, - u8 __maybe_unused *output_param_block) +efi_tcg2_submit_command(struct efi_tcg2_protocol *this, + u32 input_param_block_size, + u8 *input_param_block, + u32 output_param_block_size, + u8 *output_param_block) { - return EFI_UNSUPPORTED; + struct udevice *dev; + efi_status_t ret; + u32 rc; + size_t resp_buf_size = output_param_block_size; + + EFI_ENTRY("%p, %u, %p, %u, %p", this, input_param_block_size, + input_param_block, output_param_block_size, output_param_block); + + if (!this || !input_param_block || !input_param_block_size) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = platform_get_tpm2_device(&dev); + if (ret != EFI_SUCCESS) + goto out; + + rc = tpm2_submit_command(dev, input_param_block, + output_param_block, &resp_buf_size); + if (rc) { + ret = (rc == -ENOSPC) ? EFI_OUT_OF_RESOURCES : EFI_DEVICE_ERROR; + + goto out; + } + +out: + return EFI_EXIT(ret); } /** diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 235f8c20d4..2e7b27bd6b 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -659,3 +659,9 @@ u32 tpm2_disable_platform_hierarchy(struct udevice *dev) return 0; } + +u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, + u8 *recvbuf, size_t *recv_size) +{ + return tpm_sendrecv_command(dev, sendbuf, recvbuf, recv_size); +}