Address space layout randomization

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Tatufan (talk | contribs) at 19:31, 13 September 2010. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Address space layout randomization (ASLR) is a computer security technique which involves randomly arranging the positions of key data areas, usually including the base of the executable and position of libraries, heap, and stack, in a process's address space.

Benefits

Address space randomization hinders some types of security attacks by making it more difficult for an attacker to predict target addresses. For example, attackers trying to execute return-to-libc attacks must locate the code to be executed, while other attackers trying to execute shellcode injected on the stack have to first find the stack. In both cases, the related memory addresses are obscured from the attackers. These values have to be guessed, and a mistaken guess is not usually recoverable due to the application crashing.

Effectiveness

Address space layout randomization relies on the low chance of an attacker guessing where randomly-placed areas are located. Security is increased by increasing the search space. Thus, address space randomization is more effective when more entropy is present in the random offsets. Entropy is increased by either raising the amount of virtual memory area space the randomization occurs over, or reducing the period the randomization occurs over. The period is typically implemented as small as possible, so most systems must increase VMA space randomization.

To defeat the randomization, attackers must successfully guess the positions of all areas they wish to attack. For data areas such as stack and heap, where custom code or useful data can be loaded, more than one state can be attacked by using NOP slides for code or repeated copies of data. This allows an attack to succeed if the area is randomized to one of a handful of values. In contrast, code areas such as library base and main executable need to be discovered exactly. Often these areas are mixed, for example stack frames are injected onto the stack and a library is returned into.

To begin, let us declare the following variables:

To calculate the probability of an attacker succeeding, we have to assume a number of attempts carried out without being interrupted by a signature-based IPS, law enforcement, or other factor; in the case of brute forcing, the daemon cannot be restarted. We also have to figure out how many bits are relevant and how many are being attacked in each attempt, leaving however many bits the attacker has to defeat.

The following formulas represent the probability of success for a given set of attempts on bits of entropy.

In many systems, can be in the thousands or millions; on modern 64-bit systems, these numbers typically reach the millions at least. For 32-bit systems at 2004 computer speeds which have 16 bits for address randomisation, Shacham and co-workers state "... 16 bits of address randomization can be defeated by a brute force attack within minutes."[1] It should be noted that the authors' statement depends on the ability to attack the same application multiple times without any delay. Proper implementations of ASLR, like that included in grsecurity, provide several methods to make such brute force attacks infeasible. One method involves preventing an executable from executing for a configurable amount of time if it has crashed a certain number of times.

Some systems implement Library Load Order Randomization, a form of ASLR which randomizes the order in which libraries are loaded. This supplies very little entropy. An approximation of the number of bits of entropy supplied per needed library is shown below; this does not yet account for varied library sizes, so the actual entropy gained is really somewhat higher. Note that attackers usually need only one library; the math is more complex with multiple libraries, and shown below as well. Note that the case of an attacker using only one library is a simplification of the more complex formula for .

These values tend to be low even for large values of , most importantly since attackers typically can use only the C standard library and thus one can often assume that . Interestingly, however, even for a small number of libraries there are a few bits of entropy gained here; it is thus potentially interesting to combine library load order randomization with VMA address randomization to gain a few extra bits of entropy. Note that these extra bits of entropy will not apply to other mmap() segments, only libraries.

Reducing entropy

Attackers may make use of several methods to reduce the entropy present in a randomized address space, ranging from simple information leaks to attacking multiple bits of entropy per attack (such as by heap spraying). There is little that can be done about this.

It is possible to leak information about memory layout using format string vulnerabilities. Format string functions such as printf() use a variable argument list to do their job; format specifiers describe what the argument list looks like. Because of the way arguments are typically passed, each format specifier moves closer to the top of the stack frame. Eventually, the return pointer and stack frame pointer can be extracted, revealing the address of a vulnerable library and the address of a known stack frame; this can completely eliminate library and stack randomization as an obstacle to an attacker.

One can also decrease entropy in the stack or heap. The stack typically must be aligned to 16 bytes, and so this is the smallest possible randomization interval; while the heap must be page-aligned, typically 4096 bytes. When attempting an attack, it is possible to align duplicate attacks with these intervals; a NOP slide may be used with shellcode injection, and the string '/bin/sh' can be replaced with '////////bin/sh' for an arbitrary number of slashes when attempting to return to system(). The number of bits removed is exactly for intervals attacked.

Such decreases are limited due to the amount of data in the stack or heap. The stack, for example, is typically limited to 8MB[2] and grows to much less; this allows for at most 19 bits, although a more conservative estimate would be around 8-10 bits corresponding to 4-16KB[2] of stack stuffing. The heap on the other hand is limited by the behavior of the memory allocator; in the case of glibc, allocations above 128KB are created using mmap(), limiting attackers to 5 bits of reduction. This is also a limiting factor when brute forcing; although the number of attacks to perform can be reduced, the size of the attacks is increased enough that the behavior could in some circumstances become analogous to intrusion detection systems.

History

The PaX project first coined the term "ASLR". It published the first design and implementation of ASLR in July, 2001. This remains the most complete implementation, providing also kernel stack randomization from October 2002 onward. It also continues to provide the most entropy for each randomized layout compared to other implementations.[3]

Implementations

Several mainstream, general-purpose operating systems implement ASLR.

OpenBSD

OpenBSD became one of the first mainstream operating systems to support ASLR (and to activate it by default)[4]

Linux

Linux has enabled a weak[5] form of ASLR by default since kernel version 2.6.12 (released June 2005). The PaX and ExecShield patchsets to the Linux kernel provide more complete implementations. Various Linux distributions including Adamantix, Alpine Linux, Hardened Gentoo, and Hardened Linux From Scratch come with PaX's implementation of ASLR by default.

The Exec Shield patch for Linux supplies 19 bits of stack entropy on a period of 16 bytes; and 8 bits of mmap() base randomization on a period of 1 page of 4096 bytes. This places the stack base in an area 8MB wide containing 524288 possible positions; and the mmap() base in an area 1MB wide containing 256 possible positions.

Position-independent executable (PIE) feature implements random base address for the main executable binary since 2003. It provides the same address randomness to the main executable as being used for the shared libraries. The PIE feature is in use only for the network facing daemons - the PIE feature cannot be used together with the prelink feature for the same executable.

The prelink tool implements randomization at prelink time rather than runtime, because by design prelink aims to handle relocating libraries before the dynamic linker has to, which allows the relocation to occur once for many runs of the program. As a result, real address space randomization would defeat the purpose of prelinking.

Microsoft Windows

Microsoft's Windows Vista (released January 2007), Windows Server 2008, Windows 7, and Windows Server 2008 R2 have ASLR enabled by default, although only for those executables and dynamic link libraries specifically linked to be ASLR-enabled.[6] This did not include Internet Explorer 7 on Windows Vista prior to Service Pack 1; ASLR and DEP are both disabled for application compatibility purposes.[7] Newer versions, including Internet Explorer 8 (released March 2009), enable these protections. A registry setting is available to forcibly enable or disable ASLR for all executables and libraries. When registry key "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\MoveImages".[8]

The locations of the heap, stack, Process Environment Block, and Thread Environment Block are also randomized. A security whitepaper from Symantec noted that ASLR in 32-bit Windows Vista may not be as robust as expected, and Microsoft has acknowledged a weakness in its implementation.[9]

Host-based Intrusion prevention systems such as WehnTrust [10] and Ozone [11] also offer ASLR for Windows XP and Windows Server 2003 operating systems; however complete details of their implementation are not available.[12]

Mac OS X

Apple introduced randomization of some library offsets in Mac OS X v10.5 (released October 2007)[13]. Their implementation does not provide complete protection against attacks which ASLR is designed to defeat.[14][15][16][17]

See also

References

  1. ^ On the Effectiveness of Address-Space Randomization,Shacham, H. and Page, M. and Pfaff, B. and Goh, E.J. and Modadugu, N. and Boneh, D,Proceedings of the 11th ACM conference on Computer and communications security,pp 298--307, 2004
  2. ^ a b Transistorized memory, such as RAM, ROM, flash and cache sizes as well as file sizes are specified using binary meanings for K (10241), M (10242), G (10243), etc.
  3. ^ Comparison of PaX to ExecShield and W^X
  4. ^ Theo De Raadt (2005). "Exploit Mitigation Techniques (updated to include random malloc and mmap) at OpenCON 2005". Retrieved 26 August 2009.
  5. ^ http://www.tomshardware.com/reviews/pwn2own-mac-hack,2254-4.html
  6. ^ http://msdn.microsoft.com/en-us/library/bb430720.aspx
  7. ^ "MS08-078 and the SDL". The Security Development Lifecycle. Microsoft. December 18, 2008. Retrieved 2009-03-21.
  8. ^ Windows Internals: Including Windows Server 2008 and Windows Vista, Fifth Edition (PRO-Developer) ISBN 978-0-735-62530-3
  9. ^ Ollie Whitehouse (2007). "An Analysis of Address Space Layout Randomization on Windows Vista" (PDF). {{cite web}}: Unknown parameter |month= ignored (help)
  10. ^ WehnTrust
  11. ^ Security Architects' Ozone
  12. ^ Address-Space Randomization for Windows Systems
  13. ^ Apple - Mac OS X - Security - Keeps safe from viruses and malware
  14. ^ Quick Leopard Update | securosis.com
  15. ^ Matasano Chargen » A Roundup Of Leopard Security Features
  16. ^ Matasano Chargen » What We’ve Since Learned About Leopard Security Features
  17. ^ TippingPoint | DVLabs | New Leopard Security Features - Part I: ASLR

External links