Description
Yesterday @burdges mentioned some ideas about how to try to erase secret data from memory, and some things about zero-on-drop behaviour in Rust. It would be good to have a reliable way to clear secret data.
If I understand correctly, just implementing the Drop
trait to zero memory may not be sufficient, for two reasons:
-
the write may be optimized away (see also);
-
drop()
may never be called, because Rust's memory model allows memory leaks: "memory unsafety is doing something with invalid data, a memory leak is not doing something with valid data"
Other notes that may be of interest: this morning at RWC 2017, Laurent Simon (@lmrs2 ?) presented secretgrind.
It could be quite convenient if Rust had a #[secret_stack]
function annotation that guaranteed stack erasure, but this would require a language change.