Skip to content
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

Implement custom Drop trait for all private keys to zero memory #566

Closed
heartsucker opened this issue Jul 28, 2017 · 4 comments
Closed

Implement custom Drop trait for all private keys to zero memory #566

heartsucker opened this issue Jul 28, 2017 · 4 comments

Comments

@heartsucker
Copy link

I'm not sure if this would be considered overkill, but I think that it would marginally increase the security of the library if key material were destroyed before releasing the memory back to the OS. I only checked that this trait was or wasn't implemented for RSAPrivateKey before opening this issue.

Related: theupdateframework/rust-tuf#125

@burdges
Copy link

burdges commented Jul 28, 2017

As a technical matter, you cannot formally impose security properties with Drop since memory leaks are considered memory safe. That doesn't mean this is not a good idea! Everyone tries hard to ensure that Drop always gets run eventually. And https://github.com/cesarb/clear_on_drop works fine in practice.

We've had several discussions around this like https://github.com/isislovecruft/curve25519-dalek/issues/11 and rust-lang/rfcs#1850 but actually the most informative thing was Laurent Simon's work presented at Real World Crypto last year : You do not necessarily want to zero cryptographic key material when they types get dropped, as you might make many intermediate values. You often want to instrument your functions, keep key material only on the stack, and zero all the stack that you used when your cryptographic routines conclude. See rust-lang/rfcs#1853 (comment)

I think ring is self contained enough to do zeroing in a variety of ways of course, but the wider Rust ecosystem should find ways to follow Laurent Simon's suggestions.

@heartsucker
Copy link
Author

Ah, thanks for the links. My cursory search didn't turn up anything useful. And it seems this is something that would have to be solved at the language level and not with some tinkering with traits/unsafe.

@nadimkobeissi
Copy link

@burdges I googled "rust memory erasure" and it led me to a rabbit hole of insightful commentary from you on this issue all over GitHub. Thanks for all the info on this!

@briansmith
Copy link
Owner

I'm going to close this because solutions based on Drop don't work in general because of mem::forget() and other ways of leaking objects.

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

No branches or pull requests

4 participants