The Virtual Memory Manager (VMM) in Windows does not allow programs to lock user memory in order to prevent that memory from being swapped out to disk. This limitation, not present in other operating systems, has caused numerous security problems with encryption keys, passwords, and other sensitive information leaking from RAM to hard disk automatically under Microsoft Windows.
As demonstrated in my previous column ("Beware of File-Slack Attacks http://www.ddj.com/documents/ddj041006sec/), anything written to hard disk temporarily can be recovered with relative ease. The system virtual-memory-paging swap file can be resized manually, or Windows may resize it as needed. When the pagefile grows in size, there will not be any sensitive data stored in unallocated clusters on the drive, but that does not mean the sensitive data cannot be accessed.
Powering down a Windows box and removing the drive that contains a pagefile allows unrestricted access to its contents. A drive sector editor or other forensic tool can read directly from the sectors and clusters that belong to the system pagefile. Or, the pagefile may shrink when a reboot occurs, exposing formerly allocated clusters from the pagefile as unallocated clusters that can then easily be carved from the drive.
The only way to prevent Windows from swapping data from RAM to pagefile is to manage physical memory directly in your code. Windows 2000 introduced an API for doing just this, known as Address Windowing Extensions (AWE). The primary purpose of AWE is to remove the 4-GB physical memory limit of a 32-bit software architecture by enabling code to allocate large chunks of physical memory and then map access to the physical memory into a window of virtual memory that is 32-bit addressable. This is similar to working with memory-mapped files that are larger than the available physical memory in a computer, except there is no disk I/O involved.
The MSDN Library contains documentation for the AWE support functions: http://msdn.microsoft.com/library/en-us/memory/base/address_windowing_extensions.asp
Sample code for making use of AWE can also be found in an October 1999 MSJ article written by Jeffrey Richter: http://www.microsoft.com/msj/1099/win32/win321099.aspx
Special privileges are required in order for a user account other than System to use AWE. By default, no user, not even Administrator, is granted the necessary privilege. The "Lock Pages in Memory" user right can be assigned by using Group Policy Editor (gpedit.msc), which hosts the Group Policy MMC snap-in.
Windows XP Home does not support Policies or User Rights, but it should be possible to grant the "Lock Pages in Memory" privilege with a hack to the HKLM\SECURITY Registry hive if support under Windows XP is critical for your secure application.
Jason Coombs is Director of Forensic Services for PivX Solutions Inc. (NASDAQ OTCBB: PIVX), a provider of security solutions, computer forensics, and expert witness services. Reach him at jcoombs@PivX.com.