@@ -2600,6 +2600,7 @@ static bool parse_elf_properties(int image_fd,
IMAGE_NAME is the filename of the image, to use in error messages.
IMAGE_FD is the open file descriptor for the image.
+ WARNING: IMAGE_FD won't be closed.
BPRM_BUF is a copy of the beginning of the file; this of course
contains the elf file header at offset 0. It is assumed that this
@@ -2910,7 +2911,6 @@ static void load_elf_image(const char *image_name, int image_fd,
mmap_unlock();
- close(image_fd);
return;
exit_read:
@@ -2953,6 +2953,7 @@ static void load_elf_interp(const char *filename, struct image_info *info,
}
load_elf_image(filename, fd, info, NULL, bprm_buf);
+ close(fd);
}
static int symfind(const void *s0, const void *s1)
@@ -28,6 +28,8 @@ extern void __gcov_dump(void);
void preexit_cleanup(CPUArchState *env, int code)
{
+ close(execfd);
+
#ifdef CONFIG_GPROF
_mcleanup();
#endif
@@ -50,6 +50,7 @@
#include "crypto/init.h"
char *exec_path;
+int execfd;
int singlestep;
static const char *argv0;
@@ -628,7 +629,6 @@ int main(int argc, char **argv, char **envp)
int target_argc;
int i;
int ret;
- int execfd;
int log_mask;
unsigned long max_reserved_va;
@@ -160,6 +160,7 @@ typedef struct TaskState {
} __attribute__((aligned(16))) TaskState;
extern char *exec_path;
+extern int execfd;
void init_task_state(TaskState *ts);
void task_settid(TaskState *);
void stop_all_tasks(void);
@@ -8110,8 +8110,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
};
if (is_proc_myself(pathname, "exe")) {
- int execfd = qemu_getauxval(AT_EXECFD);
- return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode);
+ return execfd;
}
for (fake_open = fakes; fake_open->filename; fake_open++) {
@@ -8369,8 +8368,17 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
return ret;
#endif
case TARGET_NR_close:
- fd_trans_unregister(arg1);
- return get_errno(close(arg1));
+ {
+ int fd = arg1;
+
+ /* We don't need to close execfd, it will be closed on QEMU exit. */
+ if (fd == execfd) {
+ return 0;
+ }
+
+ fd_trans_unregister(fd);
+ return get_errno(close(fd));
+ }
case TARGET_NR_brk:
return do_brk(arg1);
From: Andrew Aladjev <aladjev.andrew@gmail.com> User opens /proc/self/exe symlink, than kernel should create /proc/self/fd/<execfd> symlink. We should be able to detect both exe and fd/<execfd> symlinks to provide common behaviour. The easiest solution is to make execfd global and keep it open. This solution looks acceptable because exec_path is already global. PS load_flt_binary is not closing bprm->fd, so load_elf_binary may not close it too (used symmetrically in loader_exec). --- linux-user/elfload.c | 3 ++- linux-user/exit.c | 2 ++ linux-user/main.c | 2 +- linux-user/qemu.h | 1 + linux-user/syscall.c | 16 ++++++++++++---- 5 files changed, 18 insertions(+), 6 deletions(-)