I am using Ubuntu 12.04 32-bits, for some experiment I need to disable ASLR; how do I accomplish that? What should I do after that to enable ASLR again?
I am using Ubuntu 12.04 32-bits, for some experiment I need to disable ASLR; how do I accomplish that? What should I do after that to enable ASLR again?
According to an article How Effective is ASLR on Linux Systems?, you can configure ASLR in Linux using the
/proc/sys/kernel/randomize_va_space
interface.So, to disable it, run
and to enable it again, run
This won't survive a reboot, so you'll have to configure this in
sysctl
. Add a file/etc/sysctl.d/01-disable-aslr.conf
containing:should permanently disable this.
The
/proc/sys/kernel/randomize_va_space
interface controls ASLR system-wide.If you don't want a system-wide change, use
ADDR_NO_RANDOMIZE
personality flag to temporarily disable ASLR. Controlling of this flag can be done withsetarch
and its-R
option, likeThis will open a new Bash shell for you with ASLR disabled, including all child processes run from this shell. Just
exit
the shell once you're done.By the way, on i386,
ulimit -s unlimited
can effectively "disable" ASLR.EDIT (Apr 2016): The
ulimit -s unlimited
was fixed and assigned CVE-2016-3672.The more permanent ways of disabling ASLR should be kept in a VM for obvious reasons.
to test the ability to overwrite stack frame return addresses etcetera, you'll need to compile without stack canaries
-fno-stack-protector
, while to allow you to execute code on the stack you need to compile with-z execstack
, makingYou can use the following command to temporarily disable ASLR.
If you want to construct a program which disables ASLR for itself when it runs, you can use the
personality
system call on Linux. Here's a recipe:If you look at the source for
setarch
, it callspersonality
twice in roughly this pattern. The major difference is thatsetarch
callsexec
on some other program, whereas my recipeexec
s itself. It's important that you use non-zero-ness of& ADDR_NO_RANDOMIZE
and not equality tests: else you can go into an infiniteexec
loop if you e.g. compile with-z execstack
.See also the man page for
personality
.