21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

eturn dst;<br />

}<br />

volatile void *spc_memmove(volatile void *dst, volatile void *src, size_t len) {<br />

size_t i;<br />

volatile char *cdst, *csrc;<br />

cdst = (volatile char *)dst;<br />

csrc = (volatile char *)src;<br />

if (csrc > cdst && csrc < cdst + len)<br />

for (i = 0; i < len; i++) cdst[i] = csrc[i];<br />

else<br />

while (len--) cdst[len] = csrc[len];<br />

return dst;<br />

}<br />

If you’re writing code for Windows using the latest Platform SDK, you can use<br />

SecureZeroMemory( ) instead of spc_memset( ) to zero memory. SecureZeroMemory( ) is<br />

actually implemented as a macro to RtlSecureMemory( ), which is implemented as an<br />

inline function in the same way that spc_memset( ) is implemented, except that it only<br />

allows a buffer to be filled with zero bytes instead of a value of the caller’s choosing<br />

as spc_memset( ) does.<br />

13.3 Preventing Memory from Being Paged to<br />

Disk<br />

<strong>Problem</strong><br />

Your program stores sensitive data in memory, and you want to prevent that data<br />

from ever being written to disk.<br />

Solution<br />

On Unix systems, the mlock( ) system call is often implemented in such a way that<br />

locked memory is never swapped to disk; however, the system call does not necessarily<br />

guarantee this behavior. On Windows, VirtualLock( ) can be used to achieve the<br />

desired behavior; locked memory will never be swapped to disk.<br />

Discussion<br />

The solutions presented here are not foolproof methods. Given<br />

enough time and resources, someone will eventually be able to extract<br />

the data from the program’s memory. The best you can hope for is to<br />

make it so difficult to do that an attacker deems it not worth the time.<br />

Preventing Memory from Being Paged to Disk | 707<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!