From d8bcaa4fa414160cf95b807cad2a8940340ba494 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 23 Mar 2020 15:24:12 +0100 Subject: [PATCH] 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 --- .../src/core/include/core_linux_syscalls.h | 19 +++++++++++++++++++ repos/base-linux/src/core/platform.cc | 3 +++ 2 files changed, 22 insertions(+) diff --git a/repos/base-linux/src/core/include/core_linux_syscalls.h b/repos/base-linux/src/core/include/core_linux_syscalls.h index 7e13ed603..c3bd08514 100644 --- a/repos/base-linux/src/core/include/core_linux_syscalls.h +++ b/repos/base-linux/src/core/include/core_linux_syscalls.h @@ -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 ** ********************************************/ diff --git a/repos/base-linux/src/core/platform.cc b/repos/base-linux/src/core/platform.cc index ea8fe69d6..927baf19c 100644 --- a/repos/base-linux/src/core/platform.cc +++ b/repos/base-linux/src/core/platform.cc @@ -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);