From 1c92691b7a84f0421db1f337820c9101754737fe Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 21 Feb 2023 14:46:41 +0000 Subject: [PATCH] Do pinsyscall() after static libc is configured for errno storage. --- lib/libc/dlfcn/init.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/libc/dlfcn/init.c b/lib/libc/dlfcn/init.c index a2d8e792160..24e7c1db3e5 100644 --- a/lib/libc/dlfcn/init.c +++ b/lib/libc/dlfcn/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.13 2023/02/21 14:41:51 deraadt Exp $ */ +/* $OpenBSD: init.c,v 1.14 2023/02/21 14:46:41 deraadt Exp $ */ /* * Copyright (c) 2014,2015 Philip Guenther * @@ -71,6 +71,12 @@ extern Elf_Ehdr __executable_start[] __attribute__((weak)); /* provide definitions for these */ const dl_cb *_dl_cb __relro = NULL; +int pinsyscall(int, void *, size_t); +PROTO_NORMAL(pinsyscall); + +int HIDDEN(execve)(const char *, char *const *, char *const *) + __attribute__((weak)); + void _libc_preinit(int, char **, char **, dl_cb_cb *) __dso_hidden; void _libc_preinit(int argc, char **argv, char **envp, dl_cb_cb *cb) @@ -135,9 +141,14 @@ _libc_preinit(int argc, char **argv, char **envp, dl_cb_cb *cb) _static_phdr_info.dlpi_phnum = phnum; /* static libc in a static link? */ - if (cb == NULL) + if (cb == NULL) { setup_static_tib(phdr, phnum); + /* XXX 128 maximum size of a system call stub, hopefully */ + if (&HIDDEN(execve)) + pinsyscall(SYS_execve, &HIDDEN(execve), 128); + } + /* * If a static binary has text relocations (DT_TEXT), then un-writeable * segments were not made immutable by the kernel. Textrel and RELRO @@ -203,12 +214,6 @@ _csu_finish(char **argv, char **envp, void (*cleanup)(void)) return &environ; } -int pinsyscall(int, void *, size_t); -PROTO_NORMAL(pinsyscall); - -int HIDDEN(execve)(const char *, char *const *, char *const *) - __attribute__((weak)); - #ifndef PIC /* * static libc in a static link? Then set up __progname and environ @@ -218,10 +223,6 @@ early_static_init(char **argv, char **envp) { static char progname_storage[NAME_MAX+1]; - /* XXX 128 maximum size of a system call stub, hopefully */ - if (&HIDDEN(execve)) - pinsyscall(SYS_execve, &HIDDEN(execve), 128); - environ = envp; /* set up __progname */ -- 2.20.1