Skip to content

Comments

ta: pkcs11: fix memory leak in close_persistent_db()#7710

Merged
jenswi-linaro merged 1 commit intoOP-TEE:masterfrom
manoj23:master
Feb 24, 2026
Merged

ta: pkcs11: fix memory leak in close_persistent_db()#7710
jenswi-linaro merged 1 commit intoOP-TEE:masterfrom
manoj23:master

Conversation

@manoj23
Copy link
Contributor

@manoj23 manoj23 commented Feb 21, 2026

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")

Copy link
Contributor

@jforissier jforissier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Reviewed-by: Jerome Forissier <[email protected]>

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 <[email protected]>
Reviewed-by: Jerome Forissier <[email protected]>
@jenswi-linaro jenswi-linaro merged commit 1e3f36b into OP-TEE:master Feb 24, 2026
57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants