Bugtraq mailing list archives
When scrubbing secrets in memory doesn't work
From: "Michael Howard" <mikehow () microsoft com>
Date: Tue, 5 Nov 2002 10:45:30 -0800
During the Windows Security Push in Feb/Mar 2002, we noticed an 'interesting' anomaly with code to scrub passwords that looks like this: bool DoSensitiveStuff() { bool fOK = false; const size_t cbPwd = 64; char szPwd[cbPwd]; if (GetUserPassword(szPwd,cbPwd-1)) if (DoSomethingWithPassword(szPwd)) fOK = true; memset(szPwd,0,cbPwd); return fOK; } On the surface, this looks fine, until you look at the ASM output, and you see the call to memset has been removed by the optimizer because szPwd is not read once the function completes. Hence, the secret data is still floating in memory. This optimization, common in most modern C/C++ compilers is often referred to as "dead store removal." A full write-up outlining the issue in more detail, as well as some remedies is at http://msdn.microsoft.com/library/en-us/dncode/html/secure10102002.asp. Cheers, Michael Howard Secure Windows Initiative Microsoft Corp. Writing Secure Code http://www.microsoft.com/mspress/books/5612.asp
Current thread:
- When scrubbing secrets in memory doesn't work Michael Howard (Nov 05)
- Re: When scrubbing secrets in memory doesn't work Perry E. Metzger (Nov 05)
- Re: When scrubbing secrets in memory doesn't work Andy Polyakov (Nov 07)
- Re: When scrubbing secrets in memory doesn't work Gianni Tedesco (Nov 07)
- Re: When scrubbing secrets in memory doesn't work Valdis . Kletnieks (Nov 08)
- Re: When scrubbing secrets in memory doesn't work Michael Zimmermann (Nov 09)
- Re: When scrubbing secrets in memory doesn't work Jan Echternach (Nov 14)
- <Possible follow-ups>
- When scrubbing secrets in memory doesn't work Michael Howard (Nov 09)
- RE: When scrubbing secrets in memory doesn't work Michael Wojcik (Nov 12)
- RE: When scrubbing secrets in memory doesn't work Michael Wojcik (Nov 17)
- Re: When scrubbing secrets in memory doesn't work Nicholas Weaver (Nov 18)
- Re: When scrubbing secrets in memory doesn't work Richard Moore (Nov 20)
- Re: When scrubbing secrets in memory doesn't work Florian Weimer (Nov 18)
- Re: When scrubbing secrets in memory doesn't work Peter Watkins (Nov 19)
- Re: When scrubbing secrets in memory doesn't work Nicholas Weaver (Nov 18)
- Re: When scrubbing secrets in memory doesn't work Perry E. Metzger (Nov 05)