refactor: use secret.Do instead of memcall - #137
Draft
MJDSys wants to merge 2 commits into
Draft
Conversation
Previously, ssh-tpm-agent would leak the buffer containing the passphrase as the buffer wrapper was dropped. This is hard to fix as the underlying tpm keyfile library expects a normal go byte slice as the passphrase, not an externally managed memory segment. This changes the signing module to wrap the passphrase fetching code so the buffer can also be returned, allowing it to be freed when present. It also leaves the option for the askpass machinery to provide similar buffers in the future.
Use the new (experimental) `secret.Do` in Go 1.26 instead of relying on memcall to protect the passphrase of the user. This requires a forced GC after signing to ensure all relevant buffers are removed from memory, or the passphrase can be trivially found in a coredump. But I don't believe this guarantees the GC will clear the buffer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use the new (experimental)
secret.Doin Go 1.26 instead of relying on memcall to protect the passphrase of the user.This requires a forced GC after signing to ensure all relevant buffers are removed from memory, or the passphrase can be trivially found in a coredump. But I don't believe this guarantees the GC will clear the buffer.
Based on #135 to show the difference easily to both master and that branch. I do still think we should keep memcall for
mlock. But after using my ssh-tpm-key a few times, I could confirm no passphrase was in the generated core dump. But a core dump mid-signing would still likely leak the passphrase.Marked as a draft since Github workflow will need adjusting to enable the experimental Go feature.