Message ID | 20220927124357.688536-1-laurent@vivier.eu (mailing list archive) |
---|---|
Headers | show |
Series | linux-user: handle /proc/self/exe with execve() syscall | expand |
27.09.2022 15:43, Laurent Vivier wrote: > Use exec_path to re-execute the binary from /proc/self/exe > > Fix do_openat() that should not use execfd. > > v2: > - don't use execfd as it can't be closed and is usable by the child Why can't it be closed? I mean, how about O_CLOEXEC? Your initial usage of execveat() seemed very elegant. Thanks, /mjt
Le 26/10/2022 à 17:25, Michael Tokarev a écrit : > 27.09.2022 15:43, Laurent Vivier wrote: >> Use exec_path to re-execute the binary from /proc/self/exe >> >> Fix do_openat() that should not use execfd. >> >> v2: >> - don't use execfd as it can't be closed and is usable by the child > > Why can't it be closed? I mean, how about O_CLOEXEC? I tried O_CLOEXEC, but it seems the fd is closed before it is needed by execveat() to re-spawn the process, so it exits with an error (something like EBADF) Thanks, Laurent
27.10.2022 09:40, Laurent Vivier wrote: .. > I tried O_CLOEXEC, but it seems the fd is closed before it is needed by execveat() to re-spawn the process, so it exits with an error (something like > EBADF) It works here for me with a simple test program: #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <sys/syscall.h> #define AT_EMPTY_PATH 0x1000 static char *argv[] = { "ls", NULL }; static char *envp[] = { NULL }; int main(void) { int fd = open("/usr/bin/ls", O_RDONLY); fcntl(fd, F_SETFD, O_CLOEXEC); //execveat(fd, "", argv, envp, AT_EMPTY_PATH); syscall(__NR_execveat, fd, "", argv, envp, AT_EMPTY_PATH); return 0; } /mjt
27.10.2022 13:42, Michael Tokarev wrote: > 27.10.2022 09:40, Laurent Vivier wrote: > .. >> I tried O_CLOEXEC, but it seems the fd is closed before it is needed by execveat() to re-spawn the process, so it exits with an error (something >> like EBADF) > > It works here for me with a simple test program: > > #include <sys/types.h> > #include <fcntl.h> > #include <unistd.h> > #include <sys/syscall.h> > #define AT_EMPTY_PATH 0x1000 > > static char *argv[] = { "ls", NULL }; > static char *envp[] = { NULL }; > > int main(void) { > int fd = open("/usr/bin/ls", O_RDONLY); > fcntl(fd, F_SETFD, O_CLOEXEC); > //execveat(fd, "", argv, envp, AT_EMPTY_PATH); > syscall(__NR_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > return 0; > } But for some reason it does not close this fd# on exec. static char *argv[] = { "ls", "-l", "/proc/self/fd", NULL }; shows this. Hmm. Ok. Let's keep it the way you did :) /mjt