Skip to content

Commit

Permalink
tpm: acpi: Call acpi_put_table() to fix memory leak
Browse files Browse the repository at this point in the history
commit 8740a12 upstream.

The start and length of the event log area are obtained from
TPM2 or TCPA table, so we call acpi_get_table() to get the
ACPI information, but the acpi_get_table() should be coupled with
acpi_put_table() to release the ACPI memory, add the acpi_put_table()
properly to fix the memory leak.

While we are at it, remove the redundant empty line at the
end of the tpm_read_log_acpi().

Fixes: 0bfb237 ("tpm: Move eventlog files to a subdirectory")
Fixes: 85467f6 ("tpm: Add support for event log pointer found in TPM2 ACPI table")
Cc: stable@vger.kernel.org
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
guohanjun authored and gregkh committed Jan 12, 2023
1 parent d58289f commit 638cd29
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions drivers/char/tpm/eventlog/acpi.c
Expand Up @@ -90,16 +90,21 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
return -ENODEV;

if (tbl->header.length <
sizeof(*tbl) + sizeof(struct acpi_tpm2_phy))
sizeof(*tbl) + sizeof(struct acpi_tpm2_phy)) {
acpi_put_table((struct acpi_table_header *)tbl);
return -ENODEV;
}

tpm2_phy = (void *)tbl + sizeof(*tbl);
len = tpm2_phy->log_area_minimum_length;

start = tpm2_phy->log_area_start_address;
if (!start || !len)
if (!start || !len) {
acpi_put_table((struct acpi_table_header *)tbl);
return -ENODEV;
}

acpi_put_table((struct acpi_table_header *)tbl);
format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
} else {
/* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */
Expand All @@ -120,8 +125,10 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
break;
}

acpi_put_table((struct acpi_table_header *)buff);
format = EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2;
}

if (!len) {
dev_warn(&chip->dev, "%s: TCPA log area empty\n", __func__);
return -EIO;
Expand Down Expand Up @@ -156,5 +163,4 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
kfree(log->bios_event_log);
log->bios_event_log = NULL;
return ret;

}

0 comments on commit 638cd29

Please sign in to comment.