@@ -64,6 +64,7 @@
#endif
char *exec_path;
+int execfd;
int singlestep;
static const char *argv0;
@@ -646,7 +647,6 @@ int main(int argc, char **argv, char **envp)
int target_argc;
int i;
int ret;
- int execfd;
unsigned long max_reserved_va;
bool preserve_argv0;
@@ -845,7 +845,12 @@ int main(int argc, char **argv, char **envp)
fd_trans_init();
- ret = loader_exec(execfd, exec_path, target_argv, target_environ, regs,
+ /*
+ * loader_exec() closes the file descriptor provided by the caller.
+ * As we need to keep it available for execve("/proc/self/exe")
+ * we provide a copy to loader_exec().
+ */
+ ret = loader_exec(dup(execfd), exec_path, target_argv, target_environ, regs,
info, &bprm);
if (ret != 0) {
printf("Error while loading %s: %s\n", exec_path, strerror(-ret));
@@ -649,6 +649,8 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \
safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \
int, options, struct rusage *, rusage)
safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp)
+safe_syscall5(int, execveat, int, dirfd, const char *, pathname, char **, \
+ argv, char **, envp, int, flags)
#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \
defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)
safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \
@@ -8843,7 +8845,12 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
* before the execve completes and makes it the other
* program's problem.
*/
- ret = get_errno(safe_execve(p, argp, envp));
+ if (is_proc_myself(p, "exe")) {
+ ret = get_errno(safe_execveat(execfd, "", argp, envp,
+ AT_EMPTY_PATH));
+ } else {
+ ret = get_errno(safe_execve(p, argp, envp));
+ }
unlock_user(p, arg1, 0);
goto execve_end;
@@ -23,6 +23,7 @@
#include "qemu/log.h"
extern char *exec_path;
+extern int execfd;
void init_task_state(TaskState *ts);
void task_settid(TaskState *);
void stop_all_tasks(void);
If path is /proc/self/exe, use the executable file descriptor provided by binfmt_misc (or opened by main()) with execveat(). Signed-off-by: Laurent Vivier <laurent@vivier.eu> --- linux-user/main.c | 9 +++++++-- linux-user/syscall.c | 9 ++++++++- linux-user/user-internals.h | 1 + 3 files changed, 16 insertions(+), 3 deletions(-)