From patchwork Tue Nov 2 05:48:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 516610 Delivered-To: patch@linaro.org Received: by 2002:ad5:5208:0:0:0:0:0 with SMTP id p8csp4139127iml; Mon, 1 Nov 2021 22:47:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSbPKNjHTyX/2eh+dK/itE2UZkFqqHRQLUtU0pF0s4J/xY8/6flzxJdb311mLfvMsrfX/P X-Received: by 2002:a17:907:7ba2:: with SMTP id ne34mr42139485ejc.506.1635832028042; Mon, 01 Nov 2021 22:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635832028; cv=none; d=google.com; s=arc-20160816; b=LwXB6AmIQwWMTvajAizgbA3t5UKhh9TPMGto/VvwbPqWa81mwSRdBpNnH13oAi9Qu1 4JL0L1W0yjhYWaHzRbHY4/lFvJUgU+j+pFyh+gnAFxNJsHOIuHun+1NRHspJLXw7Xov2 TgvufqZU9wdqR3It8EEF72eQzp+QOJ+rz0SjzRhJwCEhE1reMsJiyIIkkYwMmzt7mm/i Z5ndSdWixtoMXhpJrodlqB30DiUZBIr851oFNf3JrZcL1Vvy19InDMA3Lg2CtfSzrKnD zN/kP948Mr2NMWw/Minv0+PA1/SRz9hzGkwrQUjv6oBL8AV3cTJCnsEu6a8wQefJOUVf BZvA== 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=8tHVQPyJF7nOh2FMPPUAU2dT2RWygTVS3AyRLJDvUv4=; b=kM6gTO2r3ZZ+p/MULqz2tuefWJyFMUkqAzFCvADIO70dg4sQnJed/ygc3GNnKJs2lS M+otqBfQHsiUPdGEzuhjEqFmArEhL06A4DiI/osxS5SpAwJt8YGGMLoqMbW8XCs5CrkG V2QneOjCLTFdPw6IudM4zsUS87z8/3O53x6U6DA9Gg4YjL9EBwbUiJxDpLyTCLSYSohc AWoNS+cDMp4uPFP6QTonG6XRNWwpi1M9aQV2fLvCgMhuvCdj2Lzcnu1aYeJAqB6HoEh1 cicuprKzePTistiJnjLxaB6WDle7jNwcZVZjSAWWzGe7q4xMVfo7sD/D2WVgIq+r4oIX Wm5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kx4P5gpb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id hq30si16068578ejc.87.2021.11.01.22.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 22:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Kx4P5gpb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 749638352D; Tue, 2 Nov 2021 06:47:05 +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="Kx4P5gpb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0A0EB83535; Tue, 2 Nov 2021 06:47:03 +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-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 63B7B82127 for ; Tue, 2 Nov 2021 06:46:59 +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-x631.google.com with SMTP id y1so14267837plk.10 for ; Mon, 01 Nov 2021 22:46:59 -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=8tHVQPyJF7nOh2FMPPUAU2dT2RWygTVS3AyRLJDvUv4=; b=Kx4P5gpbWQWxb1QLRbIr052AxuXRR59vrAG2O7kpqLznijOtVYVw81xwrLAsC7D92N 1Jc8MF9ARJgB0AqDtBvZqCnKb3b0HZyWoHzQ+TAKl8QUURWcmBI4HffUXyFETs4gM2ok MpWdv2mn78JtxuVylrD5K3qCu1hA7+dWzWCjK5bSRYSidsthyxdw11Uk8xwCjs87VflN EK3FdyMjGsI0DLTaTcObtIUIn83hVd2z1iwjpuQi9SukGO2vCI4okQOyOsj4y8PRXPRa cLHRxXn6JqJlW6kvUA0bIWs5DvOAZmJ2Z746QDFtlr567jidM+21U1q+z7WU/84Jq19y Oqbg== 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=8tHVQPyJF7nOh2FMPPUAU2dT2RWygTVS3AyRLJDvUv4=; b=rc1VoQiTJwWDY+gzdg0JznG6YBENQ95NzpmwNm+8fnfskTdjF9ka2Oqj0uQaL7Qn2I m1ZbXqfOar/x8ekiVLs++aeI+ksWLIGxmbSy7N3afbgC3laVD6gOzpIrYX3L44RWYzJ2 eYTS5bKz/3TBby2fumFHHB7inv2QJN/+KwF9Iq1mwSuIppB7OHaYQVIxKGhMqBEq9zfQ GJGfFgSNFp1OF/iEJYy/UC7VFs0zuRF3nu4ZmVnXdEe/ZFB43Lnky2z7vfD58wHG2JPu a9cjqME4obRBS+2sbp+c9uH8KlbUJ/TiLx9yRKY3vld0SWLEVGWXkRyZ+sn49hww1Q6k z1Hw== X-Gm-Message-State: AOAM5308usTv2qShddBT7jIcdLlFtYxqOE55oJGwKtTOgYCS/ktCJxVa +Vcc8s8/FUr9m/abbLtCNoZtrLp5wcZ+1Q== X-Received: by 2002:a17:90b:1b06:: with SMTP id nu6mr4057936pjb.155.1635832017555; Mon, 01 Nov 2021 22:46:57 -0700 (PDT) Received: from localhost.localdomain ([2400:2411:502:a100:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id g3sm3966663pfv.195.2021.11.01.22.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 22:46:56 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Alexander Graf , Simon Glass Subject: [PATCH v2] efi_loader: add EFI_TCG2_PROTOCOL.SubmitCommand Date: Tue, 2 Nov 2021 14:48:52 +0900 Message-Id: <20211102054852.11235-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 --- 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 | 14 +++++++++++++ lib/efi_loader/efi_tcg2.c | 41 +++++++++++++++++++++++++++++++++------ lib/tpm-v2.c | 6 ++++++ 3 files changed, 55 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Ilias Apalodimas diff --git a/include/tpm-v2.h b/include/tpm-v2.h index e6b68769f3..39c8c0897b 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -642,4 +642,18 @@ 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 + * + * Returns 0 on success (and places the number of response bytes at + * recv_size) or -ve on failure. + */ +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..cb67006b14 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -1033,13 +1033,42 @@ 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) { + if (rc == -ENOSPC) + ret = EFI_OUT_OF_RESOURCES; + else + ret = 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); +}