Skip to content

Commit

Permalink
dso, execve{,at}, posix_spawn: do not run OpenBSD dynamic loader
Browse files Browse the repository at this point in the history
The ELF dynamic loader in OpenBSD is not executable.

	-bash-5.2$ ls -l /usr/libexec/ld.so
	-r--r--r--  1 root  bin  359016 Oct  8 19:57 /usr/libexec/ld.so

This conditionizes the code to run the dynamic loader if not OpenBSD.
  • Loading branch information
gportay committed Oct 9, 2024
1 parent fa5e6aa commit 697bbd1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion dso.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ static int __fld_needed(int fd,
return __path_iterate(needed, __ld_needed_callback, &ctx);
}

#ifndef __OpenBSD__
static int __ld_needed(const char *path,
const char *rpath,
const char *ld_library_path,
Expand All @@ -721,6 +722,7 @@ static int __ld_needed(const char *path,

return ret;
}
#endif

struct __ld_open_needed_context {
int flags;
Expand Down Expand Up @@ -3538,7 +3540,7 @@ hidden ssize_t __dl_access(const char *path, int mode, char *buf,
bufsiz);
}

#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
static const char *__root_basepath(const char *path)
{
const char *root;
Expand Down
4 changes: 2 additions & 2 deletions execve.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

extern int next_faccessat(int, const char *, int, int);

#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
extern int __ldso_execve(const char *, char * const[], char * const[]);
#endif

Expand Down Expand Up @@ -207,7 +207,7 @@ int execve(const char *path, char * const argv[], char * const envp[])
off += siz+1; /* NULL-terminated */

loader:
#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
/* It is the dynamic loader */
ret = __is_ldso(__basename(path));
/* Try to run the dynamic loader internaly... */
Expand Down
4 changes: 2 additions & 2 deletions execveat.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "iamroot.h"

#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
extern int __ldso_execveat(int, const char *, char * const[], char * const[]);
#endif

Expand Down Expand Up @@ -146,7 +146,7 @@ int execveat(int dfd, const char *path, char * const argv[],
off += siz+1; /* NULL-terminated */

loader:
#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
/* It is the dynamic loader */
ret = __is_ldso(__basename(path));
/* Try to run the dynamic loader internaly... */
Expand Down
4 changes: 2 additions & 2 deletions posix_spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "iamroot.h"

#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
extern int __ldso_posix_spawn(pid_t *,
const char *,
const posix_spawn_file_actions_t *,
Expand Down Expand Up @@ -159,7 +159,7 @@ int posix_spawn(pid_t *pid, const char *path,
off += siz+1; /* NULL-terminated */

loader:
#ifndef __NetBSD__
#if !defined __NetBSD__ && !defined __OpenBSD__
/* It is the dynamic loader */
ret = __is_ldso(__basename(path));
/* Try to run the dynamic loader internaly... */
Expand Down

0 comments on commit 697bbd1

Please sign in to comment.