Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable address space randomization for a binary on Linux?

I'm working on a runtime system for parallel programs that can take advantage of a common address space layout across multiple processes, potentially spread over several (thousand) nodes. Many times, software built for this environment is run on Linux systems that have address space randomization enabled by default, and users may not want or be able to disable it system-wide (via sysctl -w kernel.randomize_va_space=0 and the like). This imposes some limitations on the parallel programs, and can hurt performance. Thus, we want to figure out how to disable it for the binaries that we build. Security is not an issue, as this software is always running in controlled environments.

I've found references to various flags and variables, like ET_EXEC, EF_AS_NO_RANDOM (apparently never merged?) and PF_RANDOMIZE, but I can't find any document that describes what I can do to set these flags. An ideal answer would tell me what compiler/assembler/linker flag will disable randomization for the resulting binary, and what versions of the tool-chain/kernel this works on. Next best would be a tool that does the same after a binary is built.

Since I'm sure someone will suggest it, I'm already aware that we can make this change at runtime with setarch -R, but it's preferable to record this in the executable.

It looks like paxctl -rx ought to do the trick, but it doesn't seem to apply to the current method used in kernels that don't include the PaX patches.

like image 332
Phil Miller Avatar asked Sep 21 '09 18:09

Phil Miller


People also ask

Is ASLR enabled Linux?

ASLR (Address Space Layout Randomization) is a feature that is enabled by default on most Linux distributions. It is designed to improve security by loading shared memory objects at random addresses instead of fixed addresses.

How do I turn off ASLR in virtualbox?

randomize_va_space = 0 This will permanently disable ASLR.


2 Answers

Presumably you have some kind of daemon which invokes your parallel programs on the nodes. If so, you can make this common parent disable ASLR for any child processes it creates.

Look in GDB sources (7.0 or CVS Head) for how to do that. The gist of it is to call personality(orig_personality|ADDR_NO_RANDOMIZE) after fork and before exec.

like image 56
Employed Russian Avatar answered Oct 04 '22 00:10

Employed Russian


Is there some reason you can't map a shared memory space or use a named FIFO?

like image 32
greyfade Avatar answered Oct 04 '22 00:10

greyfade