Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does using SecureZeroMemory() really help to make the application more secure?

There's a SecureZeroMemory() function in WinAPI that is designed for erasing the memory used for storing passwords/encryption keys/similar stuff when the buffer is no longer needed. It differs from ZeroMemory() in that its call will not be optimized out by the compiler.

Is it really so necessary to erase the memory used for storing sensitive data? Does it really make the application more secure?

I understand that data could be written into swapfile or into hibernation file and that other processes could possibly read my program's memory. But the same could happen with the data when it is still in use. Why is use, then erase better than just use?

like image 311
sharptooth Avatar asked Apr 24 '09 14:04

sharptooth


3 Answers

It does. Hibernation file is not encrypted, for example. And if you don't securely clear the memory, you might end up with trouble. It's just a single example, though. You should always hold secret stuff in memory only as long as needed.

like image 62
mmx Avatar answered Oct 05 '22 02:10

mmx


It exists for a reason. :) If you keep sensitive data in memory, then other processes can potentially read it.

Of course, in your application, passwords or other secure data may not be so critical that this is required. But in some applications, it's pretty essential that malicious code can't just snoop your passwords or credit card numbers or whatever other data the application uses.

like image 43
jalf Avatar answered Oct 05 '22 03:10

jalf


Also note that it might be that some OS'es will not zero memory before giving it to an application, this means that an application might randomly request memory, scan it for possibly interesting content and do something with it.

If that application would only get zero'd memory, of course it would have a harder time trying to get interesting data.

like image 28
Lennaert Avatar answered Oct 05 '22 01:10

Lennaert