2020-04-02 22:52:19

by Stefan Berger

[permalink] [raw]
Subject: [PATCH v4 0/2] 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(-)

--
2.14.5


2020-04-02 22:52:21

by Stefan Berger

[permalink] [raw]
Subject: [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.

Signed-off-by: Stefan Berger <[email protected]>
Cc: [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(-)

diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index a9dcf31eadd2..0565aa5482f9 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -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;
}

diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index e7df342a317d..a80f36860bac 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -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;
}
diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h
index 2bf3baf819bb..b6118c67af0c 100644
--- a/include/acpi/actbl3.h
+++ b/include/acpi/actbl3.h
@@ -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 */
--
2.14.5

2020-04-02 22:53:59

by Stefan Berger

[permalink] [raw]
Subject: [PATCH v4 2/2] tpm: Add support for event log pointer found in TPM2 ACPI table

From: 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.

Signed-off-by: Stefan Berger <[email protected]>
---
drivers/char/tpm/eventlog/acpi.c | 56 +++++++++++++++++++++++++---------------
1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c
index 63ada5e53f13..e714a2bd0423 100644
--- a/drivers/char/tpm/eventlog/acpi.c
+++ b/drivers/char/tpm/eventlog/acpi.c
@@ -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);
--
2.14.5

2020-04-03 07:02:14

by Jarkko Sakkinen

[permalink] [raw]
Subject: Re: [PATCH v4 0/2] tpm2: Make TPM2 logs accessible for non-UEFI firmware

On Thu, Apr 02, 2020 at 06:51:38PM -0400, Stefan Berger wrote:
> 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(-)
>
> --
> 2.14.5
>

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

2020-04-03 12:33:55

by Stefan Berger

[permalink] [raw]
Subject: Re: [PATCH v4 0/2] tpm2: Make TPM2 logs accessible for non-UEFI firmware

On 4/3/20 3:01 AM, Jarkko Sakkinen wrote:
> 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

2020-04-30 23:49:39

by Stefan Berger

[permalink] [raw]
Subject: Re: [PATCH v4 1/2] acpi: Extend TPM2 ACPI table with missing log fields

Hi Rafael,

  can you ACK this patch?

Regards,
   Stefan
> 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.
>
> Signed-off-by: Stefan Berger <[email protected]>
> Cc: [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(-)
>
> diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
> index a9dcf31eadd2..0565aa5482f9 100644
> --- a/drivers/char/tpm/tpm_crb.c
> +++ b/drivers/char/tpm/tpm_crb.c
> @@ -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;
> }
>
> diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
> index e7df342a317d..a80f36860bac 100644
> --- a/drivers/char/tpm/tpm_tis.c
> +++ b/drivers/char/tpm/tpm_tis.c
> @@ -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;
> }
> diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h
> index 2bf3baf819bb..b6118c67af0c 100644
> --- a/include/acpi/actbl3.h
> +++ b/include/acpi/actbl3.h
> @@ -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 */