Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm reading "The art of exploitation" and would like to try some experiments, including reading from and writing to various memory address. I've created some simple programs and trying to overwrite their variables via various hacks, the problem is that these variables' addresses keep changing every time I run the program, making all this extremely complicated.
I know this is for security reasons but I'm wondering if is it possible to disable it for learning purposes. Here's my system's and gcc's info:

blackbear@blackbear-laptop:~$ uname -a
Linux blackbear-laptop 2.6.32-30-generic #59-Ubuntu SMP Tue Mar 1 21:30:21 UTC 2011 i686 GNU/Linux
blackbear@blackbear-laptop:~$ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

share|improve this question
up vote 5 down vote accepted

If I'm not mistaken it should be possible to disable the address space randomization via proc filesystem:

echo 0 > /proc/sys/kernel/randomize_va_space

Obviously, you have to be root for this.

share|improve this answer
Got it. But it gives me "access denied" even with sudo – BlackBear Apr 26 '11 at 15:53
That's because shell does the redirection before executing sudo. So if you need/want to use sudo, you have to do it as following: sudo sh -c 'echo 0 > /proc/sys/kernel/randomize_va_space' – Petr Uzel Apr 26 '11 at 16:04
ok, it worked. thank you so much :) – BlackBear Apr 26 '11 at 16:14
If you're doing this 'by hand' and not in a script, then another option would be using sudoedit. It's quite convenient for setting /proc file values and there's no need to escape the echo command etc. – Erik P. Apr 26 '11 at 20:26
@Erik tee is another common way (see this post) – Michael Mrozek Apr 26 '11 at 20:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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