Pseudo-random stack pointer under Linux?

I played with some code when I noticed something strange:

[~] main% cat test.cc #include <stdio.h> void f() { int i; fprintf(stderr, "&i = 0x%08X\n", (long)&i); } int main(int argc, char**argv) { f(); } [~] main% g++ test.cc [~] main% ./a.out &i = 0xBFA27AB4 [~] main% ./a.out &i = 0xBFAD7E24 [~] main% ./a.out &i = 0xBFCA3464 [~] main% ./a.out &i = 0xBF96C064 [~] main% 

The odd thing for me is a change in the address of variable i.

I assume that the kernel supplies different starting addresses of the stack in order to try to break some kind of crack. What is the real reason?

+8
stack linux
source share
1 answer

randomization of the location of the address space is used precisely for several operating systems for this very reason. Perhaps your variations in stack pointer addresses are caused by this - most likely, this will be the case in recent versions of Linux and / or BSD. Other IIRC versions also do this.

+13
source share

All Articles