Amir reza Riahi
Amir reza Riahi

Reputation: 2450

Difference between 1 and 2 in /proc/sys/kernel/randomize_va_space (ASLR)

This source explains each value:

0

Disable ASLR. This setting is applied if the kernel is booted with the norandmaps boot parameter.

1

Randomize the positions of the stack, virtual dynamic shared object (VDSO) page, and shared memory regions. The base address of the data segment is located immediately after the end of the executable code segment.

2

Randomize the positions of the stack, VDSO page, shared memory regions, and the data segment. This is the default setting.

I can not understand the difference between 1 and 2. At first I thought that the data segment (where initialized static/global variables reside) would not be randomized in option 1 but it seems not correct. The following program:

#include <stdio.h>

static int a = 1;

int main() {
   printf("%p\n", &a);
}

Has the below outputs when ASLR is set to 1:

root@ok:/tmp# echo 1 > /proc/sys/kernel/randomize_va_space 
root@ok:/tmp# ./a.out 
0x561e130dd018
root@ok:/tmp# ./a.out 
0x55cc29f85018
root@ok:/tmp# ./a.out 
0x558d670d4018
root@ok:/tmp# ./a.out 
0x564800738018
root@ok:/tmp# ./a.out 
0x55fb38c0a018

Upvotes: 0

Views: 150

Answers (0)

Related Questions