From: deraadt Date: Tue, 21 Feb 2023 14:41:51 +0000 (+0000) Subject: In static binaries, if WEAK execve can be found, use pinsyscall(2) to X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=69954aaa4dddacf54b4462afbd60790191142b89;p=openbsd In static binaries, if WEAK execve can be found, use pinsyscall(2) to tell the kernel where the execve stub is found. With this mechanism we cannot tell the size, so use 128 as an estimate for the most we expect from any architecture. discussed with kettenis, ok guenther --- diff --git a/lib/libc/dlfcn/init.c b/lib/libc/dlfcn/init.c index 48c062cef55..a2d8e792160 100644 --- a/lib/libc/dlfcn/init.c +++ b/lib/libc/dlfcn/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.12 2023/01/16 07:09:12 guenther Exp $ */ +/* $OpenBSD: init.c,v 1.13 2023/02/21 14:41:51 deraadt Exp $ */ /* * Copyright (c) 2014,2015 Philip Guenther * @@ -203,6 +203,12 @@ _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 @@ -212,6 +218,10 @@ 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 */