From patchwork Wed Jun 7 09:18:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 690182 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp210788wru; Wed, 7 Jun 2023 02:19:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54l68QZJNVlmdKJjQMlnRSjzwOKXJMh67WhbN8gLm3DF0lpRKNKrWUP+YsXucU0VuqP3V2 X-Received: by 2002:a05:6a20:748d:b0:109:38b4:a210 with SMTP id p13-20020a056a20748d00b0010938b4a210mr2924936pzd.29.1686129552655; Wed, 07 Jun 2023 02:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686129552; cv=none; d=google.com; s=arc-20160816; b=aTjBBwX2ryOgpxMj4m0Dew42dKiSNeadMROt0f3kDXs7ogor8KBqbgchx2r4i+HS5b r91pdVAOzHbiHHYuGHDoZHCNSGES48RiA4Wxvf9mHZ4RNgzZCVjqhi42CuQwbpxVCopi wNQVHcuEi3YeIRX92Xp5V+7nx6G8ljuxt+3vZv7Zqoo1DhTdsN3kZtRalrvSRiXtMrn8 +8SvRxgFye2YcDacfj4SpXv1N5zCZvD2T7MzRmHi61cSnQW/GzeZMrVgv29qbdsn2G30 QLl9CuHd4b3+MCXJQUafst5QCnsi5oAlKYww5w9ys6No9herOJjaTJbN2LcZ3aC+0TBt rAtA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rUELE9BmGM3YtfwyXcxh/N24GWahH3YY8SVllWBW9EU=; b=UMGKnuOUzUvOgtZ1kwjHavNsaJWus8S343RgzmaL1J7K9KcXac+mlTiQQDrOqt7fWB GhggAj4bQts6vu4pslpPXP4VG5qxxJESRiEhT2wSPiETXMq95dF79xlCbbMvJBHNCdYB 4KfjHDP8J+Ydr8HYfkWT9fxhzdXpLQQiKSnVjMZFsw82sCuUiSzj3lA31atrcOiL1iHU KSrhAdqd/27FwSrSFzUhmZNHDe7WIrJLzrR2Htzd4CJwXfMyOD+ZzjViQfO94jGuqnuC NywcJZ9gEvu25V+XmRk3NpkQFbzpbnhDI9WIE3TmjVH7DLQw7PsPklI+s08XZFJqIvwq v7tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yDLrJUnd; 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 w27-20020a63af1b000000b00543cac2783fsi3523040pge.485.2023.06.07.02.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 02:19:12 -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=yDLrJUnd; 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 A155086065; Wed, 7 Jun 2023 11:18:32 +0200 (CEST) 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="yDLrJUnd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F4E286005; Wed, 7 Jun 2023 11:18:25 +0200 (CEST) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 70D5C8471B for ; Wed, 7 Jun 2023 11:18:22 +0200 (CEST) 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-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f6e1394060so59711885e9.3 for ; Wed, 07 Jun 2023 02:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686129502; x=1688721502; 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=rUELE9BmGM3YtfwyXcxh/N24GWahH3YY8SVllWBW9EU=; b=yDLrJUndT7iYhKjLhF4YW+wyZ8PS21Yl+Xog5XdAXtTnUjL5zVcSmZw58fqkssJeIQ S7A1zxP9h3sfwoC8GmTFfDs1dysC6OaydimMY/Oav9UauDVifMFQ/a9Wq0AB8HnBr9wu LUNXBw+jYMR0LdjItieJGku/7WBkOPRY93U1P4kf0z1IAcIB4jEVYisvBZhvevUWechm W08ddzb5o6bKruJ+rr5Vswf6qs62AseLMxWA+oDV/75y0U6N4e+IcO8GIH2iDGJ/VWXF kFgn7hCUwL4h7xetdogB6/I1YuR0fAxxqO0+guMH9fsSM3giB8hA8qe6+sGQOsOFXnj5 hLFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686129502; x=1688721502; 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=rUELE9BmGM3YtfwyXcxh/N24GWahH3YY8SVllWBW9EU=; b=DZpEcXoxbUlMyFJ0RlQFdHP63pv9wk7ZyWdVig9a6WHdNe/sDAHaA1j7UgYx/iO+Rp A9v2fKYzgI5nVcT0D7oSK4KkmE1H3VnWYqO2A7x/5ZsTbJ8Qv9Ry51K2eeRPYbT2eBRG KluBZpg9Ry5zgEwLFvLfBAWR/B6pmvZtOqNqGE4nHbuBvtU8IxrdXJQPQx/jkPJjnwvC 8eUXdjcN7I5fmpR9pJv7XsVnI2oaNoWsg1fL/I6H+PKwN9vfrgdgG1JeD+dubrEryCa7 H1MZ1CYF2uycuMQW7KXstIhdQlKdJEuNqpoXVk+2QOMdo3slTmD7Q5fqFyDAfnnGfJYs +pxw== X-Gm-Message-State: AC+VfDzhP6Hb9CMD3thTg3Tso0iRGz5OfTqYxilu498bhK5o+ddFEuI6 xyHtbKk4bNEG2B4FlCkyh6T3bKTUvRoWfK8wX23+Zg== X-Received: by 2002:a05:600c:2216:b0:3f7:e497:a9f8 with SMTP id z22-20020a05600c221600b003f7e497a9f8mr4083191wml.38.1686129501938; Wed, 07 Jun 2023 02:18:21 -0700 (PDT) Received: from localhost.localdomain (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id o10-20020a1c750a000000b003f50d6ee334sm454569wmc.47.2023.06.07.02.18.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 02:18:21 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass Subject: [PATCH 3/3 v2] test/py: Account PCR updates properly during testing Date: Wed, 7 Jun 2023 12:18:12 +0300 Message-Id: <20230607091812.1916435-4-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230607091812.1916435-1-ilias.apalodimas@linaro.org> References: <20230607091812.1916435-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.8 at phobos.denx.de X-Virus-Status: Clean Currently we only read the pcr updates once on test_tpm2_pcr_read(). It turns out that the tpm init sequence of force_init() which consists of: - tpm2 init - tpm2 startup TPM2_SU_CLEAR - tpm2 self_test full - tpm2 clear TPM2_RH_LOCKOUT also counts as an update. Running this in the console verifies the update bump => tpm2 init => tpm2 startup TPM2_SU_CLEAR => tpm2 self_test full => tpm pcr_read 10 $loadaddr PCR #10 content (28 known updates): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 => tpm2 clear TPM2_RH_LOCKOUT => tpm pcr_read 10 $loadaddr PCR #10 content (29 known updates): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 => With the recent changes of replacing 'tpm2 init' with 'tpm2 autostart' we end up always running the full init. The reason is 'tpm init' returns -EBUSY if the tpm is already open, while 'tpm autostart' handles ths gracefully and continues with the initialization. It's worth noting that this won't affect the device functionality at all since retriggering the startup sequence and selftests has no side effects. Instead of relying on the initial value, reread the 'known updates' just before updating the PCR to ensure we read the correct values before testing Signed-off-by: Ilias Apalodimas Reviewed-by: Simon Glass --- Changes since v1: - new patch to fix the python testing failures test/py/tests/test_tpm2.py | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.39.2 diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py index 1ade66a7eda4..fce689cd992d 100644 --- a/test/py/tests/test_tpm2.py +++ b/test/py/tests/test_tpm2.py @@ -272,6 +272,12 @@ def test_tpm2_pcr_extend(u_boot_console): force_init(u_boot_console) ram = u_boot_utils.find_ram_base(u_boot_console) + read_pcr = u_boot_console.run_command('tpm2 pcr_read 0 0x%x' % (ram + 0x20)) + output = u_boot_console.run_command('echo $?') + assert output.endswith('0') + str = re.findall(r'\d+ known updates', read_pcr)[0] + updates = int(re.findall(r'\d+', str)[0]) + u_boot_console.run_command('tpm2 pcr_extend 0 0x%x' % ram) output = u_boot_console.run_command('echo $?') assert output.endswith('0')