Skip to content

Cleanse-before-free buffers for sensitive data#164

Merged
gotthardp merged 1 commit intotpm2-software:masterfrom
hyperfinitism:fix/sensitive-data-zeroing
Mar 8, 2026
Merged

Cleanse-before-free buffers for sensitive data#164
gotthardp merged 1 commit intotpm2-software:masterfrom
hyperfinitism:fix/sensitive-data-zeroing

Conversation

@hyperfinitism
Copy link
Copy Markdown
Contributor

@hyperfinitism hyperfinitism commented Mar 5, 2026

This pull request replace free() with cleanse_free() for Esys-allocated buffers.

Targets

Buffer Contents Func File
actx->message RSA decrypted plaintext rsa_asymcipher_freectx tpm2-provider-asymcipher-rsa.c
keyPrivate private key tpm2_load_external_key tpm2-provider-cipher.c
outbuff decrypted plaintext (if decrypting) tpm2_cipher_process_buffer tpm2-provider-cipher.c
outbuff decrypted plaintext (if decrypting) tpm2_cipher_update_stream tpm2-provider-cipher.c
outPoint ECDH shared secret tpm2_keyexch_derive_kdf tpm2-provider-keyexch.c
keyPrivate EC private key tpm2_ec_keymgmt_gen tpm2-keymgmt-ec.c
keyPrivate RSA private key tpm2_rsa_keymgmt_gen tpm2-keymgmt-rsa.c
buff, data,der_data DER/PEM read from NV index tpm2_handle_load_index tpm2-provider-store-handle.c

Test

I have confirmed that make check completed successfully.

@hyperfinitism hyperfinitism changed the title fix: cleanse-before-free buffers for sensitive data Cleanse-before-free buffers for sensitive data Mar 5, 2026
Copy link
Copy Markdown
Contributor

@gotthardp gotthardp left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I suggest few code simplifications based on #168.

Comment thread src/tpm2-provider-cipher.c Outdated
Comment thread src/tpm2-provider-keyexch.c Outdated
Comment thread src/tpm2-provider-store-handle.c Outdated
Comment thread src/tpm2-provider-store-handle.c Outdated
@hyperfinitism
Copy link
Copy Markdown
Contributor Author

Thank you for the review. Once PR #168 is merged, I will rebase this branch and address the suggested changes.

@gotthardp
Copy link
Copy Markdown
Contributor

Thank you for the review. Once PR #168 is merged, I will rebase this branch and address the suggested changes.

#168 is merged now

@hyperfinitism hyperfinitism force-pushed the fix/sensitive-data-zeroing branch 3 times, most recently from ae25bcd to a7763ff Compare March 8, 2026 17:29
Comment thread src/tpm2-provider-store-handle.c Fixed
@hyperfinitism hyperfinitism force-pushed the fix/sensitive-data-zeroing branch 3 times, most recently from 5e9b041 to 6aaf390 Compare March 8, 2026 17:47
Replace free() with cleanse_free() for some Esys-allocated buffers that
contains sensitive data.
The following buffers are now guaranteed to be zeroed after freed.

- RSA decrypted plaintext (tpm2-provider-asymcipher-rsa)
- Private key and decrypted plaintext (tpm2-provider-cipher)
- Private key (tpm2-keymgmt-ec)
- Private key (tpm2-keymgmt-rsa)
- DER/PEM contents read from NV index (tpm2-provider-store-handle)
- ECDH shared secret (tpm2-provider-keyexch)

Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
@hyperfinitism hyperfinitism force-pushed the fix/sensitive-data-zeroing branch from 6aaf390 to d35cea0 Compare March 8, 2026 18:08
@hyperfinitism
Copy link
Copy Markdown
Contributor Author

I have addressed all your suggested changes.

Copy link
Copy Markdown
Contributor

@gotthardp gotthardp left a comment

Choose a reason for hiding this comment

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

Thank you for the changes.

@gotthardp gotthardp merged commit c25a1ad into tpm2-software:master Mar 8, 2026
7 of 8 checks passed
@hyperfinitism hyperfinitism deleted the fix/sensitive-data-zeroing branch March 8, 2026 19:17
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