Reputation: 150
If we write a C code like printf("%p\n", __builtin_return_address(0));
and suppose we get the result 0xabcd
from customer's platform. And then, we run the same program with gdb on our platform, and we find out that 0xabcd
maps to sample_function()
, is this same function on customer's platform when he is running that program? Or in other word, is stack address fixed or dynamic for same program but different hardware platform?
Upvotes: 0
Views: 183
Reputation: 148
In order to prevent some attacks, such as buffer overflow, operating systems use Address Space Layout Randomization (ASLR). ASLR ensures that each time you run a program, the addresses will be placed randomly on virtual address space. On Linux, it is enabled by default. You can disable it by running
echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
And then, if you want to enable it again, just run
echo 2 | sudo tee /proc/sys/kernel/randomize_va_space
For more information you can check this article How Effective is ASLR on Linux Systems?
On the other hand, ASLR is disabled in gdb by default to ease debugging. You can enable/disable it with these commands
set disable-randomization off
set disable-randomization on
Upvotes: 1