tpm2: Make TPM2 logs accessible for non-UEFI firmware
Subsystems (5)
v4 cover tpm2: Make TPM2 logs accessible for non-UEFI firmware
From: Stefan Berger <[email protected]>
This series of patches extends the existing TPM2 ACPI table with additional fields found in the TPM2 TCG ACPI specification (reference is in the patch) that allow access to the log's address and its size. We then modify the code that so far only enables access to a TPM 1.2's log for a TPM2 as well. This then enables access to the TPM2's log on non-UEFI system that for example run SeaBIOS.
Stefan
v3->v4:
- Repost as one series
v2->v3:
- Split the series into two separate patches
- Added comments to ACPI table fields
- Added check for null pointer to log area and zero log size
v1->v2:
- Repost of the series
Stefan Berger (2):
acpi: Extend TPM2 ACPI table with missing log fields
tpm: Add support for event log pointer found in TPM2 ACPI table
drivers/char/tpm/eventlog/acpi.c | 56 +++++++++++++++++++++++++--------------- drivers/char/tpm/tpm_crb.c | 13 +++++++--- drivers/char/tpm/tpm_tis.c | 4 ++- include/acpi/actbl3.h | 5 ++-- 4 files changed, 51 insertions(+), 27 deletions(-)
Signature · 1 line
2.14.5
PATCH v4 1/2 acpi: Extend TPM2 ACPI table with missing log fields
From: Stefan Berger <[email protected]>
Recent extensions of the TPM2 ACPI table added 3 more fields including 12 bytes of start method specific parameters and Log Area Minimum Length (u32) and Log Area Start Address (u64). So, we extend the existing structure with these fields to allow non-UEFI systems to access the TPM2's log.
The specification that has the new fields is the following:
TCG ACPI Specification
Family "1.2" and "2.0"
Version 1.2, Revision 8
Adapt all existing table size calculations to use offsetof(struct acpi_table_tpm2, start_method_specific) [where start_method_specific is a newly added field] rather than sizeof(struct acpi_table_tpm2) so that the addition of the new fields does not affect current systems that may not have them.
--- drivers/char/tpm/tpm_crb.c | 13 ++++++++++--- drivers/char/tpm/tpm_tis.c | 4 +++- include/acpi/actbl3.h | 5 +++-- 3 files changed, 16 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_crb.c +10 -3
@@ -669,7 +669,9 @@ static int crb_acpi_add(struct acpi_device *device) status =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **) &buf); -if (ACPI_FAILURE (status) || buf->header.length <sizeof (*buf)) { +if (ACPI_FAILURE (status) || buf->header.length < + offsetof(struct acpi_table_tpm2 , + start_method_specific)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ; }
@@ -684,14 +686,19 @@ static int crb_acpi_add(struct acpi_device *device)return -ENOMEM ;if (sm ==ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC ) { -if (buf->header.length < (sizeof (*buf) +sizeof (*crb_smc))) { +if (buf->header.length < + (offsetof(struct acpi_table_tpm2 , + start_method_specific) + +sizeof (*crb_smc))) {dev_err (dev,FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n" , buf->header.length,ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC );return -EINVAL ; } - crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf)); + crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, + offsetof(struct acpi_table_tpm2 , + start_method_specific)); priv->smc_func_id = crb_smc->smc_func_id; }
drivers/char/tpm/tpm_tis.c +3 -1
@@ -111,7 +111,9 @@ static int check_acpi_tpm2(struct device *dev)*/ st =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl); -if (ACPI_FAILURE (st) || tbl->header.length <sizeof (*tbl)) { +if (ACPI_FAILURE (st) || tbl->header.length < + offsetof(struct acpi_table_tpm2 , + start_method_specific)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ; }
include/acpi/actbl3.h +3 -2
@@ -411,8 +411,9 @@ struct acpi_table_tpm2 {u16 reserved;u64 control_address;u32 start_method; - -/* Platform-specific data follows */ +u8 start_method_specific[12 ]; +u32 log_area_minimum_length;/* optional */ +u64 log_area_start_address;/* optional */ };/* Values for start_method above */
Signature · 1 line
2.14.5
Re: [PATCH v4 1/2] acpi: Extend TPM2 ACPI table with missing log fields
Hi Rafael,
can you ACK this patch?
Regards,
Stefan
Quoted 96 lines
From: Stefan Berger <[email protected]>
Recent extensions of the TPM2 ACPI table added 3 more fields including 12 bytes of start method specific parameters and Log Area Minimum Length (u32) and Log Area Start Address (u64). So, we extend the existing structure with these fields to allow non-UEFI systems to access the TPM2's log.
The specification that has the new fields is the following:
TCG ACPI Specification
Family "1.2" and "2.0"
Version 1.2, Revision 8Adapt all existing table size calculations to use
offsetof(struct acpi_table_tpm2, start_method_specific)[wherestart_method_specificis a newly added field] rather thansizeof(struct acpi_table_tpm2)so that the addition of the new fields does not affect current systems that may not have them.Signed-off-by Stefan Berger <[email protected]>--- drivers/char/tpm/tpm_crb.c | 13 ++++++++++--- drivers/char/tpm/tpm_tis.c | 4 +++- include/acpi/actbl3.h | 5 +++-- 3 files changed, 16 insertions(+), 6 deletions(-)drivers/char/tpm/tpm_crb.c +10
-3@@ -669,7 +669,9 @@ static int crb_acpi_add(struct acpi_device *device) status =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **) &buf); -if (ACPI_FAILURE (status) || buf->header.length <sizeof (*buf)) { +if (ACPI_FAILURE (status) || buf->header.length < + offsetof(struct acpi_table_tpm2 , + start_method_specific)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ; }@@ -684,14 +686,19 @@ static int crb_acpi_add(struct acpi_device *device)return -ENOMEM ;if (sm ==ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC ) { -if (buf->header.length < (sizeof (*buf) +sizeof (*crb_smc))) { +if (buf->header.length < + (offsetof(struct acpi_table_tpm2 , + start_method_specific) + +sizeof (*crb_smc))) {dev_err (dev,FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n" , buf->header.length,ACPI_TPM2_COMMAND_BUFFER_WITH_ARM_SMC );return -EINVAL ; } - crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, sizeof(*buf)); + crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf, + offsetof(struct acpi_table_tpm2 , + start_method_specific)); priv->smc_func_id = crb_smc->smc_func_id; }drivers/char/tpm/tpm_tis.c +3
-1@@ -111,7 +111,9 @@ static int check_acpi_tpm2(struct device *dev)*/ st =acpi_get_table (ACPI_SIG_TPM2 ,1 , (struct acpi_table_header **)&tbl); -if (ACPI_FAILURE (st) || tbl->header.length <sizeof (*tbl)) { +if (ACPI_FAILURE (st) || tbl->header.length < + offsetof(struct acpi_table_tpm2 , + start_method_specific)) {dev_err (dev,FW_BUG "failed to get TPM2 ACPI table\n" );return -EINVAL ; }include/acpi/actbl3.h +3
-2@@ -411,8 +411,9 @@ struct acpi_table_tpm2 {u16 reserved;u64 control_address;u32 start_method; - -/* Platform-specific data follows */ +u8 start_method_specific[12 ]; +u32 log_area_minimum_length;/* optional */ +u64 log_area_start_address;/* optional */ };/* Values for start_method above */
PATCH v4 2/2 tpm: Add support for event log pointer found in TPM2 ACPI table
In reply to Stefan BergerFrom: Stefan Berger <[email protected]>
In case a TPM2 is attached, search for a TPM2 ACPI table when trying to get the event log from ACPI. If one is found, use it to get the start and length of the log area. This allows non-UEFI systems, such as SeaBIOS, to pass an event log when using a TPM2.
--- drivers/char/tpm/eventlog/acpi.c | 56 +++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 21 deletions(-)
drivers/char/tpm/eventlog/acpi.c +35 -21
@@ -49,9 +49,8 @@ int tpm_read_log_acpi(struct tpm_chip *chip)void __iomem *virt;u64 len, start;struct tpm_bios_log *log; - -if (chip->flags &TPM_CHIP_FLAG_TPM2 ) -return -ENODEV ; +struct acpi_table_tpm2 *tbl; +int format; log = &chip->log;
@@ -61,23 +60,38 @@ int tpm_read_log_acpi(struct tpm_chip *chip)if (!chip->acpi_dev_handle)return -ENODEV ; -/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ - status =acpi_get_table (ACPI_SIG_TCPA ,1 , - (struct acpi_table_header **)&buff); - -if (ACPI_FAILURE (status)) -return -ENODEV ; - -switch (buff->platform_class) { -case BIOS_SERVER : - len = buff->server.log_max_len; - start = buff->server.log_start_addr; -break ; -case BIOS_CLIENT : -default : - len = buff->client.log_max_len; - start = buff->client.log_start_addr; -break ; +if (chip->flags &TPM_CHIP_FLAG_TPM2 ) { + status =acpi_get_table ("TPM2" ,1 , + (struct acpi_table_header **)&tbl); +if (ACPI_FAILURE (status)) +return -ENODEV ; +if (tbl->header.length <sizeof (*tbl)) +return -ENODEV ; + len = tbl->log_area_minimum_length; + start = tbl->log_area_start_address; +if (!start || !len) +return -ENODEV ; + format =EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ; + }else { +/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ + status =acpi_get_table (ACPI_SIG_TCPA ,1 , + (struct acpi_table_header **)&buff); + +if (ACPI_FAILURE (status)) +return -ENODEV ; + +switch (buff->platform_class) { +case BIOS_SERVER : + len = buff->server.log_max_len; + start = buff->server.log_start_addr; +break ; +case BIOS_CLIENT : +default : + len = buff->client.log_max_len; + start = buff->client.log_start_addr; +break ; + } + format =EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ; }if (!len) {dev_warn (&chip->dev,"%s: TCPA log area empty\n" , __func__);
@@ -98,7 +112,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 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 ; +return format; err:kfree (log->bios_event_log);
Signature · 1 line
2.14.5
Quoted 28 lines · Stefan Berger
From: Stefan Berger <[email protected]>
This series of patches extends the existing TPM2 ACPI table with additional fields found in the TPM2 TCG ACPI specification (reference is in the patch) that allow access to the log's address and its size. We then modify the code that so far only enables access to a TPM 1.2's log for a TPM2 as well. This then enables access to the TPM2's log on non-UEFI system that for example run SeaBIOS.
Stefan
v3->v4:
- Repost as one series
v2->v3:
- Split the series into two separate patches
- Added comments to ACPI table fields
- Added check for null pointer to log area and zero log size
v1->v2:
- Repost of the seriesStefan Berger (2):
acpi: Extend TPM2 ACPI table with missing log fields
tpm: Add support for event log pointer found in TPM2 ACPI table
Quoted 9 lines
drivers/char/tpm/eventlog/acpi.c | 56 +++++++++++++++++++++++++--------------- drivers/char/tpm/tpm_crb.c | 13 +++++++--- drivers/char/tpm/tpm_tis.c | 4 ++- include/acpi/actbl3.h | 5 ++-- 4 files changed, 51 insertions(+), 27 deletions(-)Signature · 1 line
2.14.5
I'll apply this after I'll get Rafael's answer whether I can add his ack to the commits.
/Jarkko
Quoted 6 lines · Jarkko Sakkinen
Reviewed-by Jarkko Sakkinen<[email protected]>I'll apply this after I'll get Rafael's answer whether I can add his ack to the commits.
/Jarkko
Thank you!
Stefan