Skip to content

Commit ab843a3

Browse files
committed
ta: pkcs11: fix memory leak in close_persistent_db()
close_persistent_db() is a no-op stub that never frees the db_main and db_objs structures allocated by init_persistent_db(). In normal TA operation this is harmless since the TEE framework reclaims all TA memory on unload, which is likely why it was left unimplemented. However, the leak becomes visible when running the TA in a host-based test environment (e.g. with AddressSanitizer) where the TEE memory reclamation does not occur. ASan reports 264 leaked allocations totalling ~24 KiB per TA lifecycle. Implement close_persistent_db() to free token->db_main and token->db_objs and NULL the pointers. Add a NULL check on the token argument for robustness. Fixes: c84ccd0 ("ta: pkcs11: persistent database for the pkcs11 tokens") Signed-off-by: Georges Savoundararadj <savoundg@amazon.com> Reviewed-by: Jerome Forissier <jerome.forissier@arm.com>
1 parent 9c650cc commit ab843a3

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

ta/pkcs11/src/persistent_token.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,16 @@ enum pkcs11_rc verify_identity_auth(struct ck_token *token,
286286
/*
287287
* Release resources relate to persistent database
288288
*/
289-
void close_persistent_db(struct ck_token *token __unused)
289+
void close_persistent_db(struct ck_token *token)
290290
{
291+
if (!token)
292+
return;
293+
294+
TEE_Free(token->db_main);
295+
token->db_main = NULL;
296+
297+
TEE_Free(token->db_objs);
298+
token->db_objs = NULL;
291299
}
292300

293301
static int get_persistent_obj_idx(struct ck_token *token, TEE_UUID *uuid)

0 commit comments

Comments
 (0)