From f75f199947552b24ef3c6d8e8169f4d1acdd00d7 Mon Sep 17 00:00:00 2001 From: Christian Helmuth Date: Wed, 9 Nov 2016 17:10:34 +0100 Subject: [PATCH] ldso: initialize ELF object before relocating This fixes a regression on Ubuntu 16.04 (resp. Linux systems with recent kernel versions) and address-space randomization originating from an uninitialized relocation base of 0. --- repos/base/src/lib/ldso/main.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index 296f22331f..e7e8741f69 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -91,6 +91,13 @@ class Linker::Elf_object : public Object, public Fifo::Element */ Lazy_volatile_object _elf_file; + + bool _object_init(Object::Name const &name, Elf::Addr reloc_base) + { + Object::init(name, reloc_base); + return true; + } + bool _init_elf_file(Env &env, Allocator &md_alloc, char const *path) { _elf_file.construct(env, md_alloc, Linker::file(path), true); @@ -98,7 +105,7 @@ class Linker::Elf_object : public Object, public Fifo::Element return true; } - bool const _elf_file_initialized; + bool const _elf_object_initialized; Dynamic _dyn; @@ -107,16 +114,15 @@ class Linker::Elf_object : public Object, public Fifo::Element Elf_object(Dependency const &dep, Object::Name const &name, Elf::Addr reloc_base) : - _elf_file_initialized(false), _dyn(dep) - { - Object::init(name, reloc_base); - } + _elf_object_initialized(_object_init(name, reloc_base)), + _dyn(dep) + { } Elf_object(Env &env, Allocator &md_alloc, char const *path, Dependency const &dep, Keep keep) : _keep(keep), - _elf_file_initialized(_init_elf_file(env, md_alloc, path)), + _elf_object_initialized(_init_elf_file(env, md_alloc, path)), _dyn(md_alloc, dep, *this, &_elf_file->phdr) { /* register for static construction and relocation */