All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Hanjun Guo <guohanjun@huawei.com>
Cc: linux-integrity@vger.kernel.org, Peter Huewe <peterhuewe@gmx.de>
Subject: Re: [PATCH 1/3] tpm: acpi: Call acpi_put_table() to fix memory leak
Date: Wed, 16 Nov 2022 01:51:37 +0200	[thread overview]
Message-ID: <Y3QmCUux2D+9ebmp@kernel.org> (raw)
In-Reply-To: <1667966622-19711-2-git-send-email-guohanjun@huawei.com>

On Wed, Nov 09, 2022 at 12:03:40PM +0800, Hanjun Guo wrote:
> 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().
> 

Please add to the commit message:

Cc: stable@vger.kernel.org

And cc this patch also to linux-kernel@vger.kernel.org.

> Fixes: 0bfb23746052 ("tpm: Move eventlog files to a subdirectory")
> Fixes: 85467f63a05c ("tpm: Add support for event log pointer found in TPM2 ACPI table")
> Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
> ---
>  drivers/char/tpm/eventlog/acpi.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c
> index 1b18ce5..0913d3eb 100644
> --- a/drivers/char/tpm/eventlog/acpi.c
> +++ b/drivers/char/tpm/eventlog/acpi.c
> @@ -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) */
> @@ -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;
> @@ -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;
> -
>  }
> -- 
> 1.7.12.4
> 

Thank you for fixing this.

BR, Jarkko

  reply	other threads:[~2022-11-15 23:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  4:03 [PATCH 0/3] ACPI table release for TPM drivers Hanjun Guo
2022-11-09  4:03 ` [PATCH 1/3] tpm: acpi: Call acpi_put_table() to fix memory leak Hanjun Guo
2022-11-15 23:51   ` Jarkko Sakkinen [this message]
2022-11-17  9:16     ` Hanjun Guo
2022-11-09  4:03 ` [PATCH 2/3] tpm: tpm_crb: Add the missed " Hanjun Guo
2022-11-15 23:52   ` Jarkko Sakkinen
2022-11-09  4:03 ` [PATCH 3/3] tpm: tpm_tis: " Hanjun Guo
2022-11-15 23:52   ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3QmCUux2D+9ebmp@kernel.org \
    --to=jarkko@kernel.org \
    --cc=guohanjun@huawei.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.