* [ima-evm-utils: PATCH 0/2] Fix memory leaks in libimaevm
@ 2026-03-24 21:23 Stefan Berger
2026-03-24 21:23 ` [ima-evm-utils: PATCH 1/2] Use EVP_PKEY_free to free a key of public_key_entry Stefan Berger
2026-03-24 21:23 ` [ima-evm-utils: PATCH 2/2] Avoid memory leak if public_keys is NULL Stefan Berger
0 siblings, 2 replies; 3+ messages in thread
From: Stefan Berger @ 2026-03-24 21:23 UTC (permalink / raw)
To: linux-integrity; +Cc: zohar, roberto.sassu, Stefan Berger
This series fixes two memory leaks in libimaevm.
Stefan
Stefan Berger (2):
Use EVP_PKEY_free to free a key of public_key_entry
Avoid memory leak if public_keys is NULL
src/libimaevm.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ima-evm-utils: PATCH 1/2] Use EVP_PKEY_free to free a key of public_key_entry
2026-03-24 21:23 [ima-evm-utils: PATCH 0/2] Fix memory leaks in libimaevm Stefan Berger
@ 2026-03-24 21:23 ` Stefan Berger
2026-03-24 21:23 ` [ima-evm-utils: PATCH 2/2] Avoid memory leak if public_keys is NULL Stefan Berger
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Berger @ 2026-03-24 21:23 UTC (permalink / raw)
To: linux-integrity; +Cc: zohar, roberto.sassu, Stefan Berger
Use EVP_PKEY_free to fix a memory leak that occurs when using free() on the
key field of public_key_entry that is a pointer to an EVP_PKEY.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
src/libimaevm.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/libimaevm.c b/src/libimaevm.c
index 3b268d5..6512ee5 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -400,7 +400,7 @@ void imaevm_free_public_keys(struct public_key_entry *public_keys)
while (entry) {
next = entry->next;
if (entry->key)
- free(entry->key);
+ EVP_PKEY_free(entry->key);
free(entry);
entry = next;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [ima-evm-utils: PATCH 2/2] Avoid memory leak if public_keys is NULL
2026-03-24 21:23 [ima-evm-utils: PATCH 0/2] Fix memory leaks in libimaevm Stefan Berger
2026-03-24 21:23 ` [ima-evm-utils: PATCH 1/2] Use EVP_PKEY_free to free a key of public_key_entry Stefan Berger
@ 2026-03-24 21:23 ` Stefan Berger
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Berger @ 2026-03-24 21:23 UTC (permalink / raw)
To: linux-integrity; +Cc: zohar, roberto.sassu, Stefan Berger
Avoid a memory leak of a public_key_entry if the passed public_keys
pointer is NULL because in this case the entry is lost. For this particular
case to work we would need public keys to be passed in as
'struct public_key_entry **public_keys' so that '*public_keys = entry'
could be assign. However, this change would propagate all the way to the
API of the library and we don't want to change existing functions'
signature.
This change should not have any noticeable side-effect since the resolved
case did not work before but the newly allocated entry was lost.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
src/libimaevm.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/libimaevm.c b/src/libimaevm.c
index 6512ee5..d8d5dbc 100644
--- a/src/libimaevm.c
+++ b/src/libimaevm.c
@@ -378,17 +378,16 @@ static EVP_PKEY *find_keyid(struct public_key_entry *public_keys,
tail = entry;
}
- /* add unknown keys to list */
- entry = calloc(1, sizeof(struct public_key_entry));
- if (!entry) {
- perror("calloc");
- return 0;
- }
- entry->keyid = keyid;
- if (tail)
+ /* add unknown keys to tail of list */
+ if (tail) {
+ entry = calloc(1, sizeof(struct public_key_entry));
+ if (!entry) {
+ perror("calloc");
+ return 0;
+ }
+ entry->keyid = keyid;
tail->next = entry;
- else
- public_keys = entry;
+ }
log_err("key %d: %x (unknown keyid)\n", i, __be32_to_cpup(&keyid));
return 0;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-24 21:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-24 21:23 [ima-evm-utils: PATCH 0/2] Fix memory leaks in libimaevm Stefan Berger
2026-03-24 21:23 ` [ima-evm-utils: PATCH 1/2] Use EVP_PKEY_free to free a key of public_key_entry Stefan Berger
2026-03-24 21:23 ` [ima-evm-utils: PATCH 2/2] Avoid memory leak if public_keys is NULL Stefan Berger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox