mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: Cong Nguyen <congnt264@gmail.com>,
	Mimi Zohar <zohar@linux.ibm.com>,
	 Roberto Sassu <roberto.sassu@huawei.com>
Cc: Dmitry Kasatkin <dmitry.kasatkin@gmail.com>,
	Eric Snowberg <eric.snowberg@oracle.com>,
	linux-integrity@vger.kernel.org,
	 linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ima: free the restored template entry on error in ima_restore_measurement_list()
Date: Wed, 02 Dec 2026 13:04:43 +0100	[thread overview]
Message-ID: <67cb8cb4f78e41359b15089c59b266847bfbbc2a.camel@huaweicloud.com> (raw)
In-Reply-To: <20261127073233.181925-1-congnt264@gmail.com>

On Fri, 2026-11-27 at 14:32 +0700, Cong Nguyen wrote:
> ima_restore_template_data() allocates a template entry that the caller
> owns once it returns success. ima_restore_measurement_list() breaks out
> of its loop without freeing it when ima_calc_field_array_hash() fails
> or when ima_restore_measurement_entry() fails, so the entry, its digests
> and its field data are leaked.
> 
> Free the entry with ima_free_template_entry() on both paths.
> 
> Fixes: 1ea973df6e21 ("ima: Calculate and extend PCR with digests in ima_template_entry")
> Fixes: 94c3aac567a9 ("ima: on soft reboot, restore the measurement list")
> Signed-off-by: Cong Nguyen <congnt264@gmail.com>

Reviewed-by: Roberto Sassu <roberto.sassu@huawei.com>

Thanks

Roberto

> ---
>  security/integrity/ima/ima_template.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
> index 16154078fd70..d5256da8f76e 100644
> --- a/security/integrity/ima/ima_template.c
> +++ b/security/integrity/ima/ima_template.c
> @@ -526,6 +526,7 @@ int ima_restore_measurement_list(loff_t size, void *buf)
>  						entry);
>  			if (ret < 0) {
>  				pr_err("cannot calculate template digest\n");
> +				ima_free_template_entry(entry);
>  				ret = -EINVAL;
>  				break;
>  			}
> @@ -541,8 +542,10 @@ int ima_restore_measurement_list(loff_t size, void *buf)
>  		entry->pcr = !ima_canonical_fmt ? *(u32 *)(hdr[HDR_PCR].data) :
>  			     le32_to_cpu(*(__le32 *)(hdr[HDR_PCR].data));
>  		ret = ima_restore_measurement_entry(entry);
> -		if (ret < 0)
> +		if (ret < 0) {
> +			ima_free_template_entry(entry);
>  			break;
> +		}
>  
>  	}
>  	return ret;


      reply	other threads:[~2026-12-02 12:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  7:32 Cong Nguyen
2026-12-02 12:04 ` Roberto Sassu [this message]

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=67cb8cb4f78e41359b15089c59b266847bfbbc2a.camel@huaweicloud.com \
    --to=roberto.sassu@huaweicloud.com \
    --cc=congnt264@gmail.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eric.snowberg@oracle.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=roberto.sassu@huawei.com \
    --cc=zohar@linux.ibm.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®