LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Variable at random location in memory? (https://www.linuxquestions.org/questions/linux-software-2/variable-at-random-location-in-memory-477520/)

Ephracis 08-26-2006 05:58 AM

Variable at random location in memory?
 
IIRC global variables like PATH used to exist at a certain memory address. But now it seems you never know where it is. I made a program before that printed out the address of a variable, and when I use it now it keeps showing up seemingly random addresses.

Code:

/* getenvaddr.c */
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
        char *addr;
        addr = getenv(argv[1]);
        printf("Addr: %p\n", addr);
}

Code:

[root@garanka laboratory] # ./getenvaddr PATH
Addr: 0xaf9dfe9b
[root@garanka laboratory] # ./getenvaddr PATH
Addr: 0xafe83e9b
[root@garanka laboratory] # ./getenvaddr PATH
Addr: 0xaf88be9b

What has happened and why?

macemoneta 08-26-2006 10:59 PM

This may be part of the Execshield implementation:

cat /proc/sys/kernel/exec-shield-randomize

0 — Randomized VM mapping is disabled
1 — Randomized VM mapping is enabled

Update: on later kernels, the value may be in:

cat /proc/sys/kernel/randomize_va_space

Ephracis 08-27-2006 05:49 AM

Yeah I've read a little bit and it seems that we now have ASLR in Linux. On an interesting note this will also come to Vista (in a lesser secure way it seems, though).


All times are GMT -5. The time now is 04:43 AM.