From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C457C7EE29 for ; Tue, 13 Jun 2023 05:48:52 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 62619861CE; Tue, 13 Jun 2023 07:48:50 +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="LenLcGhF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6C1D6861EC; Tue, 13 Jun 2023 07:48:48 +0200 (CEST) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) (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 E4367861BA for ; Tue, 13 Jun 2023 07:48:45 +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-wr1-x429.google.com with SMTP id ffacd0b85a97d-30fbf6603d2so1899521f8f.0 for ; Mon, 12 Jun 2023 22:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686635325; x=1689227325; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=zPlu0gcWibVYW8TYZ3WAwooXabwxiJAp0C4mgToM+Rg=; b=LenLcGhFc3QEZylVAZkejHAaq2WLkf+FfrCbVT7R4Q9JfeHE/nWojdxomFWbDZ0MXt 3Z8qyGcHoDyoa/nswIjvphG+tK5uBbyIMQaLy5JysEVdc8e6WIEXchUPvkHA7E+L9c6G YCQz08i1GahiwM+XCy+i5Z6uYNfDTzoinNYXkU/lZ+UZQN6H60wrv2SiCSrOiqkiXdMM GIuQYlgzk6dkJQPSv3tx+S/57OIGVRJUgcVK2tgDHemsSHRauvniUqC9f/Hr79NfU3D5 CvpozrnP6Vr1vrrb9BNGHQ/LtkdwgABeaF/3GzthrCzJ2aOVpppkrpmBUe8cqVhaUaaf 3hng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686635325; x=1689227325; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zPlu0gcWibVYW8TYZ3WAwooXabwxiJAp0C4mgToM+Rg=; b=gsRRYdxoy9UisKzd6hU4K9WffOYoKSLUH+Xi2PGBupDepY/bZFCffg2K3iBo7BGpcq 4xWp2J0tqZL7wcG0wApoHdDbDQYiLPNdT4VS7S1puVHWbZYiBv/X6VtHAswH3ufLjNcD y7P/7Zehl/e0803fdWJ2roEldXHDfwRbDMVAB3if62j5R0NdcNO9yYbTc1ofULkd7J6A rWllBPB2acjUoaoR4cynQCjKRxYGVhiyEcyes8wnHwI5MliTLLAoYpB8TiVuX+al50Pr MFaFIfjXZc9/hRVy46tTPKTO3ByYf2Kgmjvw4nai8eXGZ+P5KGer3Mhpv6DcCcAlBlAC cvLQ== X-Gm-Message-State: AC+VfDwHYZQbiH9JYvEdxS8zdueUan3MTTepQSqnei3mUix+L5BOiM0v tfHiR6oV0Nmgarie1IlslyjXcA== X-Google-Smtp-Source: ACHHUZ63G60M3bfQ9gOwIF/g4z7/htmbyT976WF1/94BoAYQNn3EYJYFfJqPXqLBUtUGhnSJxfbpag== X-Received: by 2002:a05:6000:181:b0:30f:cd95:a603 with SMTP id p1-20020a056000018100b0030fcd95a603mr562863wrx.51.1686635325194; Mon, 12 Jun 2023 22:48:45 -0700 (PDT) Received: from hera (ppp089210114029.access.hol.gr. [89.210.114.29]) by smtp.gmail.com with ESMTPSA id m7-20020a7bca47000000b003f80b96097esm10618825wml.31.2023.06.12.22.48.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 22:48:44 -0700 (PDT) Date: Tue, 13 Jun 2023 08:48:42 +0300 From: Ilias Apalodimas To: Simon Glass Cc: u-boot@lists.denx.de Subject: Re: [PATCH 3/3 v2] test/py: Account PCR updates properly during testing Message-ID: References: <20230607091812.1916435-1-ilias.apalodimas@linaro.org> <20230607091812.1916435-4-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Mon, Jun 12, 2023 at 10:17:28PM +0100, Simon Glass wrote: > Hi Ilias, > > On Wed, 7 Jun 2023 at 10:18, Ilias Apalodimas > wrote: > > > > 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. > > This may be true for some TPMs. The responses to the startup command are described by the spec, so unless the device isn't a standard TPM, this should be safe > > > > > 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 > > --- > > Changes since v1: > > - new patch to fix the python testing failures > > > > test/py/tests/test_tpm2.py | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > Reviewed-by: Simon Glass > > BTW this is an example of why I still want to be able to just init the > TPM to a basic level. Here we see that autostart changes the PCRs. > It doesnt change the PCRs. That code is checking how many commands have been sent to the TPM in total. In the previous version of the code 'tpm init' would return -EBUSY and we would never re-run the next commands. The new command returns 0 and as a result we end up running the TPM2_RH_LOCKOUT again. Thanks /Ilias > > > 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') > > -- > > 2.39.2 > >