Skip to content

refactor: use secret.Do instead of memcall - #137

Draft
MJDSys wants to merge 2 commits into
Foxboron:masterfrom
MJDSys:switch-to-using-runtime-secret
Draft

refactor: use secret.Do instead of memcall#137
MJDSys wants to merge 2 commits into
Foxboron:masterfrom
MJDSys:switch-to-using-runtime-secret

Conversation

@MJDSys

@MJDSys MJDSys commented Aug 14, 2026

Copy link
Copy Markdown

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.

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.

MJDSys added 2 commits August 13, 2026 22:30
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.
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.

1 participant