Why does the variable address keep changing between runs

I made two C programs that were exact copies of each other. Compiled them on the Linux platform (Ubuntu 10.04) using the gcc compiler and got two separate executable files. Then I got the assembly code of both executable files using objdump, and found that the assembly code was exactly the same, and even the address of the corresponding instructions in the two assembly files was the same. The program should have printed the address of the variable in it. Programs at startup create a different address, and in addition, the same program creates a different address at startup each time. Why is the address of the lines of code the same in two programs, but the address of the variable changes even for the same program every time it is run. I think the address printed by the variable on the screen is a virtual address, but if its virtual, why can it 't be the same every time. Is the address shown in the assembly code obtained by objdump also virtual?

+5
source share
2 answers

This is due to the randomization of the location of the address space .

To quote Wikipedia:

Address Space Location Randomization (ASLR) is a computer security method that involves randomly positioning the positions of key data areas, usually including the base of the executable file and the location of the libraries, heap and stack in the process address space.

Benefits

, . , , return-to-libc, , , , shellcode, , . . , - .

, , C Ubuntu 10.10:

#include <stdio.h>

int g = 0;

int main() {
  int x = 0;
  printf("%p %p\n", &x, &g);
}

(x) , (g) .

+5

, Address. , , , . , , .

+1

All Articles