From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,
	SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id D9BABC54E4B
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 04:01:57 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id AEA4520730
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 04:01:57 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fmiCg8Fm"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1725554AbgELEB5 (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 00:01:57 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53072 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL)
        by vger.kernel.org with ESMTP id S1725536AbgELEB4 (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 00:01:56 -0400
Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A0DCC061A0C
        for <linux-integrity@vger.kernel.org>; Mon, 11 May 2020 21:01:56 -0700 (PDT)
Received: by mail-wm1-x343.google.com with SMTP id n5so6765341wmd.0
        for <linux-integrity@vger.kernel.org>; Mon, 11 May 2020 21:01:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=DHu/I0/jx2sW1DokJ+Kufd/ty31VLzykSRHqsd1EPLQ=;
        b=fmiCg8FmMYn5QMPDM671yjeWBu0/9xuST9stMkpNILUmgIsbrHlpqgXtHlsKkDaDXS
         eHK1MEVqnuhveaiQyFr/3BNJwkFhPnru8bcRoBSF1YyOd39LXoqxlV3dWvQ8aJpFbIlr
         0YBUt88IwPloXQri/eC2aCqmVDZE6+ry9THSgEncfinmo1T8sdFLk3F5Z1bgLROlNNhu
         99WIgiumaZ7PV2xIRLPr8NebF/wERowEG0BypHqgrY4t+XFXhjPL0IYnwSdzjmA6g8HL
         lygjFehfkyTzF8WpHbbf4ueSxzLMqArxUMPO+6LTMU1yrpLupUYobGkkvcIoZ4EuQRS2
         viZg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=DHu/I0/jx2sW1DokJ+Kufd/ty31VLzykSRHqsd1EPLQ=;
        b=rhlbiZCfAH3XAuCL8QPy+/N/MHEHSNRGYSXvEc7jnpKw7XZ1ToPRGV8mDn0YWNbK9O
         UJNiZkKvoVOYGyfTNglbiKia1G07EQ4qBPGerp7yEHkuacpUY42x1zd0A9tA7ULaANat
         +HpnWG1uJfW5niOPZzCQrA6iKYoH/uhxCNJrzd+HkqsvA0DDR5WngTQWUXkccROyoYFz
         uUYXF5L46+wkBb//djWG09MA3QdgWPgSBCoVIneCWdAx/tb66xaZQ4xNmq2pUzCimO+G
         dVoo7Ydi3uw19UKOEUEgr+6+j8VyoGM0RNZ9JKjIue65jC6xNatjIw3O51CND65c5lIV
         dlWA==
X-Gm-Message-State: AGi0PuY4lLKwsh05602Y6JOeDv/86wYGAJ+jMyeG3piFA3bxNrAIId01
        9DmrrYRsbj+k92Wl4E6q2RJIdJMNKXY=
X-Google-Smtp-Source: APiQypIj7iE6OIfRD0Yb+X8K95Ajj+Ic3eSSrCyYp0kbUkY4ueRID8RiDxm4/vPn1J8tWPAoaJD/kg==
X-Received: by 2002:a7b:c0d1:: with SMTP id s17mr8016876wmh.157.1589256115082;
        Mon, 11 May 2020 21:01:55 -0700 (PDT)
Received: from localhost.localdomain (174.39.207.77.rev.sfr.net. [77.207.39.174])
        by smtp.gmail.com with ESMTPSA id g135sm12274450wme.22.2020.05.11.21.01.53
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 11 May 2020 21:01:53 -0700 (PDT)
From:   =?UTF-8?q?Lo=C3=AFc=20Yhuel?= <loic.yhuel@gmail.com>
To:     linux-integrity@vger.kernel.org
Cc:     matthewgarrett@google.com, ardb@kernel.org,
        jarkko.sakkinen@linux.intel.com, javierm@redhat.com,
        =?UTF-8?q?Lo=C3=AFc=20Yhuel?= <loic.yhuel@gmail.com>
Subject: [PATCH] tpm: check event log version before reading final events
Date:   Tue, 12 May 2020 06:01:13 +0200
Message-Id: <20200512040113.277768-1-loic.yhuel@gmail.com>
X-Mailer: git-send-email 2.26.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

This fixes the boot issues since 5.3 on several Dell models when the TPM
is enabled. Depending on the exact grub binary, booting the kernel would
freeze early, or just report an error parsing the final events log.

We get an event log in the SHA-1 format, which doesn't have a
tcg_efi_specid_event_head in the first event, and there is a final events
table which doesn't match the crypto agile format.
__calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
either fails, or loops long enough for the machine to be appear frozen.

So we now only parse the final events table, which is per the spec always
supposed to be in the crypto agile format, when we got a event log in this
format.

Fixes: c46f3405692de ("tpm: Reserve the TPM final events table")
Fixes: 166a2809d65b2 ("tpm: Don't duplicate events from the final event log in the TCG2 log")
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1779611
Signed-off-by: Loïc Yhuel <loic.yhuel@gmail.com>
---
 drivers/firmware/efi/libstub/tpm.c | 5 +++--
 drivers/firmware/efi/tpm.c         | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c
index 1d59e103a2e3..e9a684637b70 100644
--- a/drivers/firmware/efi/libstub/tpm.c
+++ b/drivers/firmware/efi/libstub/tpm.c
@@ -54,7 +54,7 @@ void efi_retrieve_tpm2_eventlog(void)
 	efi_status_t status;
 	efi_physical_addr_t log_location = 0, log_last_entry = 0;
 	struct linux_efi_tpm_eventlog *log_tbl = NULL;
-	struct efi_tcg2_final_events_table *final_events_table;
+	struct efi_tcg2_final_events_table *final_events_table = NULL;
 	unsigned long first_entry_addr, last_entry_addr;
 	size_t log_size, last_entry_size;
 	efi_bool_t truncated;
@@ -127,7 +127,8 @@ void efi_retrieve_tpm2_eventlog(void)
 	 * Figure out whether any events have already been logged to the
 	 * final events structure, and if so how much space they take up
 	 */
-	final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
+	if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
+		final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
 	if (final_events_table && final_events_table->nr_events) {
 		struct tcg_pcr_event2_head *header;
 		int offset;
diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index 55b031d2c989..77e101a395e7 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -62,7 +62,8 @@ int __init efi_tpm_eventlog_init(void)
 	tbl_size = sizeof(*log_tbl) + log_tbl->size;
 	memblock_reserve(efi.tpm_log, tbl_size);
 
-	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR)
+	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
+	    log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
 		goto out;
 
 	final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));
-- 
2.26.2


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-7.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,
	SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE18C54E4B
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 06:45:10 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id EDF49207DD
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 06:45:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1589265910;
	bh=Ibbq3rhPEuZHzZttWYIdBD2cMJ4dRooE/97LgSRNa4k=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From;
	b=nBKIxlQiYsacYNl0A8BK11snYhGEPVjmb0T7H9exouMsXXX/2c0zxPEUq6wUn555K
	 AeP517FU6pz9ie5J3o5oUMd4mtPMYn3j54UNSUgRk6sMd2l6Z2L/l3G2G/IK5UuQZw
	 rnaIzX66j5qiZ7LhEv9Idx6FlLbdoFgTiE9Qe3/w=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726067AbgELGpJ (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 02:45:09 -0400
Received: from mail.kernel.org ([198.145.29.99]:48308 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725987AbgELGpJ (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 02:45:09 -0400
Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mail.kernel.org (Postfix) with ESMTPSA id 283E620752
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 06:45:09 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1589265909;
        bh=Ibbq3rhPEuZHzZttWYIdBD2cMJ4dRooE/97LgSRNa4k=;
        h=References:In-Reply-To:From:Date:Subject:To:Cc:From;
        b=0KuZvZnpEp4zOnRhNzOoqTJg/MMAhzuHH0OCYFCm15mW3skQtYNKQ6LKMo4HNPC8s
         5ls+cDunTcgchOFRw1vfoP8UZjH4Bi/4ReLlzVHmwpg/CkRTZfkWHeZ28WlsL/cpO9
         036qAGSBZsprHVOaZfL9E3efYedZGU/gZ3JEA3VU=
Received: by mail-il1-f170.google.com with SMTP id i16so11138744ils.12
        for <linux-integrity@vger.kernel.org>; Mon, 11 May 2020 23:45:09 -0700 (PDT)
X-Gm-Message-State: AGi0Pubj0bJNk2GLcvH9dJgr0tvmmTWuM6Ges3OxYxZBL7YDZAW8vK5N
        OYuwEEYfFB2KCOLqnlaILgQ22xrzlbtvSS62Vuc=
X-Google-Smtp-Source: APiQypIjxvIGB0jbUMC3BgygJ9D5Rw03n6oLcV5uHWE3muITAmAbD5zkrk2pjKJ6h+aAoQlf/9hetfLVTf2Y/+QKdvQ=
X-Received: by 2002:a92:c948:: with SMTP id i8mr14019965ilq.258.1589265908506;
 Mon, 11 May 2020 23:45:08 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
In-Reply-To: <20200512040113.277768-1-loic.yhuel@gmail.com>
From:   Ard Biesheuvel <ardb@kernel.org>
Date:   Tue, 12 May 2020 08:44:57 +0200
X-Gmail-Original-Message-ID: <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
Message-ID: <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Cc:     linux-integrity@vger.kernel.org, matthewgarrett@google.com,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        javierm@redhat.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Hi Lo=C3=AFc,

Thanks for the fix.

On Tue, 12 May 2020 at 06:01, Lo=C3=AFc Yhuel <loic.yhuel@gmail.com> wrote:
>
> This fixes the boot issues since 5.3 on several Dell models when the TPM
> is enabled. Depending on the exact grub binary, booting the kernel would
> freeze early, or just report an error parsing the final events log.
>
> We get an event log in the SHA-1 format, which doesn't have a
> tcg_efi_specid_event_head in the first event, and there is a final events
> table which doesn't match the crypto agile format.
> __calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
> either fails, or loops long enough for the machine to be appear frozen.
>
> So we now only parse the final events table, which is per the spec always
> supposed to be in the crypto agile format, when we got a event log in thi=
s
> format.
>

So what functionality do we lose here? Can we still make meaningful
use of the event log without the final log? I thought one was
incomplete without the other?

> Fixes: c46f3405692de ("tpm: Reserve the TPM final events table")
> Fixes: 166a2809d65b2 ("tpm: Don't duplicate events from the final event l=
og in the TCG2 log")
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1779611
> Signed-off-by: Lo=C3=AFc Yhuel <loic.yhuel@gmail.com>

I can take this as a fix, but I need an ack from Matt as well.

> ---
>  drivers/firmware/efi/libstub/tpm.c | 5 +++--
>  drivers/firmware/efi/tpm.c         | 3 ++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/li=
bstub/tpm.c
> index 1d59e103a2e3..e9a684637b70 100644
> --- a/drivers/firmware/efi/libstub/tpm.c
> +++ b/drivers/firmware/efi/libstub/tpm.c
> @@ -54,7 +54,7 @@ void efi_retrieve_tpm2_eventlog(void)
>         efi_status_t status;
>         efi_physical_addr_t log_location =3D 0, log_last_entry =3D 0;
>         struct linux_efi_tpm_eventlog *log_tbl =3D NULL;
> -       struct efi_tcg2_final_events_table *final_events_table;
> +       struct efi_tcg2_final_events_table *final_events_table =3D NULL;
>         unsigned long first_entry_addr, last_entry_addr;
>         size_t log_size, last_entry_size;
>         efi_bool_t truncated;
> @@ -127,7 +127,8 @@ void efi_retrieve_tpm2_eventlog(void)
>          * Figure out whether any events have already been logged to the
>          * final events structure, and if so how much space they take up
>          */
> -       final_events_table =3D get_efi_config_table(LINUX_EFI_TPM_FINAL_L=
OG_GUID);
> +       if (version =3D=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
> +               final_events_table =3D get_efi_config_table(LINUX_EFI_TPM=
_FINAL_LOG_GUID);
>         if (final_events_table && final_events_table->nr_events) {
>                 struct tcg_pcr_event2_head *header;
>                 int offset;
> diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
> index 55b031d2c989..77e101a395e7 100644
> --- a/drivers/firmware/efi/tpm.c
> +++ b/drivers/firmware/efi/tpm.c
> @@ -62,7 +62,8 @@ int __init efi_tpm_eventlog_init(void)
>         tbl_size =3D sizeof(*log_tbl) + log_tbl->size;
>         memblock_reserve(efi.tpm_log, tbl_size);
>
> -       if (efi.tpm_final_log =3D=3D EFI_INVALID_TABLE_ADDR)
> +       if (efi.tpm_final_log =3D=3D EFI_INVALID_TABLE_ADDR ||
> +           log_tbl->version !=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
>                 goto out;
>
>         final_tbl =3D early_memremap(efi.tpm_final_log, sizeof(*final_tbl=
));
> --
> 2.26.2
>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS
	autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 35216C54E4A
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 11:40:23 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 0F6972075E
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 11:40:22 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UdV18JUO"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1727783AbgELLkW (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 07:40:22 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39954 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1726187AbgELLkW (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 07:40:22 -0400
Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32562C061A0C
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 04:40:22 -0700 (PDT)
Received: by mail-io1-xd2a.google.com with SMTP id e18so644985iog.9
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 04:40:22 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=d6I2nBaTdCMDd3hvG+KBjRfJdt5k5+1ubGaOtAwQk5k=;
        b=UdV18JUOBzhIMLSq2GVOGaUO7lpT4eaCx8zQDU2lJHSfb0U+A+FcptsDC+rzCQPXIa
         0KWhfObyGcaVoU61owIF+jvAzTkNEdiuD4N2mR42iICEKeiP2kK0I88TNGPCK8KmNu8N
         j8GXzlzthG89Nd4RDxvq/rHrjmu+0W/JnuP74cZ8v/vonFUJN8s3wNBOZV0xKwm/YBzO
         1t7Pbgz51JwYuUYkBB82Zgwc8+/cg6TdmAy/YUv2KjSHiBy8AnOzFo2ez99dK0Yfvm6r
         OlhPx7RQ5yazCrWIrBQk8/cvxyhg6imLRavkx0XP1oFo1/rkr9nAZGERjx69XDMjhe1z
         9RLA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=d6I2nBaTdCMDd3hvG+KBjRfJdt5k5+1ubGaOtAwQk5k=;
        b=Hz2ICtRWAR7t/BX4adDslu4WQFKs+y2Mb8W4/50yh4SBnNGYVOpcOXiOsJcCvs7iNy
         aElCvPiAamjVzdK8wRUnSU5ttCg0VGy6M7pxYtorPHsHJVOKbNkbxwmSEXmPID59gawV
         jQwMlKf4bxEyOBgQ2WPMDP0TxdO7+ZkEsG5MkXHxgZMqxIZj4eLbbsWXh6cTMW2Fpqdn
         Ivozgj17aRIIngCm9TCEHQzbQkr02BNOcPbbI9K6N/EswRDd9cuMii32c3aF1eC4QMq9
         HXM2ugI5PQlf6E7n9I5V0IV704Z5XiXTptAXjNSDCzjO6Pe5my1E+MzMxb+CPtFkvlCa
         j7mQ==
X-Gm-Message-State: AGi0PuZ3ubYrJKXGVzWlitfBko8/WSdtocur8VpA+oaOP6yqurLpqDmy
        kIVZ3V5jAH8p/Fe2Pj8S1xAkMPuVgkdGtEBhjuI=
X-Google-Smtp-Source: APiQypJrzFtnXhFOkFi0kUmpKg3B/1oVZ4dO4nu4CAnrn7h56jeyC5S0MJWuJG0mCBSNHv8+ikE2Vc+nDEQmDEUg+nY=
X-Received: by 2002:a5e:9703:: with SMTP id w3mr20412697ioj.111.1589283621510;
 Tue, 12 May 2020 04:40:21 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
In-Reply-To: <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
From:   =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Date:   Tue, 12 May 2020 13:40:10 +0200
Message-ID: <CANMwUkg+2O2nK8z38HZw6z0NdLUPwj40m4DPKmn1sf9oDqG7Pw@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Ard Biesheuvel <ardb@kernel.org>
Cc:     linux-integrity@vger.kernel.org,
        Matthew Garrett <matthewgarrett@google.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        javierm@redhat.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Le mar. 12 mai 2020 =C3=A0 08:45, Ard Biesheuvel <ardb@kernel.org> a =C3=A9=
crit :
> So what functionality do we lose here? Can we still make meaningful
> use of the event log without the final log? I thought one was
> incomplete without the other?
The char driver (drivers/char/tpm/eventlog/efi.c), already ignores
efi.tpm_final_log
if the event log version isn't EFI_TCG2_EVENT_LOG_FORMAT_TCG_2.
So there currently no code making use of the final log contents on
those machines,
besides the two cases I patched which only try to determine its size.

I don't know if the table contains bad data, or just doesn't follow
the specification
and uses the older SHA-1 log format. If this is the case, perhaps we
could try to
support it, and modify the code to allow returning the additional
events it might
contain to the userspace.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS
	autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 882CBC54E4A
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 12:30:37 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 6319B206F5
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 12:30:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1589286637;
	bh=J3dCJ8ubzx0/h11Me5hEiE/dLV/HBQNq47FFE6myQYo=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From;
	b=e2N/isBb4GMDTea+TBp1X4umqz/rRs0HcLe43jmT95799YUKt5vayGmVMJrYzB4VE
	 esA7MA3tqUQYYj0NKlJn+DEfs5nMXfjL0PtOnYxDUiPxPMdUiKF7yoWduy9tidfzBE
	 dOMneN2sWVhQLBEk/1R16Ilh4UBHDQFORXbMlaB4=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1728283AbgELMah (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 08:30:37 -0400
Received: from mail.kernel.org ([198.145.29.99]:45538 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1727859AbgELMag (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 08:30:36 -0400
Received: from mail-io1-f46.google.com (mail-io1-f46.google.com [209.85.166.46])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mail.kernel.org (Postfix) with ESMTPSA id 4E028206F5
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 12:30:36 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1589286636;
        bh=J3dCJ8ubzx0/h11Me5hEiE/dLV/HBQNq47FFE6myQYo=;
        h=References:In-Reply-To:From:Date:Subject:To:Cc:From;
        b=PIeLOogVJwtCQyhlqBPFq5HJvWUpJRyaibS4Mluqtzy5Vcn43CugA4gePgdZMuhQe
         B/EzUmTU6Bz3z4+TYyAX+RdjCNmRWti9fIM6C4+ZeQWBpUASXxksUJNVFm7GlSbjlE
         Djd+wDwXHrAHtLMWUAHxdAgYQ8bqVV5TjOJ1+Bm8=
Received: by mail-io1-f46.google.com with SMTP id i19so13632432ioh.12
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 05:30:36 -0700 (PDT)
X-Gm-Message-State: AGi0PuZvid7jJq5gefOlMBAARn2kYuz1WZJz3BtYmeelCPkI8BMA7jCQ
        fGk45XVlL28+6vQIUsgJrHv+8bJpNxKc9pgf4wc=
X-Google-Smtp-Source: APiQypLuYgpL+sZ3x5KoQ/eLalULDNGCbngRq9Pk8CHwSeG+fqpBv/4gSUl1val8Y70Ee2N2VCyJJEVv6wfWoPXWP0k=
X-Received: by 2002:a5e:8705:: with SMTP id y5mr7771528ioj.142.1589286635753;
 Tue, 12 May 2020 05:30:35 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
 <CANMwUkg+2O2nK8z38HZw6z0NdLUPwj40m4DPKmn1sf9oDqG7Pw@mail.gmail.com>
In-Reply-To: <CANMwUkg+2O2nK8z38HZw6z0NdLUPwj40m4DPKmn1sf9oDqG7Pw@mail.gmail.com>
From:   Ard Biesheuvel <ardb@kernel.org>
Date:   Tue, 12 May 2020 14:30:24 +0200
X-Gmail-Original-Message-ID: <CAMj1kXFPt4eSDCC61paWhyfOaEeWUgUQSnczwZJ7Eny8t7ow5g@mail.gmail.com>
Message-ID: <CAMj1kXFPt4eSDCC61paWhyfOaEeWUgUQSnczwZJ7Eny8t7ow5g@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Cc:     linux-integrity@vger.kernel.org,
        Matthew Garrett <matthewgarrett@google.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        javierm@redhat.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Tue, 12 May 2020 at 13:40, Lo=C3=AFc Yhuel <loic.yhuel@gmail.com> wrote:
>
> Le mar. 12 mai 2020 =C3=A0 08:45, Ard Biesheuvel <ardb@kernel.org> a =C3=
=A9crit :
> > So what functionality do we lose here? Can we still make meaningful
> > use of the event log without the final log? I thought one was
> > incomplete without the other?
> The char driver (drivers/char/tpm/eventlog/efi.c), already ignores
> efi.tpm_final_log
> if the event log version isn't EFI_TCG2_EVENT_LOG_FORMAT_TCG_2.
> So there currently no code making use of the final log contents on
> those machines,
> besides the two cases I patched which only try to determine its size.
>

Ah ok, thanks for clarifying. If we never consume it anyway, then I
agree this is the correct fix.



> I don't know if the table contains bad data, or just doesn't follow
> the specification
> and uses the older SHA-1 log format. If this is the case, perhaps we
> could try to
> support it, and modify the code to allow returning the additional
> events it might
> contain to the userspace.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 31F31CA90AF
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 17:46:10 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 0EF40206DD
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 17:46:10 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I28q1pZt"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1725950AbgELRqJ (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 13:46:09 -0400
Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36071 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1725554AbgELRqJ (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 13:46:09 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1589305568;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         content-transfer-encoding:content-transfer-encoding:
         in-reply-to:in-reply-to:references:references;
        bh=VlHK3MD9mslQAtaYQzirsJP3rdEAoipwCXorCnBdiew=;
        b=I28q1pZth5Uilj1VllM0y1vG6m0YYzQvc+X874ta66trqdcbL1eFOLEHawwlyiu5EH9Fnc
        KNX6HVgC0quk0kP9N32WkhNmVLULJurRVGOlqvN52qiWMlOnTn68q/5DGDEftAcyJH9qEd
        FP9tdweQ77PvOneUB2AikW1s5S39eKQ=
Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com
 [209.85.167.70]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-399-vG7q-43sOzOgXCGerf9v2A-1; Tue, 12 May 2020 13:46:06 -0400
X-MC-Unique: vG7q-43sOzOgXCGerf9v2A-1
Received: by mail-lf1-f70.google.com with SMTP id 74so5094195lfn.4
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 10:46:06 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=VlHK3MD9mslQAtaYQzirsJP3rdEAoipwCXorCnBdiew=;
        b=rabdaIacwcCuyz6HxPwX91SkpMYj9+mdq92+XOXSThk9sDTgY6mFU2z/IoO6o97lu5
         2dM5I0YfrhCGhE+Gt9MnI65kXiqRZz2/sosew+ImBnxuC+51YapRX3TyoXch7L7UvMZZ
         +TpTZzaW9JBxLvTzvUgEE1jAhR0FEzsD9TlmBdhuY6begNCRS4dWn4LinW6dn6gq525v
         lLwd3EwaVZN4Tm5NbF2GH3Bn/wcxAGXEKZIT+afjNuSl2Q57shBiRbGz17OaRYdD4G0A
         wmvcOcI8tz1sSEQ8zR82nxNQW9CCTR2lPh5WUAJFgo67ExsdmINIU8yODmh6O34RbI1a
         HKWA==
X-Gm-Message-State: AOAM533r+uIXnsu5dYaLZwklg50KWOuOt4Ep4zZNr5p3A787wT8RwMDp
        1by+lw9++fLBPQPptSQDi8yKbAudj632CJvBxnGt+o+l6wGlXt7dlVBx9Fs5c9RRH31ExGmiZbq
        HiWo25ZOr6aRsmUkfdq4+nBR1D0OiEMDYMbMBa5S0KFAd
X-Received: by 2002:a19:d55:: with SMTP id 82mr15462497lfn.89.1589305565165;
        Tue, 12 May 2020 10:46:05 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJx2rJ7GkPyduqApdhohXjMBvp1QWYTQ9kph1gg5Iet5LK7XYhRimhH3mknNMnGMFIY/8nws8y4z70rY47juR3I=
X-Received: by 2002:a19:d55:: with SMTP id 82mr15462483lfn.89.1589305564897;
 Tue, 12 May 2020 10:46:04 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
In-Reply-To: <20200512040113.277768-1-loic.yhuel@gmail.com>
From:   Javier Martinez Canillas <javierm@redhat.com>
Date:   Tue, 12 May 2020 19:45:53 +0200
Message-ID: <CAFOAJEfFcL5EYXnwd=Yqdj065efD2ojYVjpJ+4rOZqGcxmTAsA@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Cc:     linux-integrity@vger.kernel.org,
        Matthew Garrett <matthewgarrett@google.com>,
        Ard Biesheuvel <ardb@kernel.org>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Hello Lo=C3=AFc,

On Tue, May 12, 2020 at 6:02 AM Lo=C3=AFc Yhuel <loic.yhuel@gmail.com> wrot=
e:
>
> This fixes the boot issues since 5.3 on several Dell models when the TPM
> is enabled. Depending on the exact grub binary, booting the kernel would
> freeze early, or just report an error parsing the final events log.
>
> We get an event log in the SHA-1 format, which doesn't have a
> tcg_efi_specid_event_head in the first event, and there is a final events
> table which doesn't match the crypto agile format.
> __calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
> either fails, or loops long enough for the machine to be appear frozen.
>
> So we now only parse the final events table, which is per the spec always
> supposed to be in the crypto agile format, when we got a event log in thi=
s
> format.
>
> Fixes: c46f3405692de ("tpm: Reserve the TPM final events table")
> Fixes: 166a2809d65b2 ("tpm: Don't duplicate events from the final event l=
og in the TCG2 log")
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1779611
> Signed-off-by: Lo=C3=AFc Yhuel <loic.yhuel@gmail.com>
> ---

As you mention, that's what the TCG EFI Protocol Specification says
about the EFI Final Events Table so I agree with your patch.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

Best regards,
Javier


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 865B1C2D0F6
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 18:46:01 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 65FB420673
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 18:46:01 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UUq0fo0u"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1730496AbgELSqA (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 14:46:00 -0400
Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39481 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1725987AbgELSqA (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 14:46:00 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1589309158;
        h=from:from:reply-to:reply-to:subject:subject:date:date:
         message-id:message-id:to:to:cc:cc:mime-version:mime-version:
         content-type:content-type:
         content-transfer-encoding:content-transfer-encoding:
         in-reply-to:in-reply-to:references:references;
        bh=gANTnHwUhR+9/dJggusZJfVpovpiqd+gOXYf4b9mYZ4=;
        b=UUq0fo0uXuhAYfcAyjSZLLUh62XFekw7X80EvH0NkvcSQV/k2LY16C2wKXM6uikCCqi37i
        5iOy2JqGttQUiexxbmf6/LGomq/1qJ/vYi8ZFyxVIzSOV4t78o26hZYRsPUcV7Gt9QghUt
        2MdYGCfiG81zC/YSB6gSL8fUAFC4xFE=
Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com
 [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-377-maFJAEaTNfKFoouq_k2Omg-1; Tue, 12 May 2020 14:45:56 -0400
X-MC-Unique: maFJAEaTNfKFoouq_k2Omg-1
Received: by mail-qt1-f199.google.com with SMTP id o16so12688592qto.12
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 11:45:56 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:subject:message-id:reply-to
         :references:mime-version:content-disposition
         :content-transfer-encoding:in-reply-to;
        bh=gANTnHwUhR+9/dJggusZJfVpovpiqd+gOXYf4b9mYZ4=;
        b=bDka7+0l5faOdDZ4ZXMFmah415zpoqCWmJ4PjRUg/Y4IUQLU7ZJjPMKOhFz9KPa/Dq
         74W5hHauZ9T/XKi/8VS/ncVfz/mKG9o6CR3Vu5Nyn4e4kXV6nh+Luk6XpkRXsL4p0dor
         Ym+lcaVJoGgCTCg8ZmAisjSHVIWhqHmgQkPHmpUQiRplKsIIUM+imOFY+AcX7at/HeIo
         Piz7q0mSBESmcCqCJYQiWDnaJu8nsmb5imJ1kw3lp6aSaAgRDJnk+XDg07jWKXFYRcQc
         DFZbJsZempmtglI/XEzbTWomSDQjSWrzSJcwASsS7yLYl9NNvg6ISlz997bAecg+SqBr
         FVfw==
X-Gm-Message-State: AOAM530Jz4SvFO1NU98OzYf7GyFn63FNJk5Zvne+BiWn+/9ehUrersh7
        NXUcg3eaqS64WfCluuyYtVi0SrPezuhsQEAl4MaCI0bqRBReg0/9hLfd9J+cdX20RaMNSnVrCF8
        sRIxWoQJDpeZ+R2VEcSKaIs0xTzGA
X-Received: by 2002:ac8:1967:: with SMTP id g36mr4745262qtk.332.1589309156185;
        Tue, 12 May 2020 11:45:56 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJwIyqJerzBCIu92cdFK0jMTrRxyGeFRN87+rPmKDn8q2nfKDKbVxPfDoPFlCWNWwrGkefWteg==
X-Received: by 2002:ac8:1967:: with SMTP id g36mr4745233qtk.332.1589309155938;
        Tue, 12 May 2020 11:45:55 -0700 (PDT)
Received: from localhost (ip70-163-223-149.ph.ph.cox.net. [70.163.223.149])
        by smtp.gmail.com with ESMTPSA id 66sm12410202qtg.84.2020.05.12.11.45.54
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Tue, 12 May 2020 11:45:54 -0700 (PDT)
Date:   Tue, 12 May 2020 11:45:53 -0700
From:   Jerry Snitselaar <jsnitsel@redhat.com>
To:     =?utf-8?B?TG/Dr2M=?= Yhuel <loic.yhuel@gmail.com>
Cc:     linux-integrity@vger.kernel.org, matthewgarrett@google.com,
        ardb@kernel.org, jarkko.sakkinen@linux.intel.com,
        javierm@redhat.com
Subject: Re: [PATCH] tpm: check event log version before reading final events
Message-ID: <20200512184553.to7zij2lhbqfnedp@cantor>
Reply-To: Jerry Snitselaar <jsnitsel@redhat.com>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
In-Reply-To: <20200512040113.277768-1-loic.yhuel@gmail.com>
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Tue May 12 20, Loïc Yhuel wrote:
>This fixes the boot issues since 5.3 on several Dell models when the TPM
>is enabled. Depending on the exact grub binary, booting the kernel would
>freeze early, or just report an error parsing the final events log.
>
>We get an event log in the SHA-1 format, which doesn't have a
>tcg_efi_specid_event_head in the first event, and there is a final events
>table which doesn't match the crypto agile format.
>__calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
>either fails, or loops long enough for the machine to be appear frozen.
>
>So we now only parse the final events table, which is per the spec always
>supposed to be in the crypto agile format, when we got a event log in this
>format.
>
>Fixes: c46f3405692de ("tpm: Reserve the TPM final events table")
>Fixes: 166a2809d65b2 ("tpm: Don't duplicate events from the final event log in the TCG2 log")
>Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1779611
>Signed-off-by: Loïc Yhuel <loic.yhuel@gmail.com>
>---

Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com>


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=rf2w=62=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 5759BC2D0F7
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 20:08:26 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 2CFD120769
	for <linux-integrity@archiver.kernel.org>; Tue, 12 May 2020 20:08:26 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ecXKDWAv"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1730210AbgELUIZ (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Tue, 12 May 2020 16:08:25 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34450 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1725950AbgELUIZ (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Tue, 12 May 2020 16:08:25 -0400
Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2FAC061A0C
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 13:08:24 -0700 (PDT)
Received: by mail-io1-xd2b.google.com with SMTP id e18so2678642iog.9
        for <linux-integrity@vger.kernel.org>; Tue, 12 May 2020 13:08:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=iQ1FXZEo9sAqjvXhulqp1o6Tr1qWg73VyBJS6q3oQSY=;
        b=ecXKDWAvXHXgK5DVRc/9P3enNHhO8C04BA3CHfw832WJhzTW/8Jvz8pSm5v6kGOwRh
         UxViVF4GBzwkr3OEqVP1+jwEU0HezbZzzXDr5SU64CyDZuDt7C/3eddKQl467oT7SmI/
         jmM6cwOkfByiCZwY86b7IJ3OrwgFjG/zvmAxkv3z5964GQ4iyAgZc50qxl2cFxgwgnaL
         6UbuX+0K56gD7rVwSxQLP6D5yFSYCH9v9XcZpXYGwAy1nFSRtxsLxEKpS5XZ+K/zmee6
         GJw8Ddd9NHnc8ZoedlfOTIFEOx1bjj68zSOg3ANjoVdI2BfchZ368LlLAnSe2DL4M1RU
         tXdw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=iQ1FXZEo9sAqjvXhulqp1o6Tr1qWg73VyBJS6q3oQSY=;
        b=gISTWS5EEtuKylZvNE6t/AXo2t39kaiAD0Wz96aqwJvp4o3zMB33dQZuTWjwbPVeiY
         sQeYr8Q8lQgE698oVd3Km9erMvcZ0xpwBbeOUWYv8dFshR6H845iDPFf14pVhmNGffz5
         SpKMYyV8biDhXzmRaOnSJXb+d6QXYKpnpP/FvcBUpCBHdxswtWkR/lryVExa52IzIDFr
         JmHJha/G1eQYxxO168aVbw5FVPCkgvzIe9cfkIYBFAd6XHFmQ8pEqlhAFbF9VLX64Edq
         eoirZyT10ZqfDmY1FfNiTAvn8UVhA9p/GqHedSplH6ZTYQR6ZLtCDI6w+celWYh+7d5z
         MIAA==
X-Gm-Message-State: AGi0Puarjfmzxz/Iq2EBUskDZe1ZQQBeIgxmy3jdDMPoU223wPFajrgc
        22Kxc7qijNHVqCldP30388FEVmR0SFGhiWtm/PVjQpIt
X-Google-Smtp-Source: APiQypL4wFQfR0vZuCymK1dKdrMRavz8+o57sMdnaXLgL7YcBWqhLJJKPwFM8PpGH9W+rYkFS8f7AILNfFqJMoWAuDk=
X-Received: by 2002:a02:1746:: with SMTP id 67mr3911965jah.103.1589314103323;
 Tue, 12 May 2020 13:08:23 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
In-Reply-To: <20200512040113.277768-1-loic.yhuel@gmail.com>
From:   Matthew Garrett <mjg59@google.com>
Date:   Tue, 12 May 2020 13:08:12 -0700
Message-ID: <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Cc:     linux-integrity <linux-integrity@vger.kernel.org>,
        Ard Biesheuvel <ardb@kernel.org>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Javier Martinez Canillas <javierm@redhat.com>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Mon, May 11, 2020 at 9:01 PM Lo=C3=AFc Yhuel <loic.yhuel@gmail.com> wrot=
e:

> We get an event log in the SHA-1 format, which doesn't have a
> tcg_efi_specid_event_head in the first event, and there is a final events
> table which doesn't match the crypto agile format.

This seems like a firmware bug, but we definitely shouldn't fail as a resul=
t.

Reviewed-by: Matthew Garrett <mjg59@google.com>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id EA5A5C433E0
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 01:09:17 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id F37AF205ED
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 01:09:17 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726070AbgENBJR (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Wed, 13 May 2020 21:09:17 -0400
Received: from mga17.intel.com ([192.55.52.151]:36826 "EHLO mga17.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725943AbgENBJR (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Wed, 13 May 2020 21:09:17 -0400
IronPort-SDR: RC1slc/ec3LpppMX+N9NLRGBTilQqN4p3mctnDBHJMLkf30ThmwE26OWzdV1+n93nBts3SV1AE
 EG3ePw9SG3mA==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from fmsmga008.fm.intel.com ([10.253.24.58])
  by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2020 18:09:16 -0700
IronPort-SDR: YiIAlxpI4EtN9VTx0Vegwpwfu9sU8tkDAOEDfFqZnoYZRKQuayv5Vc/ogZVPhGmYCmunH+QNzO
 aA8klNpyns3w==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.73,389,1583222400"; 
   d="scan'208";a="253346471"
Received: from gliber-mobl1.ger.corp.intel.com ([10.249.38.41])
  by fmsmga008.fm.intel.com with ESMTP; 13 May 2020 18:09:14 -0700
Message-ID: <ab9df4468cc294c67a67ef336019379033e7c90c.camel@linux.intel.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
From:   Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To:     Ard Biesheuvel <ardb@kernel.org>,
        =?ISO-8859-1?Q?Lo=EFc?= Yhuel <loic.yhuel@gmail.com>
Cc:     linux-integrity@vger.kernel.org, matthewgarrett@google.com,
        javierm@redhat.com
Date:   Thu, 14 May 2020 04:09:13 +0300
In-Reply-To: <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
         <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.36.1-2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Tue, 2020-05-12 at 08:44 +0200, Ard Biesheuvel wrote:
> Hi Loïc,
> 
> Thanks for the fix.
> 
> On Tue, 12 May 2020 at 06:01, Loïc Yhuel <loic.yhuel@gmail.com> wrote:
> > This fixes the boot issues since 5.3 on several Dell models when the TPM
> > is enabled. Depending on the exact grub binary, booting the kernel would
> > freeze early, or just report an error parsing the final events log.
> > 
> > We get an event log in the SHA-1 format, which doesn't have a
> > tcg_efi_specid_event_head in the first event, and there is a final events
> > table which doesn't match the crypto agile format.
> > __calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
> > either fails, or loops long enough for the machine to be appear frozen.
> > 
> > So we now only parse the final events table, which is per the spec always
> > supposed to be in the crypto agile format, when we got a event log in this
> > format.
> > 
> 
> So what functionality do we lose here? Can we still make meaningful
> use of the event log without the final log? I thought one was
> incomplete without the other?


Nope it would be incomplete [*].

So probably would make sense to at least issue a warning in this case.

[*] https://www.kernel.org/doc/Documentation/security/tpm/tpm_event_log.rst

/Jarkko


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS
	autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 9D820C433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 08:10:30 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 763872065D
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 08:10:30 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1589443830;
	bh=Xf8DEKxe/HcjD/EnXUO0eGUCvnkUXJ1xE0FLARkXWGA=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From;
	b=pYcMl6T7yP9q9OojPeCmPPM2kHdRx53HWiK0MFvfEA0lDPs2KZFpqRNvlDYtjLLWQ
	 6S08APRGiCkhsBS4Ua+S+FE0Ju7hoQFSj9ZdQaST/p4v5kTU8AE2irerLn1qt/fFat
	 wzeO+h6UqXrfwiRNAvEahX7Kx+cIbKb7Kbc7nj7U=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1725925AbgENIKa (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 04:10:30 -0400
Received: from mail.kernel.org ([198.145.29.99]:49114 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725886AbgENIK3 (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 04:10:29 -0400
Received: from mail-il1-f169.google.com (mail-il1-f169.google.com [209.85.166.169])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mail.kernel.org (Postfix) with ESMTPSA id 450FE2065D
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 08:10:29 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1589443829;
        bh=Xf8DEKxe/HcjD/EnXUO0eGUCvnkUXJ1xE0FLARkXWGA=;
        h=References:In-Reply-To:From:Date:Subject:To:Cc:From;
        b=duE6MUlt6a33ZXoDy7N06eQHQyJ/iHiLmi5D2wHAxeAgbOknJICTp+xqAdplGkW2j
         i5XrVwIx/uQ1IcFBHeuzfv3bUp8sGlSKGrLqMK59hWGrvIfGZqLtF7vo9qIqTLR6Du
         Lpp/rMgvabhQTGnRggk1LoQiN29/oHbTvEp1DotI=
Received: by mail-il1-f169.google.com with SMTP id b15so840349ilq.12
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 01:10:29 -0700 (PDT)
X-Gm-Message-State: AOAM533m1h3cqi4ZGA9I9Q0jmqODYuIE+yJ0A3BjoNzAyhXYLqjVbkKC
        TgR99vwC0ag3ughtTKvvEXHOszATxku9PpKFzRs=
X-Google-Smtp-Source: ABdhPJzLDW5i+bsVSa0+yv6nTiwlQQoNIUBFaLtTnTHWfUUOiQdB3YRebMCuPtmgfnVQxRKwkMV+5PD5wlM31zp8nLY=
X-Received: by 2002:a92:a312:: with SMTP id a18mr3541237ili.80.1589443828605;
 Thu, 14 May 2020 01:10:28 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
 <ab9df4468cc294c67a67ef336019379033e7c90c.camel@linux.intel.com>
In-Reply-To: <ab9df4468cc294c67a67ef336019379033e7c90c.camel@linux.intel.com>
From:   Ard Biesheuvel <ardb@kernel.org>
Date:   Thu, 14 May 2020 10:10:17 +0200
X-Gmail-Original-Message-ID: <CAMj1kXHX2Hf_QeKF4m-4yfjzcM2=AFV-EzthQvDO1pOsyaSsZw@mail.gmail.com>
Message-ID: <CAMj1kXHX2Hf_QeKF4m-4yfjzcM2=AFV-EzthQvDO1pOsyaSsZw@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>,
        linux-integrity@vger.kernel.org,
        Matthew Garrett <matthewgarrett@google.com>, javierm@redhat.com
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, 14 May 2020 at 03:09, Jarkko Sakkinen
<jarkko.sakkinen@linux.intel.com> wrote:
>
> On Tue, 2020-05-12 at 08:44 +0200, Ard Biesheuvel wrote:
> > Hi Lo=C3=AFc,
> >
> > Thanks for the fix.
> >
> > On Tue, 12 May 2020 at 06:01, Lo=C3=AFc Yhuel <loic.yhuel@gmail.com> wr=
ote:
> > > This fixes the boot issues since 5.3 on several Dell models when the =
TPM
> > > is enabled. Depending on the exact grub binary, booting the kernel wo=
uld
> > > freeze early, or just report an error parsing the final events log.
> > >
> > > We get an event log in the SHA-1 format, which doesn't have a
> > > tcg_efi_specid_event_head in the first event, and there is a final ev=
ents
> > > table which doesn't match the crypto agile format.
> > > __calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", a=
nd
> > > either fails, or loops long enough for the machine to be appear froze=
n.
> > >
> > > So we now only parse the final events table, which is per the spec al=
ways
> > > supposed to be in the crypto agile format, when we got a event log in=
 this
> > > format.
> > >
> >
> > So what functionality do we lose here? Can we still make meaningful
> > use of the event log without the final log? I thought one was
> > incomplete without the other?
>
>
> Nope it would be incomplete [*].
>
> So probably would make sense to at least issue a warning in this case.
>
> [*] https://www.kernel.org/doc/Documentation/security/tpm/tpm_event_log.r=
st
>

Right.

I'll take the current patch as a fix for now.

I agree it makes sense to add a warning, but I'd like to understand
better which exact condition we should warn about.
Currently, tpm_read_log_efi() simply disregards the final log if it is
not in crypto agile format, but is there any point to exposing
anything in that case?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 3DA06C433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 10:51:57 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 26A6D20575
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 10:51:57 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726202AbgENKv4 (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 06:51:56 -0400
Received: from mga06.intel.com ([134.134.136.31]:23270 "EHLO mga06.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1726015AbgENKv4 (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 06:51:56 -0400
IronPort-SDR: tefQ+fuE/yM/C0NNxBEbpuXQqERNCz0lwggjminhOS8x6ic0q6BErv2goSbGmhK8rXsV3MhVJy
 jZ4IdA9uakVw==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga006.jf.intel.com ([10.7.209.51])
  by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2020 03:51:55 -0700
IronPort-SDR: 46gXR2FOU1CoYboCW4wd1pF2D2k8gL53ixan8bWkgETCODT1YK9wVtHmz6WXGaeemSCYbludmZ
 CbO8F9kw3+Dw==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.73,391,1583222400"; 
   d="scan'208";a="266202646"
Received: from apogrebi-mobl2.ger.corp.intel.com ([10.249.39.119])
  by orsmga006.jf.intel.com with ESMTP; 14 May 2020 03:51:53 -0700
Message-ID: <aa633c59f845817f7ada8089f29638bdfdb016a3.camel@linux.intel.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
From:   Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To:     Ard Biesheuvel <ardb@kernel.org>,
        =?ISO-8859-1?Q?Lo=EFc?= Yhuel <loic.yhuel@gmail.com>
Cc:     linux-integrity@vger.kernel.org,
        Matthew Garrett <matthewgarrett@google.com>, javierm@redhat.com
Date:   Thu, 14 May 2020 13:51:53 +0300
In-Reply-To: <CAMj1kXFPt4eSDCC61paWhyfOaEeWUgUQSnczwZJ7Eny8t7ow5g@mail.gmail.com>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
         <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
         <CANMwUkg+2O2nK8z38HZw6z0NdLUPwj40m4DPKmn1sf9oDqG7Pw@mail.gmail.com>
         <CAMj1kXFPt4eSDCC61paWhyfOaEeWUgUQSnczwZJ7Eny8t7ow5g@mail.gmail.com>
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.36.1-2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Tue, 2020-05-12 at 14:30 +0200, Ard Biesheuvel wrote:
> On Tue, 12 May 2020 at 13:40, Loïc Yhuel <loic.yhuel@gmail.com> wrote:
> > Le mar. 12 mai 2020 à 08:45, Ard Biesheuvel <ardb@kernel.org> a écrit :
> > > So what functionality do we lose here? Can we still make meaningful
> > > use of the event log without the final log? I thought one was
> > > incomplete without the other?
> > The char driver (drivers/char/tpm/eventlog/efi.c), already ignores
> > efi.tpm_final_log
> > if the event log version isn't EFI_TCG2_EVENT_LOG_FORMAT_TCG_2.
> > So there currently no code making use of the final log contents on
> > those machines,
> > besides the two cases I patched which only try to determine its size.
> > 
> 
> Ah ok, thanks for clarifying. If we never consume it anyway, then I
> agree this is the correct fix.

I think issuing a warning would not be a bad idea given the incompleteness
of the even log.

/Jarkko


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 31302C433E0
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 10:54:03 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 1503020575
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 10:54:03 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726011AbgENKyC (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 06:54:02 -0400
Received: from mga07.intel.com ([134.134.136.100]:26216 "EHLO mga07.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725925AbgENKyC (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 06:54:02 -0400
IronPort-SDR: BKH5TBhPJVnTMblNw6OHK9vooXd6G6qWof8KSHgmbN742LHkEGCf101o4MjNZdB293JMkK9Y2m
 ncoVv4gMktfA==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga006.jf.intel.com ([10.7.209.51])
  by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2020 03:54:02 -0700
IronPort-SDR: d7Xwa4+QlcoDO5TCeicGMdaj4kDvLVY2XhwpVWpIV7Q8SLhC2YjN1UhK8jQ6e37aOcZZIAjTfr
 gAw92wGkouPQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.73,391,1583222400"; 
   d="scan'208";a="266203020"
Received: from apogrebi-mobl2.ger.corp.intel.com ([10.249.39.119])
  by orsmga006.jf.intel.com with ESMTP; 14 May 2020 03:54:00 -0700
Message-ID: <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
From:   Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To:     Matthew Garrett <mjg59@google.com>,
        =?ISO-8859-1?Q?Lo=EFc?= Yhuel <loic.yhuel@gmail.com>
Cc:     linux-integrity <linux-integrity@vger.kernel.org>,
        Ard Biesheuvel <ardb@kernel.org>,
        Javier Martinez Canillas <javierm@redhat.com>
Date:   Thu, 14 May 2020 13:53:59 +0300
In-Reply-To: <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
         <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.36.1-2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Tue, 2020-05-12 at 13:08 -0700, Matthew Garrett wrote:
> On Mon, May 11, 2020 at 9:01 PM Loïc Yhuel <loic.yhuel@gmail.com> wrote:
> 
> > We get an event log in the SHA-1 format, which doesn't have a
> > tcg_efi_specid_event_head in the first event, and there is a final events
> > table which doesn't match the crypto agile format.
> 
> This seems like a firmware bug, but we definitely shouldn't fail as a result.
> 
> Reviewed-by: Matthew Garrett <mjg59@google.com>

So it is clear that "pr_warn(FW_BUG ..." would be a sane to have there.

/Jarkko


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,
	URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 295CEC433E0
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 11:28:30 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id EE3DB206A5
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 11:28:29 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hL5fV5rZ"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726011AbgENL23 (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 07:28:29 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35336 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1726010AbgENL23 (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 07:28:29 -0400
Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50691C061A0C
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 04:28:29 -0700 (PDT)
Received: by mail-il1-x134.google.com with SMTP id w18so2886616ilm.13
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 04:28:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=+IdqknttVh5/K1Sdf3ytc/NygnuBZXyGJs6YURDEGek=;
        b=hL5fV5rZ3xSKvUN8t2pQUV+QP2gL5hRwR2Bt1EkcNoBe8qRMlEObs0cb6TolXQCPQE
         G1czOvsiMRRw1pUi+ZcEcLgd2PvjKbGPwD4zbVSBvCTkXFuADP4ZxOdbsACUixh2qR+6
         UtY7uQ4yj0chkHBfYPCFhv49J1QjyPtJUAuTJwMSqnxZ3MXlFsBaYN6e/KDVTKBozVGO
         SggdmNWEqP0TzB4P/jvjZcVDLSp5xIHXljqtK4KE8xoakeDz9moBTTQ6Tn/Cdb8IJMwf
         RqiZKJwV8zjD1/JDO/C5KfgwhaNhL6GtViiDJsHwjJLI4fDDu0Jr/DGNvsjggC8ywJKE
         OrLQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=+IdqknttVh5/K1Sdf3ytc/NygnuBZXyGJs6YURDEGek=;
        b=iwcE3QB5xHh+jqlBIHtyMaJBa20Yc9E5tIJ9WJTNAgSMWFGntjASqtIR1thof+AH1q
         +XzsYpZzU7mbKUlCg++db5/acqT0x95XNd19Zn/j1QJI2TOcKZ2KZc6hcrxStFYOy2aR
         9qp7PMylsn0ybauBeDVGfnnBQKxMad6tlWkzHw97wrRiHbEuk30F85SpgXVlUVYMRcC4
         258EDoygQtTkpbw86g7KxdQRgtWuP4rlns3DABF2cUsbBHfswJBxhZo47jGBL6fCnGyw
         AUTtnrysZYT9IHnKGxWqzGpEqkVIWjnyaVAIhGhJ6J2HpmFsiHqrPl83u9CKGALv38OZ
         0Vhw==
X-Gm-Message-State: AOAM530yJVy6v7VLoHBdwwJpxaxvXIma6eAqOA6P5u90kTOTO0C1/q8y
        lnQRteIYZhMx2P0Hfndd/V1EmoSiCpeGgI5nc5o=
X-Google-Smtp-Source: ABdhPJyIvmOPRf0Z/gYMetcCIknefxd1zlTaiKSYf2LbWqDLMKOqGBeB/k3Mqifq87XbTUkq1gg7q88H+okKV6QRbP4=
X-Received: by 2002:a92:3a81:: with SMTP id i1mr785232ilf.234.1589455708679;
 Thu, 14 May 2020 04:28:28 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
In-Reply-To: <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
From:   =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Date:   Thu, 14 May 2020 13:28:16 +0200
Message-ID: <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc:     Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>,
        Ard Biesheuvel <ardb@kernel.org>,
        Javier Martinez Canillas <javierm@redhat.com>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Le jeu. 14 mai 2020 =C3=A0 12:54, Jarkko Sakkinen
<jarkko.sakkinen@linux.intel.com> a =C3=A9crit :
> So it is clear that "pr_warn(FW_BUG ..." would be a sane to have there.
So only to tell the UEFI might have logged events the kernel can't read ?
There is no warning if the table is missing, which would have the same resu=
lt.

I can try to dump it, perhaps it is using the SHA-1 log format.
If so, would a patch to support this non-standard behavior be accepted ?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS
	autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 02DBDC433E0
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 11:31:47 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id C3A12206A5
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 11:31:46 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1589455906;
	bh=PuzTH6CqhLggZ8jZbx8qtWT/CeRl5Dq+4vHb6iz0WfE=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From;
	b=DdW6vxowPisuEBgYO3qhqgVw8Vz0fI3IMIxlxyGvhXNodOZUET/QD62Dgy7RFkqmX
	 4U3/lNytyds3yQIW4c2EkmtExa3zQimSkGe201eEptDLgkI6lajXb19SiLxAAA7Kpv
	 pP/3bBnz3NSZkTAdWKs//1I0PQnb4We9fHG1MEj0=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726056AbgENLbq (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 07:31:46 -0400
Received: from mail.kernel.org ([198.145.29.99]:53416 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1726010AbgENLbq (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 07:31:46 -0400
Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mail.kernel.org (Postfix) with ESMTPSA id AA8DF206A5
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 11:31:45 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1589455905;
        bh=PuzTH6CqhLggZ8jZbx8qtWT/CeRl5Dq+4vHb6iz0WfE=;
        h=References:In-Reply-To:From:Date:Subject:To:Cc:From;
        b=WZGfAWRxyoS06JCg7Ou0G6BLDFrugLP4LCq/NSFak79u+9k5TUddwq0m50vr2ihbx
         m8tUpNzc1ZNaf/gIqx3ffvCoNJi7EW8nd1NSMv3DzLoTeUhneFMVixOzLeSpoDc5oe
         CqfC7iRj4W31vTTKB2wYKK5piKHyd3yrbtoVtqoA=
Received: by mail-io1-f42.google.com with SMTP id f3so2633949ioj.1
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 04:31:45 -0700 (PDT)
X-Gm-Message-State: AOAM531Z6oE0Rp6oK9/StAadliTrgNiKgsnSFKBj9UWhWMKdhbtejjie
        rvIarkodYPueXeDRzP+iEYZU6lMv9OJaajYr7eI=
X-Google-Smtp-Source: ABdhPJwy0miA6l+83er/64OnU+6cQdypzxrSsrfA+kNjqkksdvlk9+KbN0kw4ozZO5XFwhLAE3AUJSMjM0mjo7ic/7M=
X-Received: by 2002:a5d:9b8a:: with SMTP id r10mr3628751iom.171.1589455905082;
 Thu, 14 May 2020 04:31:45 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com> <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
In-Reply-To: <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
From:   Ard Biesheuvel <ardb@kernel.org>
Date:   Thu, 14 May 2020 13:31:33 +0200
X-Gmail-Original-Message-ID: <CAMj1kXEUTdmudiB5aKeDAkYhv5jbwzBQ4cOrxK8VOt8O8Xjk=Q@mail.gmail.com>
Message-ID: <CAMj1kXEUTdmudiB5aKeDAkYhv5jbwzBQ4cOrxK8VOt8O8Xjk=Q@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Cc:     Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>,
        Javier Martinez Canillas <javierm@redhat.com>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, 14 May 2020 at 13:28, Lo=C3=AFc Yhuel <loic.yhuel@gmail.com> wrote:
>
> Le jeu. 14 mai 2020 =C3=A0 12:54, Jarkko Sakkinen
> <jarkko.sakkinen@linux.intel.com> a =C3=A9crit :
> > So it is clear that "pr_warn(FW_BUG ..." would be a sane to have there.
> So only to tell the UEFI might have logged events the kernel can't read ?
> There is no warning if the table is missing, which would have the same re=
sult.
>
> I can try to dump it, perhaps it is using the SHA-1 log format.
> If so, would a patch to support this non-standard behavior be accepted ?

That is why I was asking the question: what exact condition should we
warn about? And at which point?

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,
	MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,
	USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 7F390C433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 11:33:33 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 54377206A5
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 11:33:33 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="G0GbdAP9"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726140AbgENLdd (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 07:33:33 -0400
Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49610 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1726010AbgENLdc (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 07:33:32 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1589456010;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         content-transfer-encoding:content-transfer-encoding:
         in-reply-to:in-reply-to:references:references;
        bh=2g8xrqpnBtZg1yEipPkcil9Ez0ybDcEwF2eaj66C9Vc=;
        b=G0GbdAP9GnbhQn/lwsP+oNMDl7UtctAAyNMw2iPgg/UQqlTWBq76VpDgoPSHAh5geQbu/4
        YWlqQ44vkyd+b15r4H9tILQ9sN1KKrms9X0simjXTNz8VSEnM2gcl41TYAxOWHW4d8BLjI
        eLMFGolCPOxVh9wFolxOJczV6/zmXKg=
Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com
 [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-470-gETNiqYlPUudHB4cqL0sbg-1; Thu, 14 May 2020 07:33:28 -0400
X-MC-Unique: gETNiqYlPUudHB4cqL0sbg-1
Received: by mail-wm1-f71.google.com with SMTP id n124so357944wma.1
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 04:33:28 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:cc:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :content-transfer-encoding;
        bh=2g8xrqpnBtZg1yEipPkcil9Ez0ybDcEwF2eaj66C9Vc=;
        b=NpvUpePMP+GfKPwVaYwSG1i1uo3Ulyo5l++p5bT9F3SPt9bgXroDh+Qk8nC31g4nck
         41+yWPcc/RGGHKp4NwdV7o/gn7vc3T/B24p68JG+x9dpYZT+rt9XiSFs7O3oMnh8v+PV
         Bjng+U+AdmHe6Ft+Ibt8p7bkKVzbR/GFyElxwglDa2f0xoDfjxiv0iHG2H3FAn31Uxoy
         9uXSEn7z89AP+3Q/FUtnA7dez3Dy/qtwcXHbZhA+516mY31OuIBjRC9gr05UZBIRP+zE
         Bm87YmAkCzrBOAuLfpPLhJGoVvn1bHi6eWVCOLz6gWJJ2g7KTVTzXFIKcm78LrpIZx0H
         TWfg==
X-Gm-Message-State: AGi0PuYn7Een9gdw4YSao925xYEh6bhLbpw0CCGre5o5Uh+DhBijkd1o
        eu/F9sclfkdoZVF3V46PMLtLZrpZhHmQnF+xI8mPGZcH+/gTfyhC792Xij5zNDjKsW2WZiSm1oF
        V6MZUv1C6Fj8OpAZctXKmw8EFOA/t
X-Received: by 2002:a7b:c413:: with SMTP id k19mr22196327wmi.124.1589456007211;
        Thu, 14 May 2020 04:33:27 -0700 (PDT)
X-Google-Smtp-Source: APiQypKSA61mh33hpVAOC1brJkMUy8uokt2zP/EYoEz71EIbFd3gKs9Rp40tA03od660Vs6zwVFrOA==
X-Received: by 2002:a7b:c413:: with SMTP id k19mr22196313wmi.124.1589456006930;
        Thu, 14 May 2020 04:33:26 -0700 (PDT)
Received: from ?IPv6:2a01:c50f:ab80:6700:527f:85b3:5615:ff0b? ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b])
        by smtp.gmail.com with ESMTPSA id v126sm11268861wmb.4.2020.05.14.04.33.25
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Thu, 14 May 2020 04:33:26 -0700 (PDT)
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     =?UTF-8?Q?Lo=c3=afc_Yhuel?= <loic.yhuel@gmail.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc:     Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>,
        Ard Biesheuvel <ardb@kernel.org>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
 <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
From:   Javier Martinez Canillas <javierm@redhat.com>
Message-ID: <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
Date:   Thu, 14 May 2020 13:33:24 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.7.0
MIME-Version: 1.0
In-Reply-To: <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Hello Loïc,

On 5/14/20 1:28 PM, Loïc Yhuel wrote:
> Le jeu. 14 mai 2020 à 12:54, Jarkko Sakkinen
> <jarkko.sakkinen@linux.intel.com> a écrit :
>> So it is clear that "pr_warn(FW_BUG ..." would be a sane to have there.
> So only to tell the UEFI might have logged events the kernel can't read ?
> There is no warning if the table is missing, which would have the same result.
> 
> I can try to dump it, perhaps it is using the SHA-1 log format.
> If so, would a patch to support this non-standard behavior be accepted ?
>

I was thinking the same and wrote the following (untested) patch that should
expose the logs from this Final Events Table that is not following the spec.

>From a08ec2b99b62b3ce97c0906527d5d11f41c255a6 Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Thu, 14 May 2020 13:29:42 +0200
Subject: [RFC PATCH] tpm: Append logs from the Final Events table also for SHA1
 format

The Final Events Table contains the logs for any events that are triggered
by ExitBootServices(). According to the TCG EFI Protocol Specification the
table will only contains log entries using the crypto agile log format.

But some EFI firmwares seems to expose a Final Events Table even when the
SHA-1 log format is used. This is not supported according to the TCG spec,
but there is also no other way to get a complete TPM event log for SHA-1
if ExitBootServices() extends PCR5.

Currently the kernel only queries for the Final Events Log when using the
crypto agile log format, which is the correct behaviour to be compliant
with the spec. But since there are firmwares that provide the table even
for the SHA-1 log format, attempt to get it and append the final logs to
the TPM event log that is exposed to user-space.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
 drivers/char/tpm/eventlog/efi.c    |  3 +--
 drivers/firmware/efi/libstub/tpm.c | 18 ++++++++++++------
 drivers/firmware/efi/tpm.c         | 21 +++++++++++++++------
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c
index 6bb023de17f..4a8200c9445 100644
--- a/drivers/char/tpm/eventlog/efi.c
+++ b/drivers/char/tpm/eventlog/efi.c
@@ -61,8 +61,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
 	ret = tpm_log_version;
 
 	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
-	    efi_tpm_final_log_size == 0 ||
-	    tpm_log_version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
+	    efi_tpm_final_log_size == 0)
 		goto out;
 
 	final_tbl = memremap(efi.tpm_final_log,
diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libstub/tpm.c
index e9a684637b7..ba9d3ac2e19 100644
--- a/drivers/firmware/efi/libstub/tpm.c
+++ b/drivers/firmware/efi/libstub/tpm.c
@@ -127,10 +127,9 @@ void efi_retrieve_tpm2_eventlog(void)
 	 * Figure out whether any events have already been logged to the
 	 * final events structure, and if so how much space they take up
 	 */
-	if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
-		final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
+	final_events_table = get_efi_config_table(LINUX_EFI_TPM_FINAL_LOG_GUID);
 	if (final_events_table && final_events_table->nr_events) {
-		struct tcg_pcr_event2_head *header;
+		void *header;
 		int offset;
 		void *data;
 		int event_size;
@@ -142,9 +141,16 @@ void efi_retrieve_tpm2_eventlog(void)
 
 		while (i > 0) {
 			header = data + offset + final_events_size;
-			event_size = __calc_tpm2_event_size(header,
-						   (void *)(long)log_location,
-						   false);
+			if (version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
+				event_size = __calc_tpm2_event_size(header,
+						(void *)(long)log_location,
+								    false);
+			} else {
+				struct tcpa_event *event =
+					(struct tcpa_event *)header;
+				event_size = sizeof(*event) + event->event_size;
+			}
+
 			final_events_size += event_size;
 			i--;
 		}
diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index 77e101a395e..0962d566481 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -16,14 +16,24 @@
 int efi_tpm_final_log_size;
 EXPORT_SYMBOL(efi_tpm_final_log_size);
 
-static int __init tpm2_calc_event_log_size(void *data, int count, void *size_info)
+static int __init tpm2_calc_event_log_size(void *data, int count,
+					   struct linux_efi_tpm_eventlog *log)
 {
-	struct tcg_pcr_event2_head *header;
+	void *header;
 	int event_size, size = 0;
+	struct tcpa_event *event;
 
 	while (count > 0) {
 		header = data + size;
-		event_size = __calc_tpm2_event_size(header, size_info, true);
+		if (log->version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
+			event_size = __calc_tpm2_event_size(header,
+							    (void *)log->log,
+							    true);
+		} else {
+			event = (struct tcpa_event *)header;
+			event_size = sizeof(*event) + event->event_size;
+		}
+
 		if (event_size == 0)
 			return -1;
 		size += event_size;
@@ -62,8 +72,7 @@ int __init efi_tpm_eventlog_init(void)
 	tbl_size = sizeof(*log_tbl) + log_tbl->size;
 	memblock_reserve(efi.tpm_log, tbl_size);
 
-	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
-	    log_tbl->version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
+	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR)
 		goto out;
 
 	final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));
@@ -84,7 +93,7 @@ int __init efi_tpm_eventlog_init(void)
 
 		tbl_size = tpm2_calc_event_log_size(events,
 						    final_tbl->nr_events,
-						    log_tbl->log);
+						    log_tbl);
 	}
 
 	if (tbl_size < 0) {
-- 
2.26.2

Best regards,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,
	SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id BA9A0C433E0
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 12:29:00 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 9425120727
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 12:29:00 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1589459340;
	bh=LublLW5V70u4VL/HwQ23bC7aUgA/qOoEt8EUhKO0uUQ=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From;
	b=Xsv0fY3twSK7bLxB24jwGVkyL96En5nAdG7fyBA81FUOwyRRu5uaRdo7hnBfVV3nh
	 euSYprKoKzbi6bajXOh7A2KE0+MBN2fJ9u4qm+ASwizbqV/tB0vsBOcGeDvx3VR+5S
	 9RZ1zXvNy+r98bywp1iw/Piqss7c6cpyCoCA+cX4=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726245AbgENM26 (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 08:28:58 -0400
Received: from mail.kernel.org ([198.145.29.99]:59650 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1725925AbgENM26 (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 08:28:58 -0400
Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mail.kernel.org (Postfix) with ESMTPSA id D7F3020734
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 12:28:56 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1589459336;
        bh=LublLW5V70u4VL/HwQ23bC7aUgA/qOoEt8EUhKO0uUQ=;
        h=References:In-Reply-To:From:Date:Subject:To:Cc:From;
        b=CsMRbKHDoM8Ax6JkTXQ1o+M00AkzzLB7x8CKpcRyD0t93wSwhu43709F2f1YyGXls
         2icjuFKtrKQBFIOFhEufrJt2T04O/74EvTMdlFpCenntL4cgsecoMpxAUaU7cWyjKJ
         d2YyhVhiwUxDj2I9yHOiNXyDqM/L3jODTbMr2vYE=
Received: by mail-io1-f48.google.com with SMTP id x5so192517ioh.6
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 05:28:56 -0700 (PDT)
X-Gm-Message-State: AOAM530bRdjgz4Z1nL92HK6jZs7g/4D2n+edSYN+5/kA4ukN16l4SaxC
        yoVTiA0KHdJMBw7E7LZygOAFiCghBvK/1xWAKgA=
X-Google-Smtp-Source: ABdhPJzMIYY2trcECno64MDB46AnYaqNYqF3Y/FuOmK+oAIfbr008KPGJVyg87Sv7mMe6Jt5zxYeKu6wc3OIJtq1vOY=
X-Received: by 2002:a6b:5008:: with SMTP id e8mr3829472iob.161.1589459336166;
 Thu, 14 May 2020 05:28:56 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com> <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
In-Reply-To: <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
From:   Ard Biesheuvel <ardb@kernel.org>
Date:   Thu, 14 May 2020 14:28:45 +0200
X-Gmail-Original-Message-ID: <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
Message-ID: <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Javier Martinez Canillas <javierm@redhat.com>
Cc:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, 14 May 2020 at 13:33, Javier Martinez Canillas
<javierm@redhat.com> wrote:
>
> Hello Lo=C3=AFc,
>
> On 5/14/20 1:28 PM, Lo=C3=AFc Yhuel wrote:
> > Le jeu. 14 mai 2020 =C3=A0 12:54, Jarkko Sakkinen
> > <jarkko.sakkinen@linux.intel.com> a =C3=A9crit :
> >> So it is clear that "pr_warn(FW_BUG ..." would be a sane to have there=
.
> > So only to tell the UEFI might have logged events the kernel can't read=
 ?
> > There is no warning if the table is missing, which would have the same =
result.
> >
> > I can try to dump it, perhaps it is using the SHA-1 log format.
> > If so, would a patch to support this non-standard behavior be accepted =
?
> >
>
> I was thinking the same and wrote the following (untested) patch that sho=
uld
> expose the logs from this Final Events Table that is not following the sp=
ec.
>
> From a08ec2b99b62b3ce97c0906527d5d11f41c255a6 Mon Sep 17 00:00:00 2001
> From: Javier Martinez Canillas <javierm@redhat.com>
> Date: Thu, 14 May 2020 13:29:42 +0200
> Subject: [RFC PATCH] tpm: Append logs from the Final Events table also fo=
r SHA1
>  format
>
> The Final Events Table contains the logs for any events that are triggere=
d
> by ExitBootServices().

This is inaccurate afaik. The final events table contains all events
that were logged since the first call to Tcg2::GetEventLog()

> According to the TCG EFI Protocol Specification the
> table will only contains log entries using the crypto agile log format.
>
> But some EFI firmwares seems to expose a Final Events Table even when the
> SHA-1 log format is used. This is not supported according to the TCG spec=
,
> but there is also no other way to get a complete TPM event log for SHA-1
> if ExitBootServices() extends PCR5.
>
> Currently the kernel only queries for the Final Events Log when using the
> crypto agile log format, which is the correct behaviour to be compliant
> with the spec. But since there are firmwares that provide the table even
> for the SHA-1 log format, attempt to get it and append the final logs to
> the TPM event log that is exposed to user-space.
>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
>  drivers/char/tpm/eventlog/efi.c    |  3 +--
>  drivers/firmware/efi/libstub/tpm.c | 18 ++++++++++++------
>  drivers/firmware/efi/tpm.c         | 21 +++++++++++++++------
>  3 files changed, 28 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/=
efi.c
> index 6bb023de17f..4a8200c9445 100644
> --- a/drivers/char/tpm/eventlog/efi.c
> +++ b/drivers/char/tpm/eventlog/efi.c
> @@ -61,8 +61,7 @@ int tpm_read_log_efi(struct tpm_chip *chip)
>         ret =3D tpm_log_version;
>
>         if (efi.tpm_final_log =3D=3D EFI_INVALID_TABLE_ADDR ||
> -           efi_tpm_final_log_size =3D=3D 0 ||
> -           tpm_log_version !=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
> +           efi_tpm_final_log_size =3D=3D 0)
>                 goto out;
>
>         final_tbl =3D memremap(efi.tpm_final_log,
> diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/li=
bstub/tpm.c
> index e9a684637b7..ba9d3ac2e19 100644
> --- a/drivers/firmware/efi/libstub/tpm.c
> +++ b/drivers/firmware/efi/libstub/tpm.c
> @@ -127,10 +127,9 @@ void efi_retrieve_tpm2_eventlog(void)
>          * Figure out whether any events have already been logged to the
>          * final events structure, and if so how much space they take up
>          */
> -       if (version =3D=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
> -               final_events_table =3D get_efi_config_table(LINUX_EFI_TPM=
_FINAL_LOG_GUID);
> +       final_events_table =3D get_efi_config_table(LINUX_EFI_TPM_FINAL_L=
OG_GUID);
>         if (final_events_table && final_events_table->nr_events) {
> -               struct tcg_pcr_event2_head *header;
> +               void *header;
>                 int offset;
>                 void *data;
>                 int event_size;
> @@ -142,9 +141,16 @@ void efi_retrieve_tpm2_eventlog(void)
>
>                 while (i > 0) {
>                         header =3D data + offset + final_events_size;
> -                       event_size =3D __calc_tpm2_event_size(header,
> -                                                  (void *)(long)log_loca=
tion,
> -                                                  false);
> +                       if (version =3D=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_=
2) {
> +                               event_size =3D __calc_tpm2_event_size(hea=
der,
> +                                               (void *)(long)log_locatio=
n,
> +                                                                   false=
);
> +                       } else {
> +                               struct tcpa_event *event =3D
> +                                       (struct tcpa_event *)header;
> +                               event_size =3D sizeof(*event) + event->ev=
ent_size;
> +                       }
> +
>                         final_events_size +=3D event_size;
>                         i--;
>                 }
> diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
> index 77e101a395e..0962d566481 100644
> --- a/drivers/firmware/efi/tpm.c
> +++ b/drivers/firmware/efi/tpm.c
> @@ -16,14 +16,24 @@
>  int efi_tpm_final_log_size;
>  EXPORT_SYMBOL(efi_tpm_final_log_size);
>
> -static int __init tpm2_calc_event_log_size(void *data, int count, void *=
size_info)
> +static int __init tpm2_calc_event_log_size(void *data, int count,
> +                                          struct linux_efi_tpm_eventlog =
*log)
>  {
> -       struct tcg_pcr_event2_head *header;
> +       void *header;
>         int event_size, size =3D 0;
> +       struct tcpa_event *event;
>
>         while (count > 0) {
>                 header =3D data + size;
> -               event_size =3D __calc_tpm2_event_size(header, size_info, =
true);
> +               if (log->version =3D=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) =
{
> +                       event_size =3D __calc_tpm2_event_size(header,
> +                                                           (void *)log->=
log,
> +                                                           true);
> +               } else {
> +                       event =3D (struct tcpa_event *)header;
> +                       event_size =3D sizeof(*event) + event->event_size=
;
> +               }
> +
>                 if (event_size =3D=3D 0)
>                         return -1;
>                 size +=3D event_size;
> @@ -62,8 +72,7 @@ int __init efi_tpm_eventlog_init(void)
>         tbl_size =3D sizeof(*log_tbl) + log_tbl->size;
>         memblock_reserve(efi.tpm_log, tbl_size);
>
> -       if (efi.tpm_final_log =3D=3D EFI_INVALID_TABLE_ADDR ||
> -           log_tbl->version !=3D EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
> +       if (efi.tpm_final_log =3D=3D EFI_INVALID_TABLE_ADDR)
>                 goto out;
>
>         final_tbl =3D early_memremap(efi.tpm_final_log, sizeof(*final_tbl=
));
> @@ -84,7 +93,7 @@ int __init efi_tpm_eventlog_init(void)
>
>                 tbl_size =3D tpm2_calc_event_log_size(events,
>                                                     final_tbl->nr_events,
> -                                                   log_tbl->log);
> +                                                   log_tbl);
>         }
>
>         if (tbl_size < 0) {
> --
> 2.26.2
>
> Best regards,
> --
> Javier Martinez Canillas
> Software Engineer - Desktop Hardware Enablement
> Red Hat
>

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-2.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id BA89DC433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 12:56:11 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 9253220727
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 12:56:11 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YXN9DYoc"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726146AbgENM4L (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 08:56:11 -0400
Received: from us-smtp-2.mimecast.com ([207.211.31.81]:45888 "EHLO
        us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL)
        by vger.kernel.org with ESMTP id S1726050AbgENM4L (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 08:56:11 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1589460969;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         content-transfer-encoding:content-transfer-encoding:
         in-reply-to:in-reply-to:references:references;
        bh=TAmoezoC05P96DOudxLb1/r1uRT/iFGquaiotKnIECE=;
        b=YXN9DYoc3Tyssm7IzBSAu5+/3hALfBwPOV2Zat+tKe6cRmpWK/jwrGdGi5J+49G/yCWc3P
        Dr9XA4ppz7JyKbAdUuz8HMx/GBcW3RLoplv0YE4lX/TqLymEQH9mt9abt4OaItPvcXP9NJ
        bb27VpNfsbVxdbcM7gLBKNNmqfky6Jw=
Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com
 [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-377-3N0pAP-zPmyNNDKOXKhB9Q-1; Thu, 14 May 2020 08:56:07 -0400
X-MC-Unique: 3N0pAP-zPmyNNDKOXKhB9Q-1
Received: by mail-wr1-f72.google.com with SMTP id p2so1545573wrm.6
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 05:56:06 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:cc:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :content-transfer-encoding;
        bh=TAmoezoC05P96DOudxLb1/r1uRT/iFGquaiotKnIECE=;
        b=ob9yn5XaT3lFBbrQQGuWa1HoT+Tvhh5ZqlztN9S6W6Wr4dkeeJ0ap5Kz5dTMxP1XFO
         f9mjpQST5h423f+//X7BrdlE3tro1pb6NOx/0ClJUcAP22aNcl0J9E0SMs7sduL8iwRq
         EzFXTlaI262/Zm9ewV82BFBgAdfa+OuocQr1mbR5H9AiMd0pq/NOZGW0MGPLfxzyqw+j
         Zz40P8GK5mvV2+ofFoZPOp2jexxUeQETjY5lregGO8MZ0SPuXqu/9Qy99JI1vy0QicQy
         1d1ka6CSNNbxMsogmPwNmW5zdaG6gNuPS3HnAmq6CPyoll41PNKs0LPwCa/17yWdQWdm
         k1Rg==
X-Gm-Message-State: AOAM530DyxLLUdi/VQPcQhnsVbN75u0XE1va9ffhXAUaVrmJIAiEalwk
        hrPVzSQCJWnOjksUkB7IT1x/LpRvu+/gm6JDd9xoUFEp6/O6y8AUKpqL3Eb5bB5O/2Fl9u6X3yH
        c/tcD9TRrqg9fIj9YRpsC78iOwmGb
X-Received: by 2002:a1c:46c1:: with SMTP id t184mr5712294wma.185.1589460965733;
        Thu, 14 May 2020 05:56:05 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJxjXbUyLQuuOWL+JOQUmn3G1AdsfCYpSP0KN4LxvpraQzEbKZ4xumuN9+gobLqXch7Q2O3gmg==
X-Received: by 2002:a1c:46c1:: with SMTP id t184mr5712279wma.185.1589460965512;
        Thu, 14 May 2020 05:56:05 -0700 (PDT)
Received: from ?IPv6:2a01:c50f:ab80:6700:527f:85b3:5615:ff0b? ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b])
        by smtp.gmail.com with ESMTPSA id x17sm3812412wrp.71.2020.05.14.05.56.04
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Thu, 14 May 2020 05:56:04 -0700 (PDT)
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Ard Biesheuvel <ardb@kernel.org>
Cc:     =?UTF-8?Q?Lo=c3=afc_Yhuel?= <loic.yhuel@gmail.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
 <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
 <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
 <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
From:   Javier Martinez Canillas <javierm@redhat.com>
Message-ID: <789b40ad-3017-b2cc-df15-d2739787d05e@redhat.com>
Date:   Thu, 14 May 2020 14:56:03 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.7.0
MIME-Version: 1.0
In-Reply-To: <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Hello Ard,

On 5/14/20 2:28 PM, Ard Biesheuvel wrote:
> On Thu, 14 May 2020 at 13:33, Javier Martinez Canillas

[snip]

>>
>> The Final Events Table contains the logs for any events that are triggered
>> by ExitBootServices().
> 
> This is inaccurate afaik. The final events table contains all events
> that were logged since the first call to Tcg2::GetEventLog()
> 

Yes, you are correct. After the first call to GetEventLog(), all events
are logged in both the event log and the Final Events Table IIUC.

But what I tried to say is that only the Final Events Table can be used to
obtain the logs for the events triggered by ExitBootServices(). I'll try
to make it more clear if I post this as a proper patch.

I still don't know if something like that would be acceptable or if we
should just consider a bug if a firmware doesn't conform with the spec.

Best regards,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-4.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,
	SPF_PASS autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id A3DA3C433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 13:04:38 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 782F020728
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 13:04:38 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=default; t=1589461478;
	bh=Rbpqw4q9YQgTkPxJMMGrLnrCBwb928GEfYREah7lFfw=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From;
	b=Iy2Jb7yre6j8JxQR/lfSC4OPw7jERDKJXONV6/xkXi8YspF3/sXO2EWiHZfFfsc6J
	 Ly+8eVdK0x5FwNJ3VeTGX8PIixvv+2iDBuKetU7GLTmTe46N3WhoLQf56okbFfDr3I
	 ytb3Rd4pwfv/2ZIReHil9Vj1yTQGjkLzRdakj7qc=
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726056AbgENNEi (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 09:04:38 -0400
Received: from mail.kernel.org ([198.145.29.99]:54616 "EHLO mail.kernel.org"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1726011AbgENNEh (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 09:04:37 -0400
Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170])
        (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
        (No client certificate requested)
        by mail.kernel.org (Postfix) with ESMTPSA id 74F7320748
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 13:04:37 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
        s=default; t=1589461477;
        bh=Rbpqw4q9YQgTkPxJMMGrLnrCBwb928GEfYREah7lFfw=;
        h=References:In-Reply-To:From:Date:Subject:To:Cc:From;
        b=tOP3kNgJAP1oHgsdpqFxABr4mVFhQNXVOr8Uj0f4IG3PuQsX1Zf/xc0tP3fFjilDi
         iojeijRsqTLJVOw6Jtjq9zONgYef5DbObZA4fM62j/uU69AXM5zpB3EzzTmgnD++Nw
         fOZJMQBH8R07BycJG6uMararVXndbfr0G5SK5POo=
Received: by mail-il1-f170.google.com with SMTP id j2so638099ilr.5
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 06:04:37 -0700 (PDT)
X-Gm-Message-State: AOAM5319bz+VVRn8ym0tDPr7CXDjmmZWVK1MGeOqv0ZqJQAYxz2fKOWz
        b0h5TWCH2t3i4M9M7CwsuQUSGDNeE2Rj3CcHBSU=
X-Google-Smtp-Source: ABdhPJwFjYeeA5K6j1xF/B2ekQ+AX0cI3irLgGBLARh87YjDQFTaHoFlks/W88U+ou4Rkh08jog8XWdGSXu2k4r8RWI=
X-Received: by 2002:a92:8555:: with SMTP id f82mr4317839ilh.279.1589461476743;
 Thu, 14 May 2020 06:04:36 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
 <29fb28c4-9642-0265-a926-455377066b75@redhat.com> <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
 <789b40ad-3017-b2cc-df15-d2739787d05e@redhat.com>
In-Reply-To: <789b40ad-3017-b2cc-df15-d2739787d05e@redhat.com>
From:   Ard Biesheuvel <ardb@kernel.org>
Date:   Thu, 14 May 2020 15:04:25 +0200
X-Gmail-Original-Message-ID: <CAMj1kXFs6Z8VwqRMHf_OOZct4xNnNqiVOGBO0TtLfirg7WX8Eg@mail.gmail.com>
Message-ID: <CAMj1kXFs6Z8VwqRMHf_OOZct4xNnNqiVOGBO0TtLfirg7WX8Eg@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Javier Martinez Canillas <javierm@redhat.com>
Cc:     =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>
Content-Type: text/plain; charset="UTF-8"
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, 14 May 2020 at 14:56, Javier Martinez Canillas
<javierm@redhat.com> wrote:
>
> Hello Ard,
>
> On 5/14/20 2:28 PM, Ard Biesheuvel wrote:
> > On Thu, 14 May 2020 at 13:33, Javier Martinez Canillas
>
> [snip]
>
> >>
> >> The Final Events Table contains the logs for any events that are triggered
> >> by ExitBootServices().
> >
> > This is inaccurate afaik. The final events table contains all events
> > that were logged since the first call to Tcg2::GetEventLog()
> >
>
> Yes, you are correct. After the first call to GetEventLog(), all events
> are logged in both the event log and the Final Events Table IIUC.
>
> But what I tried to say is that only the Final Events Table can be used to
> obtain the logs for the events triggered by ExitBootServices(). I'll try
> to make it more clear if I post this as a proper patch.
>
> I still don't know if something like that would be acceptable or if we
> should just consider a bug if a firmware doesn't conform with the spec.
>

I'd like Matt's and Jarkko's take on this - for me, considering it a
bug is just fine. I just want to understand what exactly to warn
about, since we currently silently ignore the lack of a final events
table, while it apparently defeats the purpose of having a log in the
first.

So given that the ordinary event log will contain everything *except*
the events that were logged during EBS(), I agree that the log may
still be useful if those final events only affected PCRs that you
don't care about.

Something like the below perhaps? Should we suppress the warning for
tables of size 0x0?

diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c
index 6bb023de17f1..65bfee8e636d 100644
--- a/drivers/char/tpm/eventlog/efi.c
+++ b/drivers/char/tpm/eventlog/efi.c
@@ -62,8 +62,10 @@ int tpm_read_log_efi(struct tpm_chip *chip)

        if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
            efi_tpm_final_log_size == 0 ||
-           tpm_log_version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
+           tpm_log_version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
+               pr_warn(FW_BUG "TPM Final Event table not found - some
events may be missing\n");
                goto out;
+       }

        final_tbl = memremap(efi.tpm_final_log,
                             sizeof(*final_tbl) + efi_tpm_final_log_size,

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-5.4 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham
	autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id B8468C433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 13:51:51 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 8EAD120671
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 13:51:51 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SvKpDCu+"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726176AbgENNvv (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 09:51:51 -0400
Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56326 "EHLO
        us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org
        with ESMTP id S1726011AbgENNvu (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 09:51:50 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
        s=mimecast20190719; t=1589464308;
        h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
         to:to:cc:cc:mime-version:mime-version:content-type:content-type:
         content-transfer-encoding:content-transfer-encoding:
         in-reply-to:in-reply-to:references:references;
        bh=efjaVrgMBOavtCD7eQNlqVJMXGEwbv20kGqzKX/uDEI=;
        b=SvKpDCu+NxCsrxauhm/mu+PmIjpOPVIZ0dQxgl1qc384i7y1xaF0ZXq3clMk79/1MA55bw
        r+pLhjyl88XvYSMG1owC9jw8TCvnPltVNIjmKQX9JTBRqnBD9drIY+PNjrTs4Ozkp5LAYQ
        KyJJyt2mmFS2qIg4fND89RFOzxdBZzk=
Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com
 [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id
 us-mta-206-4nOMim8INH61yc1wEOcL4g-1; Thu, 14 May 2020 09:51:47 -0400
X-MC-Unique: 4nOMim8INH61yc1wEOcL4g-1
Received: by mail-wm1-f70.google.com with SMTP id k17so4174984wmi.4
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 06:51:46 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:cc:references:from:message-id:date
         :user-agent:mime-version:in-reply-to:content-language
         :content-transfer-encoding;
        bh=efjaVrgMBOavtCD7eQNlqVJMXGEwbv20kGqzKX/uDEI=;
        b=kETbK4sZLL3MjOoCXr0A9Ii5iyaanTuLN3IKGEIODWhkv3OVEAdGsGbgdIR33IQ26n
         u449KmPo9dtSVwgDNxIy3OZqtLCVOXM/2BCtzQ1IZFjxPk7BnNiYjUyfrTio/UF+hOvP
         tZpgRAGhGvgdbehFgC/Z+OOqcXqXYf+syd9cJfCcECLJxFMIMaJaRn+EkWhlbvCrMoX5
         MkjRCQkkDpms575AsLnGQpN7zPEtEZIkwp5nqOoKwuAokWXMgFPve2A3jzCqlZHHqsv+
         VuIGXmHzvvzljEg0j6NVyhwdsd7YTjH694Rn4qWtrzgaA96WxSndBpZbjdbv7DV1Jsw/
         2gKg==
X-Gm-Message-State: AOAM5317Zc29hZJZKwgwOq0cNmUOxrX9pvM/aaZYK47moLTgVUo8rEVf
        TkyH8ty2y8Ay9vOf8HVoMIMvE+nlkAyN+dDcBV0Lc68LOM/Psfmy2LAc87NSmqtazlPvTeYt/L4
        PCcyUiaYED+uE5JxewOAvAVQ696tZ
X-Received: by 2002:adf:c508:: with SMTP id q8mr5360650wrf.4.1589464305020;
        Thu, 14 May 2020 06:51:45 -0700 (PDT)
X-Google-Smtp-Source: ABdhPJye1Qfo71M6H8Dj93MK9d23hfv1t0aHOb9vA4ScEg1DRVfmR8/wA/U+EkSlNRglkF1evbhAkQ==
X-Received: by 2002:adf:c508:: with SMTP id q8mr5360633wrf.4.1589464304811;
        Thu, 14 May 2020 06:51:44 -0700 (PDT)
Received: from ?IPv6:2a01:c50f:ab80:6700:527f:85b3:5615:ff0b? ([2a01:c50f:ab80:6700:527f:85b3:5615:ff0b])
        by smtp.gmail.com with ESMTPSA id a15sm3984912wrw.56.2020.05.14.06.51.43
        (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
        Thu, 14 May 2020 06:51:43 -0700 (PDT)
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Ard Biesheuvel <ardb@kernel.org>
Cc:     =?UTF-8?Q?Lo=c3=afc_Yhuel?= <loic.yhuel@gmail.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
 <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
 <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
 <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
 <789b40ad-3017-b2cc-df15-d2739787d05e@redhat.com>
 <CAMj1kXFs6Z8VwqRMHf_OOZct4xNnNqiVOGBO0TtLfirg7WX8Eg@mail.gmail.com>
From:   Javier Martinez Canillas <javierm@redhat.com>
Message-ID: <9ebd9e60-12dd-a6df-923c-dc9c6dbd709b@redhat.com>
Date:   Thu, 14 May 2020 15:51:42 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.7.0
MIME-Version: 1.0
In-Reply-To: <CAMj1kXFs6Z8VwqRMHf_OOZct4xNnNqiVOGBO0TtLfirg7WX8Eg@mail.gmail.com>
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On 5/14/20 3:04 PM, Ard Biesheuvel wrote:
> On Thu, 14 May 2020 at 14:56, Javier Martinez Canillas

[snip]

>>
>> I still don't know if something like that would be acceptable or if we
>> should just consider a bug if a firmware doesn't conform with the spec.
>>
> 
> I'd like Matt's and Jarkko's take on this - for me, considering it a
> bug is just fine. I just want to understand what exactly to warn
> about, since we currently silently ignore the lack of a final events
> table, while it apparently defeats the purpose of having a log in the
> first.
>
> So given that the ordinary event log will contain everything *except*
> the events that were logged during EBS(), I agree that the log may
> still be useful if those final events only affected PCRs that you
> don't care about.
>

Agreed.

> Something like the below perhaps? Should we suppress the warning for
> tables of size 0x0?
>

That's what is not clear to me. For example, if a firmware follows the
spec what happens during EBS() when a TPM2 only supports the SHA-1 format?

Does the firmware always log events during EBS() even when it won't provide
a Final Events Table? If so, are the SHA-1 logs always incomplete?

What I wonder is if the firmware bug error should always be printed if the
crypto agile log format isn't used or only if isn't used and the firmware
provides a Final Events Table, which is a behavior that's out of the spec.

> diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c
> index 6bb023de17f1..65bfee8e636d 100644
> --- a/drivers/char/tpm/eventlog/efi.c
> +++ b/drivers/char/tpm/eventlog/efi.c
> @@ -62,8 +62,10 @@ int tpm_read_log_efi(struct tpm_chip *chip)
> 
>         if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR ||
>             efi_tpm_final_log_size == 0 ||
> -           tpm_log_version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
> +           tpm_log_version != EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) {
> +               pr_warn(FW_BUG "TPM Final Event table not found - some
> events may be missing\n");

Maybe mentioning that the missing logs are for events that happen during EBS()?

>                 goto out;
> +       }
> 
>         final_tbl = memremap(efi.tpm_final_log,
>                              sizeof(*final_tbl) + efi_tpm_final_log_size,
> 

Best regards,
-- 
Javier Martinez Canillas
Software Engineer - Desktop Hardware Enablement
Red Hat


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED,
	DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,
	SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 8C947C433E0
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 18:06:34 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 5E49920675
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 18:06:34 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ptd0FWt2"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1727810AbgENSGd (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 14:06:33 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41228 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL)
        by vger.kernel.org with ESMTP id S1726532AbgENSGd (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 14:06:33 -0400
Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26C10C061A0C
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 11:06:33 -0700 (PDT)
Received: by mail-il1-x12e.google.com with SMTP id r2so1226530ilo.6
        for <linux-integrity@vger.kernel.org>; Thu, 14 May 2020 11:06:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc;
        bh=8qWZjfPNPeZVwJ+ttL8j414cG6OOVM8EPD8XZYqVff0=;
        b=ptd0FWt22/sTokSUEWQqFBto54E3rIiVRfyn8/K9iHJik0OfMrreWGMUvwgQYMv4n3
         Xgg51aO51JNj7KLXHDKEANHgJ2fTIO3rqH/BgFYfuBgJTQPUktdquglQpjui95OWwyXM
         S3OQmpJ359Ttt8Dz1hWLZc1jFVZBPKh/mKOJ5ecF0WfCYmLLqQER6ckmFGK/ALKowAr7
         kvypgXsWSDPi4vJ5pYdTpzRHIbO7DiJMK6cq6lycmmSMr0T/OgFligCbMYvBx8RgKANO
         NIZ/jPmicIV2prwApcvPgwt080iGhAt7p87EmTwj7GApn/sKhIQ5Yz8xIHak98hMyBCu
         xdwA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc;
        bh=8qWZjfPNPeZVwJ+ttL8j414cG6OOVM8EPD8XZYqVff0=;
        b=B9Dami01wCw5Ehl2TAz6DgzNo/t2neSorOPFq3hGa7T5cNdPOlVUrQ71tsGDQ6PRTh
         xhb2XeMYGBC3GWVYbvmIbXXq5twC7GnQ4QTD1jIgxJUjxW5s//npkihxjzbQvHucoAXk
         46cPv/qsADZjlyFofb0svAuBbWg8eI5q6i8ANTQF+wAa191W1WAyl1CX8J4xd8a91E99
         Yb0Rxm8xAHlcGBJziO3Ga8AdoDhIsXRboFu+vSg/OfL8H23CfjkYDOj6t9SCoDb9X2xT
         1zyZNsNI3wXjX9oYSXFMWOK6pfFN9PsPl7Jm2VSJ7kT3MNH1V40179jFn+RYl6aA0iwt
         djeg==
X-Gm-Message-State: AOAM532F3kAimZyFsMQt1BCm78G3S9zkpPR6LbT86VrpzfVCqpJpywQQ
        tKDDkTDAuHZ0wRjcM+KzPjO3j1p+u3bU6y++jVKSHA==
X-Google-Smtp-Source: ABdhPJxQ2G/I+phiA1Oxlw5adMrjtQur2AcgiBWHOsJp9LSYDeOS8LI7xvExvWg9TJjCtc8o/+w8WdCwRpBFyVn4fug=
X-Received: by 2002:a05:6e02:ecb:: with SMTP id i11mr5847140ilk.169.1589479592114;
 Thu, 14 May 2020 11:06:32 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
 <29fb28c4-9642-0265-a926-455377066b75@redhat.com> <CAMj1kXHFKajuvd5KkrQTozebKzaO1LaMQdd37unLs_dGR0UwVg@mail.gmail.com>
 <789b40ad-3017-b2cc-df15-d2739787d05e@redhat.com> <CAMj1kXFs6Z8VwqRMHf_OOZct4xNnNqiVOGBO0TtLfirg7WX8Eg@mail.gmail.com>
 <9ebd9e60-12dd-a6df-923c-dc9c6dbd709b@redhat.com>
In-Reply-To: <9ebd9e60-12dd-a6df-923c-dc9c6dbd709b@redhat.com>
From:   Matthew Garrett <mjg59@google.com>
Date:   Thu, 14 May 2020 11:06:20 -0700
Message-ID: <CACdnJutqe03fypMBSQrXcBovOJ+-Vy0C1T54GJ_BD4miMUq9fQ@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Javier Martinez Canillas <javierm@redhat.com>
Cc:     Ard Biesheuvel <ardb@kernel.org>,
        =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>,
        Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        linux-integrity <linux-integrity@vger.kernel.org>
Content-Type: text/plain; charset="UTF-8"
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, May 14, 2020 at 6:51 AM Javier Martinez Canillas
<javierm@redhat.com> wrote:
> That's what is not clear to me. For example, if a firmware follows the
> spec what happens during EBS() when a TPM2 only supports the SHA-1 format?
>
> Does the firmware always log events during EBS() even when it won't provide
> a Final Events Table? If so, are the SHA-1 logs always incomplete?

In my experience, yes. We deal with this by just brute forcing all
possible PCR5 events until we find a solution that matches.

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=ax+g=64=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no
	autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id 0D695C433DF
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 23:45:30 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id D316A2054F
	for <linux-integrity@archiver.kernel.org>; Thu, 14 May 2020 23:45:29 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726294AbgENXp3 (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 19:45:29 -0400
Received: from mga11.intel.com ([192.55.52.93]:15654 "EHLO mga11.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1726087AbgENXp3 (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 19:45:29 -0400
IronPort-SDR: 6yRLmhgV/4GgiaDZgg+Ge+0FuzmVqBjJ6ZE2IR4KUrRv/roNh2ZDlEnrt7lI/w9sj/DZ45EU8k
 I3Mq25uqsiqg==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga004.jf.intel.com ([10.7.209.38])
  by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2020 16:45:10 -0700
IronPort-SDR: QJjC5KP/0QZ5t28RoYykDPx+zZ2pXQM3doJrw8eAM17sh9hWU3hzMQAYwM7Qp7dii/cECMTdvc
 tn340YMzDtPQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.73,392,1583222400"; 
   d="scan'208";a="410262700"
Received: from ashadrin-mobl1.ccr.corp.intel.com ([10.249.38.112])
  by orsmga004.jf.intel.com with ESMTP; 14 May 2020 16:45:07 -0700
Message-ID: <7f477bcd992f0927a25f8538663c7bad8efb73c1.camel@linux.intel.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
From:   Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To:     Ard Biesheuvel <ardb@kernel.org>
Cc:     =?ISO-8859-1?Q?Lo=EFc?= Yhuel <loic.yhuel@gmail.com>,
        linux-integrity@vger.kernel.org,
        Matthew Garrett <matthewgarrett@google.com>, javierm@redhat.com
Date:   Fri, 15 May 2020 02:44:55 +0300
In-Reply-To: <CAMj1kXHX2Hf_QeKF4m-4yfjzcM2=AFV-EzthQvDO1pOsyaSsZw@mail.gmail.com>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
         <CAMj1kXFfLvUXU1A-7jnh3KMy5Qguhq0k9Cw=O0iBmbToowV_8A@mail.gmail.com>
         <ab9df4468cc294c67a67ef336019379033e7c90c.camel@linux.intel.com>
         <CAMj1kXHX2Hf_QeKF4m-4yfjzcM2=AFV-EzthQvDO1pOsyaSsZw@mail.gmail.com>
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.36.1-2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, 2020-05-14 at 10:10 +0200, Ard Biesheuvel wrote:
> On Thu, 14 May 2020 at 03:09, Jarkko Sakkinen
> <jarkko.sakkinen@linux.intel.com> wrote:
> > On Tue, 2020-05-12 at 08:44 +0200, Ard Biesheuvel wrote:
> > > Hi Loïc,
> > > 
> > > Thanks for the fix.
> > > 
> > > On Tue, 12 May 2020 at 06:01, Loïc Yhuel <loic.yhuel@gmail.com> wrote:
> > > > This fixes the boot issues since 5.3 on several Dell models when the TPM
> > > > is enabled. Depending on the exact grub binary, booting the kernel would
> > > > freeze early, or just report an error parsing the final events log.
> > > > 
> > > > We get an event log in the SHA-1 format, which doesn't have a
> > > > tcg_efi_specid_event_head in the first event, and there is a final events
> > > > table which doesn't match the crypto agile format.
> > > > __calc_tpm2_event_size reads bad "count" and "efispecid->num_algs", and
> > > > either fails, or loops long enough for the machine to be appear frozen.
> > > > 
> > > > So we now only parse the final events table, which is per the spec always
> > > > supposed to be in the crypto agile format, when we got a event log in this
> > > > format.
> > > > 
> > > 
> > > So what functionality do we lose here? Can we still make meaningful
> > > use of the event log without the final log? I thought one was
> > > incomplete without the other?
> > 
> > Nope it would be incomplete [*].
> > 
> > So probably would make sense to at least issue a warning in this case.
> > 
> > [*] https://www.kernel.org/doc/Documentation/security/tpm/tpm_event_log.rst
> > 
> 
> Right.
> 
> I'll take the current patch as a fix for now.
> 
> I agree it makes sense to add a warning, but I'd like to understand
> better which exact condition we should warn about.
> Currently, tpm_read_log_efi() simply disregards the final log if it is
> not in crypto agile format, but is there any point to exposing
> anything in that case?


IMHO just a brief warning that "tail is missing" would be sufficient,
no other info.

/Jarkko


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=HrVK=65=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS,
	MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no
	version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id B9BEDC433E0
	for <linux-integrity@archiver.kernel.org>; Fri, 15 May 2020 00:03:26 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id 8CA58206B6
	for <linux-integrity@archiver.kernel.org>; Fri, 15 May 2020 00:03:26 +0000 (UTC)
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726125AbgEOAD0 (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Thu, 14 May 2020 20:03:26 -0400
Received: from mga06.intel.com ([134.134.136.31]:17796 "EHLO mga06.intel.com"
        rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP
        id S1726088AbgEOAD0 (ORCPT <rfc822;linux-integrity@vger.kernel.org>);
        Thu, 14 May 2020 20:03:26 -0400
IronPort-SDR: g/0Sb2OIhduRYzLkFPrXOhvrbY3ujtNR8RJfYR/Xh4U1kCyXZl2cvs+fSCCisw2Dy097Gy7ynF
 FvRyeryR4hSw==
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga006.jf.intel.com ([10.7.209.51])
  by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2020 17:03:25 -0700
IronPort-SDR: IMU8mvYF/BX3FJs5oOTyEUMla3XtzozhJcao0jL/7xZKH3ZpBvjZISrte25WPNwTCkEYZJTpJj
 m13mDz2d9sZA==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.73,392,1583222400"; 
   d="scan'208";a="266422263"
Received: from ashadrin-mobl1.ccr.corp.intel.com ([10.249.38.112])
  by orsmga006.jf.intel.com with ESMTP; 14 May 2020 17:03:23 -0700
Message-ID: <7dadd27c89860c03d6c2eb0922838ef3e29e8f9b.camel@linux.intel.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
From:   Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To:     Ard Biesheuvel <ardb@kernel.org>,
        =?ISO-8859-1?Q?Lo=EFc?= Yhuel <loic.yhuel@gmail.com>
Cc:     Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>,
        Javier Martinez Canillas <javierm@redhat.com>
Date:   Fri, 15 May 2020 03:03:10 +0300
In-Reply-To: <CAMj1kXEUTdmudiB5aKeDAkYhv5jbwzBQ4cOrxK8VOt8O8Xjk=Q@mail.gmail.com>
References: <20200512040113.277768-1-loic.yhuel@gmail.com>
         <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
         <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
         <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com>
         <CAMj1kXEUTdmudiB5aKeDAkYhv5jbwzBQ4cOrxK8VOt8O8Xjk=Q@mail.gmail.com>
Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.36.1-2 
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

On Thu, 2020-05-14 at 13:31 +0200, Ard Biesheuvel wrote:
> On Thu, 14 May 2020 at 13:28, Loïc Yhuel <loic.yhuel@gmail.com> wrote:
> > Le jeu. 14 mai 2020 à 12:54, Jarkko Sakkinen
> > <jarkko.sakkinen@linux.intel.com> a écrit :
> > > So it is clear that "pr_warn(FW_BUG ..." would be a sane to have there.
> > So only to tell the UEFI might have logged events the kernel can't read ?
> > There is no warning if the table is missing, which would have the same result.
> > 
> > I can try to dump it, perhaps it is using the SHA-1 log format.
> > If so, would a patch to support this non-standard behavior be accepted ?
> 
> That is why I was asking the question: what exact condition should we
> warn about? And at which point?

Always when final table is missing there should be some sort of notification
because the event log is incomplete.

I.e. it misses PCR5 extends from GetEventLog().

No additional info, just a note that we don't have the tail. I'm fine with
info level message too.

/Jarkko


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <SRS0=HrVK=65=vger.kernel.org=linux-integrity-owner@kernel.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on
	aws-us-west-2-korg-lkml-1.web.codeaurora.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID,
	DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,
	HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS
	autolearn=no autolearn_force=no version=3.4.0
Received: from mail.kernel.org (mail.kernel.org [198.145.29.99])
	by smtp.lore.kernel.org (Postfix) with ESMTP id D89F7C433E0
	for <linux-integrity@archiver.kernel.org>; Fri, 15 May 2020 15:55:33 +0000 (UTC)
Received: from vger.kernel.org (vger.kernel.org [23.128.96.18])
	by mail.kernel.org (Postfix) with ESMTP id B6201206D8
	for <linux-integrity@archiver.kernel.org>; Fri, 15 May 2020 15:55:33 +0000 (UTC)
Authentication-Results: mail.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EoquAB9i"
Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand
        id S1726275AbgEOPzd (ORCPT
        <rfc822;linux-integrity@archiver.kernel.org>);
        Fri, 15 May 2020 11:55:33 -0400
Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47978 "EHLO
        lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL)
        by vger.kernel.org with ESMTP id S1726255AbgEOPzb (ORCPT
        <rfc822;linux-integrity@vger.kernel.org>);
        Fri, 15 May 2020 11:55:31 -0400
Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d])
        by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41B90C061A0C
        for <linux-integrity@vger.kernel.org>; Fri, 15 May 2020 08:55:30 -0700 (PDT)
Received: by mail-il1-x12d.google.com with SMTP id t12so3004912ile.9
        for <linux-integrity@vger.kernel.org>; Fri, 15 May 2020 08:55:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=mime-version:references:in-reply-to:from:date:message-id:subject:to
         :cc:content-transfer-encoding;
        bh=0xjdNILmqzRS0OoO8pCb/YOr4IsehWnqDX983vBgYIs=;
        b=EoquAB9iPewpta6TuUVi4h7qywZiPfBqcprnPjy3tazAS/3KyinRxhvZ2VAJ4y8qRf
         HNsizPrCb8TSun9rqrs9P1V8q784lgKwGBP3BbKLvWea3OI2SvyWLBH2TqSE8w642O4I
         BxQCLOh7uaSjsXfV69tLjZ/TBEwVHBeWIeNJLmlQjySuF7oMB//6VZnV5hGDijt9ZJ2l
         w9bu1DJLyZI/RrbLVdNRkfhV6cIaP2iZ4E22qKdlF21qGXuiA4ymLw5DX2kw/jxeJe8Y
         /ZrPUMh9yjgvi2s8m6psrbPY3UWMM55l7PmSsMiJ4NxPmrxpBofQLoDtFXx7wv3MnSHX
         o/Ww==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to:from:date
         :message-id:subject:to:cc:content-transfer-encoding;
        bh=0xjdNILmqzRS0OoO8pCb/YOr4IsehWnqDX983vBgYIs=;
        b=ffFkApluOrNDNh7TmS6GMpor5Z6Fpu9dH0N7dGBBiPhTykKQFuwfFz5hx5CRhk1dwC
         N5DmmePNYPSnkJcJp2D8WG+VPUZO9N18PKx0LjRV4s/Vi7En7gxbkoDxLdrJ6sFSRyQG
         U+y3V/B9cxM3/5dNISYEALoXMPtyMEyXQPJa//anf4+6f7YnExT7ukqele/6ilqaVWHs
         Dui2J9SxsBdGjn9Q3O+m/xzoifQbrwEI72ezFWt8pJKaUxkp6b6dWpWGYzNKJvs5s2So
         ZqmJml10iKMNrn9l6HZaqS9au3HdGfieCjzIz1t5jj42qx4i/evt5rca1B3GiDtbPFvs
         2whQ==
X-Gm-Message-State: AOAM53324r94AqGuyLyTF40Nc9+qfJpH38WAEdUcT75cJv0v9t9KVXlh
        ihIBXByYcP/8Fo3cDfu6bvkN4n3kk/cae6GzWco=
X-Google-Smtp-Source: ABdhPJzX0FnU8IF19JNFRdCCKdFOk2cgz1jYAIg8mVAeHMZ1cwUsHuopnrZWPXznT9YlG6TQjmmJqWa7G7lFGt3bbjQ=
X-Received: by 2002:a92:3d03:: with SMTP id k3mr4026916ila.296.1589558129580;
 Fri, 15 May 2020 08:55:29 -0700 (PDT)
MIME-Version: 1.0
References: <20200512040113.277768-1-loic.yhuel@gmail.com> <CACdnJuv8OyQpO4achWJb2HeB8Jb6Ejq9LsG64659JSay-a9O5A@mail.gmail.com>
 <116341780ff56884d2f03aa9b90a8f9566b91540.camel@linux.intel.com>
 <CANMwUkir2WTA7-J--Y_QFz8ZX5dHNTtLru19FHYew1uyxyKYNA@mail.gmail.com> <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
In-Reply-To: <29fb28c4-9642-0265-a926-455377066b75@redhat.com>
From:   =?UTF-8?Q?Lo=C3=AFc_Yhuel?= <loic.yhuel@gmail.com>
Date:   Fri, 15 May 2020 17:55:18 +0200
Message-ID: <CANMwUkhXYj03ppRej2j-w1f3--k5pM8sT+jTWEQ+hKZ_7Vo8PA@mail.gmail.com>
Subject: Re: [PATCH] tpm: check event log version before reading final events
To:     Javier Martinez Canillas <javierm@redhat.com>
Cc:     Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
        Matthew Garrett <mjg59@google.com>,
        linux-integrity <linux-integrity@vger.kernel.org>,
        Ard Biesheuvel <ardb@kernel.org>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Sender: linux-integrity-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-integrity.vger.kernel.org>
X-Mailing-List: linux-integrity@vger.kernel.org

Le jeu. 14 mai 2020 =C3=A0 13:33, Javier Martinez Canillas
<javierm@redhat.com> a =C3=A9crit :
> I was thinking the same and wrote the following (untested) patch that sho=
uld
> expose the logs from this Final Events Table that is not following the sp=
ec.
> [...]
Thanks, I tried it, and added the missing early_memremap.
But I still got bad values, so I dumped the first 4KB of the table.
It seems to contain events, but they overlap : the last 16 bytes of an
event are overwritten by the following one.
So it seems the UEFI miscalculated the offsets when writing the table,
so gives us data which cannot be used.

