ArticleslgStudy

science

Address space layout randomization

Address space layout randomization is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Address space layout randomization rather than just read about it. In short: 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…

Key takeaways

  • Address space layout randomization belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Address space layout randomization to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Address space layout randomization from memory before moving on to harder problems.

Reference excerpt

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.

Worked examples

Example 1 — a first encounter with Address space layout randomization

Start with the simplest possible case. Write down what Address space layout randomization claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Address space layout randomization before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Address space layout randomization ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Address space layout randomization

In research
Address space layout randomization appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Address space layout randomization in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Address space layout randomization is common in secondary-school and first-year university syllabi. It links to neighbouring topics Operating system security, so understanding it makes those chapters shorter.
In everyday life
Look for Address space layout randomization outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Address space layout randomization” →

How to study Address space layout randomization in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Address space layout randomization means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Address space layout randomization out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Address space layout randomization in simple terms?

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 addr…

Why does Address space layout randomization matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Address space layout randomization?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Address space layout randomization.

Tags

  • Operating system security

Keep exploring