From patchwork Wed Sep 20 08:13:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Thi=C3=A9baud_Weksteen?= X-Patchwork-Id: 9961083 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7A51F6056A for ; Wed, 20 Sep 2017 08:15:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CB9A28FFC for ; Wed, 20 Sep 2017 08:15:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60AC229013; Wed, 20 Sep 2017 08:15:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB6FA28FFD for ; Wed, 20 Sep 2017 08:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751902AbdITIOX (ORCPT ); Wed, 20 Sep 2017 04:14:23 -0400 Received: from mail-wm0-f73.google.com ([74.125.82.73]:57392 "EHLO mail-wm0-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751671AbdITIOT (ORCPT ); Wed, 20 Sep 2017 04:14:19 -0400 Received: by mail-wm0-f73.google.com with SMTP id 10so97773wmv.16 for ; Wed, 20 Sep 2017 01:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=7UVB0Bvus91U069hIhCOu0NHSTBgIFKqDCvKMnzwYiE=; b=V9F+ATFG8RZVvokEKRNWPkW1WypGtwnA7Js1KaIz6+9DeoU2hAK6A9WnB16MPlaVeM LUd1O7URZVlOAlcHWxeGMeSff5BqlCQnkgRwUmSDCG624Z0jyMxLUlt4Y9SGPa/yjSZT VjZ0VrHdpe8T9yWl3jOR9mb9YvVFfe2TpBYQzfJSoOmaPmOazBIMJdwc+qjRO206pZmf aAGfYqSpO8JAO5pbG3CJy1QCaFSLR03HLFApjP5RMACnFyF2sC8tdGwVRha6jdmSWd4u RszY8+pj4VEbnJdln2jioPI9zcX6kocyYFJUhfAbwlw9uQhWEFFdirPUdVpDCQRbIuhA XZ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=7UVB0Bvus91U069hIhCOu0NHSTBgIFKqDCvKMnzwYiE=; b=qp+TtupKbbJOH52cw+sQy9cYg6g/VMKkY3zhEuUBVMqmq7gEH55ZjABsWUFMX6spQh gn0pcG9N8NTRTXu3Pk3kcqIcESk5fl7MSiAokWPwh+ZOntDmODcdtZiffBO7eTaHIheD djA7d10Y5F9vV6gFsggchuLHrlQBA30drYkDYDfHsyp90RNqDcpC+S5YLqxBlMfGY0tU vrE65+w+pAPh+oIlO5dGk7Pagzq/rq0v6fPhueeaFUO+2VD1PdeVHW7BrmtrcIKVeix8 Bn7uXelI2TuTfTQousEOjoEtlcT7fhMWLxbuiyQUnO5YP7h4LpahZUn2jGgaU0usKR4U XrTA== X-Gm-Message-State: AHPjjUhxpQQX7YFtv/Pvfz9N1lVO2B3QQywmCI3Bm5RMSEFlWd0B7fG4 I1xpP9ISfG9/oxVNYinLAzMkJt+YlQ== X-Google-Smtp-Source: AOwi7QAnfkBcilaS6Xk70qV3O3ZY+IdU8HFbJiIRRoAu5sHZXOaHqv4e30u/qm36hhe/YpCAetdiUEHwBQ== MIME-Version: 1.0 X-Received: by 10.28.24.78 with SMTP id 75mr39138wmy.0.1505895257727; Wed, 20 Sep 2017 01:14:17 -0700 (PDT) Date: Wed, 20 Sep 2017 10:13:40 +0200 In-Reply-To: <20170920081340.7413-1-tweek@google.com> Message-Id: <20170920081340.7413-6-tweek@google.com> References: <20170920081340.7413-1-tweek@google.com> X-Mailer: git-send-email 2.14.1.821.g8fa685d3b7-goog Subject: [PATCH v3 5/5] tpm: parse TPM event logs based on EFI table From: Thiebaud Weksteen To: linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org, tpmdd-devel@lists.sourceforge.net Cc: ard.biesheuvel@linaro.org, matt@codeblueprint.co.uk, linux-kernel@vger.kernel.org, mjg59@google.com, peterhuewe@gmx.de, jarkko.sakkinen@linux.intel.com, jgunthorpe@obsidianresearch.com, tpmdd@selhorst.net, Thiebaud Weksteen Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we are not able to retrieve the TPM event logs from the ACPI table, check the EFI configuration table (Linux-specific GUID). The format version of the log is now returned by the provider function. Signed-off-by: Thiebaud Weksteen Reviewed-by: Jason Gunthorpe --- drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm.h | 8 +++++ drivers/char/tpm/tpm1_eventlog.c | 11 ++++-- drivers/char/tpm/tpm_eventlog_acpi.c | 2 +- drivers/char/tpm/tpm_eventlog_efi.c | 66 ++++++++++++++++++++++++++++++++++++ drivers/char/tpm/tpm_eventlog_of.c | 4 ++- 6 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 drivers/char/tpm/tpm_eventlog_efi.c diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile index c8509cd723a1..e94ccecff4a5 100644 --- a/drivers/char/tpm/Makefile +++ b/drivers/char/tpm/Makefile @@ -6,6 +6,7 @@ tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \ tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \ tpm2-space.o tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_eventlog_acpi.o +tpm-$(CONFIG_EFI) += tpm_eventlog_efi.o tpm-$(CONFIG_OF) += tpm_eventlog_of.o obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o obj-$(CONFIG_TCG_TIS) += tpm_tis.o diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 46caccf6fd1a..1bd97e01df50 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -597,6 +597,14 @@ static inline int tpm_read_log_of(struct tpm_chip *chip) return -ENODEV; } #endif +#if defined(CONFIG_EFI) +int tpm_read_log_efi(struct tpm_chip *chip); +#else +static inline int tpm_read_log_efi(struct tpm_chip *chip) +{ + return -ENODEV; +} +#endif int tpm_bios_log_setup(struct tpm_chip *chip); void tpm_bios_log_teardown(struct tpm_chip *chip); diff --git a/drivers/char/tpm/tpm1_eventlog.c b/drivers/char/tpm/tpm1_eventlog.c index d6f70f365443..add798bd69d0 100644 --- a/drivers/char/tpm/tpm1_eventlog.c +++ b/drivers/char/tpm/tpm1_eventlog.c @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -371,6 +372,10 @@ static int tpm_read_log(struct tpm_chip *chip) if (rc != -ENODEV) return rc; + rc = tpm_read_log_efi(chip); + if (rc != -ENODEV) + return rc; + return tpm_read_log_of(chip); } @@ -388,11 +393,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip) { const char *name = dev_name(&chip->dev); unsigned int cnt; + int log_version; int rc = 0; rc = tpm_read_log(chip); - if (rc) + if (rc < 0) return rc; + log_version = rc; cnt = 0; chip->bios_dir[cnt] = securityfs_create_dir(name, NULL); @@ -404,7 +411,7 @@ int tpm_bios_log_setup(struct tpm_chip *chip) cnt++; chip->bin_log_seqops.chip = chip; - if (chip->flags & TPM_CHIP_FLAG_TPM2) + if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) chip->bin_log_seqops.seqops = &tpm2_binary_b_measurements_seqops; else diff --git a/drivers/char/tpm/tpm_eventlog_acpi.c b/drivers/char/tpm/tpm_eventlog_acpi.c index acc990ba376a..66f19e93c216 100644 --- a/drivers/char/tpm/tpm_eventlog_acpi.c +++ b/drivers/char/tpm/tpm_eventlog_acpi.c @@ -102,7 +102,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip) memcpy_fromio(log->bios_event_log, virt, len); acpi_os_unmap_iomem(virt, len); - return 0; + return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; err: kfree(log->bios_event_log); diff --git a/drivers/char/tpm/tpm_eventlog_efi.c b/drivers/char/tpm/tpm_eventlog_efi.c new file mode 100644 index 000000000000..e3f9ffd341d2 --- /dev/null +++ b/drivers/char/tpm/tpm_eventlog_efi.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017 Google + * + * Authors: + * Thiebaud Weksteen + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + */ + +#include +#include + +#include "tpm.h" + +/* read binary bios log from EFI configuration table */ +int tpm_read_log_efi(struct tpm_chip *chip) +{ + + struct linux_efi_tpm_eventlog *log_tbl; + struct tpm_bios_log *log; + u32 log_size; + u8 tpm_log_version; + + if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) + return -ENODEV; + + if (efi.tpm_log == EFI_INVALID_TABLE_ADDR) + return -ENODEV; + + log = &chip->log; + + log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl), MEMREMAP_WB); + if (!log_tbl) { + pr_err("Could not map UEFI TPM log table !\n"); + return -ENOMEM; + } + + log_size = log_tbl->size; + memunmap(log_tbl); + + log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size, + MEMREMAP_WB); + if (!log_tbl) { + pr_err("Could not map UEFI TPM log table payload!\n"); + return -ENOMEM; + } + + /* malloc EventLog space */ + log->bios_event_log = kmalloc(log_size, GFP_KERNEL); + if (!log->bios_event_log) + goto err_memunmap; + memcpy(log->bios_event_log, log_tbl->log, log_size); + log->bios_event_log_end = log->bios_event_log + log_size; + + tpm_log_version = log_tbl->version; + memunmap(log_tbl); + return tpm_log_version; + +err_memunmap: + memunmap(log_tbl); + return -ENOMEM; +} diff --git a/drivers/char/tpm/tpm_eventlog_of.c b/drivers/char/tpm/tpm_eventlog_of.c index 4a2f8c79231e..96fd5646f866 100644 --- a/drivers/char/tpm/tpm_eventlog_of.c +++ b/drivers/char/tpm/tpm_eventlog_of.c @@ -76,5 +76,7 @@ int tpm_read_log_of(struct tpm_chip *chip) memcpy(log->bios_event_log, __va(base), size); - return 0; + if (chip->flags & TPM_CHIP_FLAG_TPM2) + return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2; + return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2; }