From patchwork Wed Jan 25 11:39:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 1731662 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=W3k50qca; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P221p439Bz23gM for ; Wed, 25 Jan 2023 22:39:40 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 09C3B85615; Wed, 25 Jan 2023 12:39:29 +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="W3k50qca"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5982885688; Wed, 25 Jan 2023 12:39:27 +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-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 09A5C84EEF for ; Wed, 25 Jan 2023 12:39:24 +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=ilias.apalodimas@linaro.org Received: by mail-ed1-x531.google.com with SMTP id w11so6156377edv.0 for ; Wed, 25 Jan 2023 03:39:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fqqxM+OONfQHliw+seZpRPyYSHaD+WY9Ca/T6ZwZvsc=; b=W3k50qcaKFMtTt6vSxV9kzuPAAhrEDEE+gy9Y5XwgfZdRny7nApHKixAPstua56xIX ebel9B0HXLTx/giMUvNGCD/F53OkjIeIhq1Cvih0yjWaqHFzcLRcfvZSrpQqlzpSKbIf g57tUA+X7VO6UKzVzF0aBL8Mdr8iElfvusoeUEj9GHzXJFXvqZtbW09aJMjMcU8mSl7+ Tvhi0a++YPnP0f0ixjNhDAY/UBlPlcpna49PVXN81Pyel9+RAMI8ZmlktxTZ63v5hDxy JzM744jjqSXcphw5ob40fe52pMssVJdfh5cTNJTv5DpzEzCphXfRD5uETtX4ipfEh4JC m6wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fqqxM+OONfQHliw+seZpRPyYSHaD+WY9Ca/T6ZwZvsc=; b=W7PbiO9JK/wBlqKkf56msW68NZBf+NXlptjuVD8PP92AMBnFR0CG6tNkKa4Vqy1l6u V7skHoUDi3P56Hs+OzR3bk5DbA7Qcr1y0Qzos6gmBE/lSuj6YsX0H3FBWEI7cWQK9Rzi kTynLs3Py5kChrAeHTzoPRvBw231LqAlahub3JuwMItgXRUNvCOMYWaRwc7A6SCWcn7x YkCK2CApZUEegQ5kWh1zrP8/+jGga/a0qho4JjMDvTRJuWtQmSvknCvgirPsZmw5PqLy lg227Bupcq567YWHu3bYao/bQg5NJxArUmWSKYtGnyHDCzpMKuykIjik52A/4Bun2ai9 lnbw== X-Gm-Message-State: AFqh2korTTneX2IIEG5/5VBaY/qZW/EAJDxP+EVHCUWj+HSBQV94Mb0p ozV/6xYLdGcAVM0dEpdZ31+nU45i4qJgCMR+ X-Google-Smtp-Source: AMrXdXvsiQg/4tUL6UU8XJ+lGI98LycA18RuIMccZm8I00dVjY2tkibJMiR9008uxikoDo1O5TkSYw== X-Received: by 2002:a05:6402:2990:b0:499:8849:5fb8 with SMTP id eq16-20020a056402299000b0049988495fb8mr35648123edb.30.1674646763593; Wed, 25 Jan 2023 03:39:23 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:f0f6:e48b:8d50:ecb2]) by smtp.gmail.com with ESMTPSA id c10-20020a056402100a00b0049dfd6bdc25sm2261794edu.84.2023.01.25.03.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 03:39:23 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH 1/2] tpm: add a function that performs selftest + startup Date: Wed, 25 Jan 2023 13:39:03 +0200 Message-Id: <20230125113904.517057-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean As described in [0] if a command requires use of an untested algorithm or functional module, the TPM performs the test and then completes the command actions. Since we don't check for TPM_RC_NEEDS_TEST (which is the return code of the TPM in that case) and even if we would, it would complicate our TPM code for no apparent reason, add a wrapper function that performs both the selftest and the startup sequence of the TPM. It's worth noting that this is implemented on TPMv2.0. The code for 1.2 would look similar, but I don't have a device available to test. [0] https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.07-2014-03-13.pdf ยง12.3 Self-test modes Signed-off-by: Ilias Apalodimas --- include/tpm-v2.h | 8 ++++++++ include/tpm_api.h | 8 ++++++++ lib/tpm-v2.c | 29 +++++++++++++++++++++++++++++ lib/tpm_api.c | 8 ++++++++ 4 files changed, 53 insertions(+) diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 737e57551d73..3013f69a90ed 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -688,4 +688,12 @@ u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd, u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd); +/** + * tpm2_auto_start() - start up the TPM and perform selftests + * + * @param dev TPM device + * Return: return code of the operation (0 = success) + */ +u32 tpm2_auto_start(struct udevice *dev); + #endif /* __TPM_V2_H */ diff --git a/include/tpm_api.h b/include/tpm_api.h index 8979d9d6df7e..022a8bbaeca6 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -331,4 +331,12 @@ static inline bool tpm_is_v2(struct udevice *dev) return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; } +/** + * tpm_auto_start() - start up the TPM and perform selftests + * + * @param dev TPM device + * Return: return code of the operation (0 = success) + */ +u32 tpm_auto_start(struct udevice *dev); + #endif /* __TPM_API_H */ diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 697b982e079f..c34e158e2bb4 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -44,6 +44,35 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test) return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } +/* + * - If a testable function has not been tested and is requested the TPM2 will return + * TPM_RC_NEEDS_TEST. + * - If TPM2 self-test has been received and the tests are not complete the + * result will be TPM_RC_TESTING. + * - If testing of all functions is complete without functional failures the result + * will be TPM_RC_SUCCESS. + * - If any test failed, the result will be TPM2_RC_FAILURE. + * - if the TPM hasn't started it will return TPM2_RC_INITIALIZE. + */ +u32 tpm2_auto_start(struct udevice *dev) +{ + u32 rc; + + rc = tpm2_self_test(dev, TPMI_YES); + if (rc && rc != TPM2_RC_INITIALIZE) + return rc; + + if (rc == TPM2_RC_INITIALIZE) { + rc = tpm2_startup(dev, TPM2_SU_CLEAR); + if (rc) + return rc; + + rc = tpm2_self_test(dev, TPMI_YES); + } + + return rc; +} + u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, const ssize_t pw_sz) { diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 7e8df8795ef3..5b2c11a277cc 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -35,6 +35,14 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) } } +u32 tpm_auto_start(struct udevice *dev) +{ + if (tpm_is_v2(dev)) + return tpm2_auto_start(dev); + + return -ENOSYS; +} + u32 tpm_resume(struct udevice *dev) { if (tpm_is_v1(dev)) From patchwork Wed Jan 25 11:39:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 1731663 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=unVBc2y3; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P221y6Lt5z23gM for ; Wed, 25 Jan 2023 22:39:50 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 04F8385695; Wed, 25 Jan 2023 12:39:39 +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="unVBc2y3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A130C84EEF; Wed, 25 Jan 2023 12:39:27 +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-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (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 6DD9B8563A for ; Wed, 25 Jan 2023 12:39:25 +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=ilias.apalodimas@linaro.org Received: by mail-ed1-x531.google.com with SMTP id w11so6156450edv.0 for ; Wed, 25 Jan 2023 03:39:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OilGK1mftFnUBqVlsIktR0LqPpPfkUMxifI8HXfvKpo=; b=unVBc2y3WfzCpVddd5k5Z6xug9MxoSZSCf1eaImg7y2JIVsQVGIUIRMRjJIJTE0PvW x25J5HEpGV/5fgO2GdE+1d+d0aqwV+QyePWgBFIUv/kELh7GCp3tLPCs4VevedCpt/xL ymS+NH2T5e7Qo1ReuUClv59c8Rktbqgj1Jur2xqrzbme8TgMfLW0gO+2TKSAxN/UmF+8 YHsiRiRMLYBd3hBsQ+jpnQGPzacn5LO0AeSa76aS8nE1u+Qk1HAdBfFAYMipr0vUX84a R/0xOiZMheUm99DYI5Ug9ZV4EXfdB3S/pPCxMnZyPqRmPyMj8aCcqa1W96Isf1FxQwJ5 16dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OilGK1mftFnUBqVlsIktR0LqPpPfkUMxifI8HXfvKpo=; b=ANzoeX3bF+bIe9JBANh74BshTWDk2odKAbfa6eyH9jtOzfhMMIvh08Kbl1gf8oe65a 7wr8SRsor8HzZ7AkYi88uDIHUbJmY5+s9bubo/Efggr0M7zSZPitgnaQD1yTt80ja3fl FtDZ9tszL9qpRVCNhFTN9YQC+AD4aIrFr2zQmRrySQBHzCXaJW1FMLgXnhoU0khadAnc UfJWja1/OvKnQ539mZEMmoiV9DTo6AGUkhOBP45ja7tl/TpjKuSuiuYxYGRkr6XKznoA 5V6E6aIb0mJ9dkU1eUtKE5rfMBBdLsoZK5vdmgvxNnUaPintzZ8+lhshj/j/1NHezxtO BkHg== X-Gm-Message-State: AFqh2kohLJkY4qFiidCVkEpjPeZBSzMAOMBVC7NaC7dq7S1aaIaFSixK NKjBseLl2Dao1YI/Ez3y9oq/j/701HD6kRd2 X-Google-Smtp-Source: AMrXdXujday87c5EMlc37s8bIe3oWyhui1rVhMucnaOnsgKzoRcI6AljFEodHnBzg97MhVwhBJM+ag== X-Received: by 2002:a05:6402:f20:b0:499:b672:ee3a with SMTP id i32-20020a0564020f2000b00499b672ee3amr39865916eda.12.1674646765139; Wed, 25 Jan 2023 03:39:25 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:f0f6:e48b:8d50:ecb2]) by smtp.gmail.com with ESMTPSA id c10-20020a056402100a00b0049dfd6bdc25sm2261794edu.84.2023.01.25.03.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 03:39:24 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH 2/2] efi_loader: use tpm_auto_start for the tpm device Date: Wed, 25 Jan 2023 13:39:04 +0200 Message-Id: <20230125113904.517057-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230125113904.517057-1-ilias.apalodimas@linaro.org> References: <20230125113904.517057-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.6 at phobos.denx.de X-Virus-Status: Clean A previous commit is adding a new tpm startup functions which initializes the TPMv2 and performs all the needed selftests. Since the TPM selftests might be needed depending on the requested lgorithm or functional module use that instead. Signed-off-by: Ilias Apalodimas --- lib/efi_loader/efi_tcg2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 918e9a268641..d035a00d98ac 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -2422,7 +2422,7 @@ efi_status_t efi_tcg2_register(void) } /* initialize the TPM as early as possible. */ - err = tpm_startup(dev, TPM_ST_CLEAR); + err = tpm_auto_start(dev); if (err) { log_err("TPM startup failed\n"); goto fail;