git: d8e841a9aa1f - main - libc: treat execvpe as a week symbol
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 22 Apr 2025 18:12:44 UTC
The branch main has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=d8e841a9aa1f8c4ce50d98b01f1ba1376cdd9705
commit d8e841a9aa1f8c4ce50d98b01f1ba1376cdd9705
Author: SHENGYI HONG <aokblast@FreeBSD.org>
AuthorDate: 2025-04-02 20:35:13 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-04-22 18:12:26 +0000
libc: treat execvpe as a week symbol
Some program intercepts the execvpe call in runtime. At the same time, the
implementation of posix_spwan use execvpe. If execvpe is intercepted and
then calls posix_spawn when intercepted. It wil create a infinite loop
because the intercepted execvpe will spawn a posix_spwan call and will be
intercepted again.
See https://github.com/rizsotto/Bear/issues/557 for reference.
Reviewed by: brooks, kib, emaste
Sponsored by: FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49733
---
lib/libc/gen/exec.c | 6 ++++--
lib/libc/gen/posix_spawn.c | 2 +-
lib/libc/include/libc_private.h | 1 +
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c
index d9285733e965..926c50d64852 100644
--- a/lib/libc/gen/exec.c
+++ b/lib/libc/gen/exec.c
@@ -136,7 +136,7 @@ execv(const char *name, char * const *argv)
int
execvp(const char *name, char * const *argv)
{
- return (execvpe(name, argv, environ));
+ return (__libc_execvpe(name, argv, environ));
}
static int
@@ -288,7 +288,7 @@ execvP(const char *name, const char *path, char * const argv[])
}
int
-execvpe(const char *name, char * const argv[], char * const envp[])
+__libc_execvpe(const char *name, char * const argv[], char * const envp[])
{
const char *path;
@@ -298,3 +298,5 @@ execvpe(const char *name, char * const argv[], char * const envp[])
return (execvPe(name, path, argv, envp));
}
+
+__weak_reference(__libc_execvpe, execvpe);
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
index ee2ce05ff317..a5b732696b8c 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -261,7 +261,7 @@ _posix_spawn_thr(void *data)
}
envp = psa->envp != NULL ? psa->envp : environ;
if (psa->use_env_path)
- execvpe(psa->path, psa->argv, envp);
+ __libc_execvpe(psa->path, psa->argv, envp);
else
_execve(psa->path, psa->argv, envp);
psa->error = errno;
diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h
index 4c244f962b2b..41b44456b6ee 100644
--- a/lib/libc/include/libc_private.h
+++ b/lib/libc/include/libc_private.h
@@ -345,6 +345,7 @@ struct __ucontext;
struct __wrusage;
enum idtype;
+int __libc_execvpe(const char *, char * const *, char * const *);
int __libc_sigaction(int, const struct sigaction *,
struct sigaction *) __hidden;
int __libc_sigprocmask(int, const __sigset_t *, __sigset_t *)