3

I created a simple C program and every time I load it in GDB, I see the same memory addresses allocated to the instructions of the program. For example, a function what() always loads at memory location 0x000055555555472d. In fact the stack is exactly the same for each execution(Not just the content of stack but the memory address which rsp points to.

I understand that ASLR can be disabled in Linux by setting "/proc/sys/kernel/randomize_va_space" to 0 but my Debian system has value 2 in it.

root@Sierra ~ % cat /proc/sys/kernel/randomize_va_space 
2

According to my understanding of ASLR, these addresses should be randomized at each run. My question is why is this happening? Did I get something wrong?

5

Gdb disables address space randomization on Linux by default. The gdb command set disable-randomization off will turn this feature off, and any debugging targets created by gdb afterwards will have ASLR either on or off depending on the value of the kernel.randomize_va_space sysctl variable.

0

How was the program compiled? On a Centos 7 system given blah.c and with the development foo installed

#include <stdio.h>

int whereisthis(void) { return 42; }

int main(void) {
    printf("%p\n", whereisthis);
    return 0;
}

the address of whereisthis can depend on the compile flags

% rm blah
% CFLAGS='-pipe' make blah
cc -pipe    blah.c   -o blah
% repeat 3 ./blah
0x40054c
0x40054c
0x40054c
% rm blah
% CFLAGS='-fstack-protector-all -fPIE -pie -pipe' make blah
cc -fstack-protector-all -fPIE -pie -pipe    blah.c   -o blah
% repeat 3 ./blah
0x7f0e9d3ba82f
0x7fd940aca82f
0x7f6961b1182f
% 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.