base-linux: disable ASLR for child processes

ASLR collides with the libc's fork mechanism on 32-bit. In particular,
the tool_chain_auto.run scenario would sporadically fail while mirroring
the parent's address space.

Fixes #3710
This commit is contained in:
Norman Feske 2020-03-23 15:24:12 +01:00
parent 7a5841b637
commit d8bcaa4fa4
2 changed files with 22 additions and 0 deletions

View File

@ -101,11 +101,13 @@ inline int lx_ioctl_iomem(int fd, unsigned long phys, Genode::size_t offset)
return lx_syscall(SYS_ioctl, fd, _IOW('g', 1, void *), &range);
}
inline int lx_ioctl_irq(int fd, int irq)
{
return lx_syscall(SYS_ioctl, fd, _IOW('g', 2, int*), &irq);
}
/**************************************
** Process creation and destruction **
**************************************/
@ -161,6 +163,23 @@ inline int lx_pollpid()
}
/**
* Disable address-space layout randomization for child processes
*
* The virtual address space layout is managed by Genode, not the kernel.
* Otherwise, the libc's fork mechanism could not work on Linux.
*/
inline void lx_disable_aslr()
{
/* defined in linux/personality.h */
enum { ADDR_NO_RANDOMIZE = 0x0040000UL };
unsigned long const orig_flags = lx_syscall(SYS_personality, 0xffffffff);
(void)lx_syscall(SYS_personality, orig_flags | ADDR_NO_RANDOMIZE);
}
/********************************************
** Communication over Unix-domain sockets **
********************************************/

View File

@ -91,6 +91,9 @@ static void sigchld_handler(int)
Platform::Platform()
: _core_mem_alloc(nullptr)
{
/* make 'mmap' behave deterministically */
lx_disable_aslr();
/* catch control-c */
lx_sigaction(LX_SIGINT, sigint_handler, false);