-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: Go 2: "sensitive" keyword to mark vars / consts containing sensitive data such as crypto keys #21374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A few comments:
Overall, I see the appeal of the mechanism, but it seems to me that a library is the better approach than introducing an unproven concept into the language. |
Regarding your points:
EDIT: |
@leonklingele I meant "constants", not "comments", of course. Apologies, my typo. Corrected. |
Language changes aside, it would be useful to have a function in the standard library for zeroing memory that was guaranteed not to be optimized away by dead store elimination. Right now you'd have to resort to something like the old trick of calling memset through a function pointer in a different translation unit. Asking GC to finalize 'sensitive' data wouldn't be any more reliable than finalizers are today (as in, not very). There would still likely be a large time window during which the data would be 'dead' but still present for an attacker to harvest. Of course, Go is pretty far from a real-time language, so you don't really have any guarantee of timeliness even if you zero the memory explicitly in the code. |
An explicit The |
I disagree about the crypto package. The problem in this proposal is poorly defined and makes assumptions about physical device security. The proposed solution should not be in a package known for making precise security guarantees. |
As a language design concept, this seems too experimental for Go. It's not clear precisely what it means for Go, and it's not clear that it actually provides any additional security. As mentioned above a few times, this should be addressed as an external package first. As far as I can see, an external package using reflect could do anything that a language keyword could do. |
Proposal
As explained in #18645, one is currently missing a way to wipe sensitive material from memory in Go.
Recently a new library (memguard) arose which tries to solve that exact problem and I think something like this should be available in the Go 2 standard library.
(
memguard
only works with byte slices, this proposal extends that behavior to more (all?) built-in types.)Reasoning
It's a common practice to erase sensitive data from memory after use and ensure that it is never swapped out to disk. This pretty much sums it up:
Examples
Example 1
Variables and constants which are intended to hold sensitive data such as cryptographic keys can be declared / initialized as follows:
As soon as
key
in the example above goes out of scope it is securely wiped (to be defined) from memory.Example 2
Example 3
Reassigning variables marked as
sensitive
should wipe them firstAdditions
One should be able to wipe vars declared
sensitive
before they go out of scope:EDIT:
mmap
->mlock
The text was updated successfully, but these errors were encountered: