Skip to content

Commit 58cc1e4

Browse files
tweksteenJarkko Sakkinen
authored and
Jarkko Sakkinen
committed
tpm: parse TPM event logs based on EFI table
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 <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Tested-by: Javier Martinez Canillas <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent 33b6d03 commit 58cc1e4

File tree

6 files changed

+88
-4
lines changed

6 files changed

+88
-4
lines changed

drivers/char/tpm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o \
77
tpm-dev-common.o tpmrm-dev.o tpm1_eventlog.o tpm2_eventlog.o \
88
tpm2-space.o
99
tpm-$(CONFIG_ACPI) += tpm_ppi.o tpm_eventlog_acpi.o
10+
tpm-$(CONFIG_EFI) += tpm_eventlog_efi.o
1011
tpm-$(CONFIG_OF) += tpm_eventlog_of.o
1112
obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
1213
obj-$(CONFIG_TCG_TIS) += tpm_tis.o

drivers/char/tpm/tpm.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,14 @@ static inline int tpm_read_log_of(struct tpm_chip *chip)
589589
return -ENODEV;
590590
}
591591
#endif
592+
#if defined(CONFIG_EFI)
593+
int tpm_read_log_efi(struct tpm_chip *chip);
594+
#else
595+
static inline int tpm_read_log_efi(struct tpm_chip *chip)
596+
{
597+
return -ENODEV;
598+
}
599+
#endif
592600

593601
int tpm_bios_log_setup(struct tpm_chip *chip);
594602
void tpm_bios_log_teardown(struct tpm_chip *chip);

drivers/char/tpm/tpm1_eventlog.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222

2323
#include <linux/seq_file.h>
24+
#include <linux/efi.h>
2425
#include <linux/fs.h>
2526
#include <linux/security.h>
2627
#include <linux/module.h>
@@ -371,6 +372,10 @@ static int tpm_read_log(struct tpm_chip *chip)
371372
if (rc != -ENODEV)
372373
return rc;
373374

375+
rc = tpm_read_log_efi(chip);
376+
if (rc != -ENODEV)
377+
return rc;
378+
374379
return tpm_read_log_of(chip);
375380
}
376381

@@ -388,11 +393,13 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
388393
{
389394
const char *name = dev_name(&chip->dev);
390395
unsigned int cnt;
396+
int log_version;
391397
int rc = 0;
392398

393399
rc = tpm_read_log(chip);
394-
if (rc)
400+
if (rc < 0)
395401
return rc;
402+
log_version = rc;
396403

397404
cnt = 0;
398405
chip->bios_dir[cnt] = securityfs_create_dir(name, NULL);
@@ -404,7 +411,7 @@ int tpm_bios_log_setup(struct tpm_chip *chip)
404411
cnt++;
405412

406413
chip->bin_log_seqops.chip = chip;
407-
if (chip->flags & TPM_CHIP_FLAG_TPM2)
414+
if (log_version == EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
408415
chip->bin_log_seqops.seqops =
409416
&tpm2_binary_b_measurements_seqops;
410417
else

drivers/char/tpm/tpm_eventlog_acpi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
102102
memcpy_fromio(log->bios_event_log, virt, len);
103103

104104
acpi_os_unmap_iomem(virt, len);
105-
return 0;
105+
return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
106106

107107
err:
108108
kfree(log->bios_event_log);

drivers/char/tpm/tpm_eventlog_efi.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2017 Google
3+
*
4+
* Authors:
5+
* Thiebaud Weksteen <[email protected]>
6+
*
7+
* This program is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU General Public License
9+
* as published by the Free Software Foundation; either version
10+
* 2 of the License, or (at your option) any later version.
11+
*
12+
*/
13+
14+
#include <linux/efi.h>
15+
#include <linux/tpm_eventlog.h>
16+
17+
#include "tpm.h"
18+
19+
/* read binary bios log from EFI configuration table */
20+
int tpm_read_log_efi(struct tpm_chip *chip)
21+
{
22+
23+
struct linux_efi_tpm_eventlog *log_tbl;
24+
struct tpm_bios_log *log;
25+
u32 log_size;
26+
u8 tpm_log_version;
27+
28+
if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
29+
return -ENODEV;
30+
31+
if (efi.tpm_log == EFI_INVALID_TABLE_ADDR)
32+
return -ENODEV;
33+
34+
log = &chip->log;
35+
36+
log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl), MEMREMAP_WB);
37+
if (!log_tbl) {
38+
pr_err("Could not map UEFI TPM log table !\n");
39+
return -ENOMEM;
40+
}
41+
42+
log_size = log_tbl->size;
43+
memunmap(log_tbl);
44+
45+
log_tbl = memremap(efi.tpm_log, sizeof(*log_tbl) + log_size,
46+
MEMREMAP_WB);
47+
if (!log_tbl) {
48+
pr_err("Could not map UEFI TPM log table payload!\n");
49+
return -ENOMEM;
50+
}
51+
52+
/* malloc EventLog space */
53+
log->bios_event_log = kmalloc(log_size, GFP_KERNEL);
54+
if (!log->bios_event_log)
55+
goto err_memunmap;
56+
memcpy(log->bios_event_log, log_tbl->log, log_size);
57+
log->bios_event_log_end = log->bios_event_log + log_size;
58+
59+
tpm_log_version = log_tbl->version;
60+
memunmap(log_tbl);
61+
return tpm_log_version;
62+
63+
err_memunmap:
64+
memunmap(log_tbl);
65+
return -ENOMEM;
66+
}

drivers/char/tpm/tpm_eventlog_of.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,7 @@ int tpm_read_log_of(struct tpm_chip *chip)
7676

7777
memcpy(log->bios_event_log, __va(base), size);
7878

79-
return 0;
79+
if (chip->flags & TPM_CHIP_FLAG_TPM2)
80+
return EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
81+
return EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
8082
}

0 commit comments

Comments
 (0)