linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Stefan Berger <stefanb@linux.ibm.com>
Cc: peterhuewe@gmx.de, jgg@ziepe.ca, linux-integrity@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] tpm: acpi: Check eventlog signature before using it
Date: Thu, 11 Mar 2021 01:13:31 +0200	[thread overview]
Message-ID: <YElSm4UchdU+W7D7@kernel.org> (raw)
In-Reply-To: <20210310221916.356716-3-stefanb@linux.ibm.com>

On Wed, Mar 10, 2021 at 05:19:15PM -0500, Stefan Berger wrote:
> Check the eventlog signature before using it. This avoids using an
> empty log, as may be the case when QEMU created the ACPI tables,
> rather than probing the EFI log next. This resolves an issue where
> the EFI log was empty since an empty ACPI log was used.
> 
> Fixes: 85467f63a05c ("tpm: Add support for event log pointer found in TPM2 ACPI table")
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
>  drivers/char/tpm/eventlog/acpi.c | 33 +++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c
> index 3633ed70f48f..1b18ce5ebab1 100644
> --- a/drivers/char/tpm/eventlog/acpi.c
> +++ b/drivers/char/tpm/eventlog/acpi.c
> @@ -41,6 +41,27 @@ struct acpi_tcpa {
>  	};
>  };
>  
> +/* Check that the given log is indeed a TPM2 log. */
> +static bool tpm_is_tpm2_log(void *bios_event_log, u64 len)
> +{
> +	struct tcg_efi_specid_event_head *efispecid;
> +	struct tcg_pcr_event *event_header;
> +	int n;
> +
> +	if (len < sizeof(*event_header))
> +		return false;
> +	len -= sizeof(*event_header);
> +	event_header = bios_event_log;
> +
> +	if (len < sizeof(*efispecid))
> +		return false;
> +	efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
> +
> +	n = memcmp(efispecid->signature, TCG_SPECID_SIG,
> +		   sizeof(TCG_SPECID_SIG));
> +	return n == 0;
> +}
> +
>  /* read binary bios log */
>  int tpm_read_log_acpi(struct tpm_chip *chip)
>  {
> @@ -52,6 +73,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
>  	struct acpi_table_tpm2 *tbl;
>  	struct acpi_tpm2_phy *tpm2_phy;
>  	int format;
> +	int ret;
>  
>  	log = &chip->log;
>  
> @@ -112,6 +134,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
>  
>  	log->bios_event_log_end = log->bios_event_log + len;
>  
> +	ret = -EIO;
>  	virt = acpi_os_map_iomem(start, len);
>  	if (!virt)
>  		goto err;
> @@ -119,11 +142,19 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
>  	memcpy_fromio(log->bios_event_log, virt, len);
>  
>  	acpi_os_unmap_iomem(virt, len);
> +
> +	if (chip->flags & TPM_CHIP_FLAG_TPM2 &&
> +	    !tpm_is_tpm2_log(log->bios_event_log, len)) {
> +		/* try EFI log next */
> +		ret = -ENODEV;
> +		goto err;
> +	}
> +
>  	return format;
>  
>  err:
>  	kfree(log->bios_event_log);
>  	log->bios_event_log = NULL;
> -	return -EIO;
> +	return ret;
>  
>  }
> -- 
> 2.29.2
> 
> 

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

/Jarkko

  reply	other threads:[~2021-03-10 23:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 22:19 [PATCH v2 0/3] Fix bugs related to TPM2 event log Stefan Berger
2021-03-10 22:19 ` [PATCH v2 1/3] tpm: efi: Use local variable for calculating final log size Stefan Berger
2021-03-10 23:14   ` Jarkko Sakkinen
2021-03-10 23:21   ` Jarkko Sakkinen
2021-03-10 23:24     ` Jarkko Sakkinen
2021-03-11 14:02       ` Stefan Berger
2021-03-12 16:54         ` Jarkko Sakkinen
2021-03-10 22:19 ` [PATCH v2 2/3] tpm: acpi: Check eventlog signature before using it Stefan Berger
2021-03-10 23:13   ` Jarkko Sakkinen [this message]
2021-03-10 22:19 ` [PATCH v2 3/3] tpm: vtpm_proxy: Avoid reading host log when using a virtual device Stefan Berger
2021-03-10 23:04   ` Jarkko Sakkinen
2021-03-10 23:04 ` [PATCH v2 0/3] Fix bugs related to TPM2 event log Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YElSm4UchdU+W7D7@kernel.org \
    --to=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=stefanb@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).