* [PATCH] ima: free the restored template entry on error in ima_restore_measurement_list()
@ 2026-11-27 7:32 Cong Nguyen
2026-11-27 7:38 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-11-27 7:32 UTC (permalink / raw)
To: Mimi Zohar, Roberto Sassu
Cc: Dmitry Kasatkin, Eric Snowberg, linux-integrity,
linux-security-module, linux-kernel
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>
---
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;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ima: free the restored template entry on error in ima_restore_measurement_list()
2026-11-27 7:32 [PATCH] ima: free the restored template entry on error in ima_restore_measurement_list() Cong Nguyen
@ 2026-11-27 7:38 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27 7:38 UTC (permalink / raw)
Cc: linux-security-module
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127073233.181925-1-congnt264@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 7:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 7:32 [PATCH] ima: free the restored template entry on error in ima_restore_measurement_list() Cong Nguyen
2026-11-27 7:38 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox