Address space layout randomization (ASLR) is a computer security technique involved in preventing exploitation of memory corruption vulnerabilities. In order to prevent an attacker from reliably redirecting code execution to a particular exploited function in memory, ASLR randomly arranges the address space positions of key data areas of a process, including the base of the executable and the positions of the stack, heap and libraries. When applied to the kernel, this technique is called kernel address space layout randomization (KASLR).
History The Linux PaX project first coined the term "ASLR", and published the first design and implementation of ASLR in July 2001 as a patch for the Linux kernel. It is seen as a complete implementation, providing a patch for kernel stack randomization since October 2002. The first mainstream operating system to support ASLR by default was OpenBSD version 3.4 in 2003, followed by Linux in 2005.
Benefits Address space randomization hinders some types of 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 find the stack first. In both cases, the system makes related addresses in memory difficult for the attacker to predict. These values have to be guessed, and a mistaken guess is not usually recoverable due to the application crashing.
Effectiveness Address space layout randomization is based upon the low chance of an attacker guessing the locations of randomly placed areas. 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 over which the randomization occurs or reducing the period over which the randomization occurs. 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. The following variables can be declared:
Es (entropy bits of stack top) Em (entropy bits of mmap() base) Ex (entropy bits of main executable base) Eh (entropy bits of heap base) As (attacked bits per attempt of stack entropy) Am (attacked bits per attempt of mmap() base entropy) Ax (attacked bits per attempt of main executable entropy) Ah (attacked bits per attempt of heap base entropy) α (attempts made) N (total amount of entropy: N=(Es−As)+(Em−Am)+(Ex−Ax)+(Eh−Ah)) To calculate the probability of an attacker succeeding, a number of attempts α carried out without being interrupted by a signature-based IPS, law enforcement, or other factor must be assumed; in the case of brute forcing, the daemon cannot be restarted. The number of relevant bits and how many are being attacked in each attempt must also be calculated, leaving however many bits the attacker has to defeat. The following formulas represent the probability of success for a given set of α attempts on N bits of entropy.
g(α)=1−(1−2−N)α if 0≤α (isolated guessing; address space is re-randomized after each attempt) b(α)=α2N if 0≤α≤2N (systematic brute forcing on copies of the program with the same address space) In many systems, 2N can be in the thousands or millions. On 32-bit systems, a typical amount of entropy N is 8 bits. For 2004 computer speeds, Shacham and co-workers state "... 16 bits of address randomization can be defeated by a brute force attack within minutes." (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.) On modern 64-bit systems, these numbers typically reach the millions at least. Android, and possibly other 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 appears below; this does not yet account for varied library sizes, so the actual entropy gained is really somewhat higher. Attackers usually need only one library; the math is more complex with multiple libraries, and shown below as well. The case of an attacker using only one library is a simplification of the more complex formula for l=1.
l (number of libraries loaded) β (number of libraries used by the attacker) Em={log2(l) if β=1,l≥1∑i=ll−(β−1)log2(i) if β≥1,l≥1 These values tend to be low even for large values of l, most importantly since attackers typically can use only the C standard library and thus one can often assume that β=1. 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. These extra bits of entropy will not apply to other mmap() segments, only libraries.
… excerpt ends here. Continue reading the full article.