Static non-PIE binaries always have a base address of 0 (even if the ELF
authorkettenis <kettenis@openbsd.org>
Sun, 21 Jan 2024 17:18:13 +0000 (17:18 +0000)
committerkettenis <kettenis@openbsd.org>
Sun, 21 Jan 2024 17:18:13 +0000 (17:18 +0000)
headers start at a higher address).  Using the wrong base address meant
that we were protecting the wrong address range for the malloc internals
which made the code error out now that mimmutable(2) no longer allows an
RW->R transition.  Issue found by gkoehler@ who got most of the way
towards a proper fix.

ok deraadt@

lib/libc/dlfcn/init.c

index dd38ba9..9fc63c9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: init.c,v 1.21 2024/01/19 14:15:51 deraadt Exp $ */
+/*     $OpenBSD: init.c,v 1.22 2024/01/21 17:18:13 kettenis Exp $ */
 /*
  * Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org>
  *
@@ -129,7 +129,6 @@ _libc_preinit(int argc, char **argv, char **envp, dl_cb_cb *cb)
                 * Static non-PIE processes don't get an AUX vector,
                 * so find the phdrs through the ELF header
                 */
-               _static_phdr_info.dlpi_addr = (Elf_Addr)__executable_start;
                phdr = (void *)((char *)__executable_start +
                    __executable_start->e_phoff);
                phnum = __executable_start->e_phnum;