* [PATCH] fexecve: implement in terms of execveat when it exists @ 2018-09-02 4:04 Joseph Sible 2018-09-02 17:11 ` Rich Felker 0 siblings, 1 reply; 4+ messages in thread From: Joseph Sible @ 2018-09-02 4:04 UTC (permalink / raw) To: musl This lets fexecve work even when /proc isn't mounted. --- src/process/fexecve.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/process/fexecve.c b/src/process/fexecve.c index 6507b42..905487e 100644 --- a/src/process/fexecve.c +++ b/src/process/fexecve.c @@ -1,13 +1,20 @@ +#define _GNU_SOURCE #include <unistd.h> #include <errno.h> +#include <fcntl.h> +#include "syscall.h" void __procfdname(char *, unsigned); int fexecve(int fd, char *const argv[], char *const envp[]) { +#ifdef SYS_execveat + return syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); +#else char buf[15 + 3*sizeof(int)]; __procfdname(buf, fd); execve(buf, argv, envp); if (errno == ENOENT) errno = EBADF; return -1; +#endif } -- 2.7.4 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fexecve: implement in terms of execveat when it exists 2018-09-02 4:04 [PATCH] fexecve: implement in terms of execveat when it exists Joseph Sible @ 2018-09-02 17:11 ` Rich Felker 2018-09-02 17:42 ` Joseph C. Sible 0 siblings, 1 reply; 4+ messages in thread From: Rich Felker @ 2018-09-02 17:11 UTC (permalink / raw) To: musl On Sun, Sep 02, 2018 at 12:04:55AM -0400, Joseph Sible wrote: > This lets fexecve work even when /proc isn't mounted. > --- > src/process/fexecve.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/src/process/fexecve.c b/src/process/fexecve.c > index 6507b42..905487e 100644 > --- a/src/process/fexecve.c > +++ b/src/process/fexecve.c > @@ -1,13 +1,20 @@ > +#define _GNU_SOURCE > #include <unistd.h> > #include <errno.h> > +#include <fcntl.h> > +#include "syscall.h" > > void __procfdname(char *, unsigned); > > int fexecve(int fd, char *const argv[], char *const envp[]) > { > +#ifdef SYS_execveat > + return syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > +#else > char buf[15 + 3*sizeof(int)]; > __procfdname(buf, fd); > execve(buf, argv, envp); > if (errno == ENOENT) errno = EBADF; > return -1; > +#endif > } > -- > 2.7.4 This breaks programs running on any kernel older than 3.19. Instead it needs to be something like int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); if (r!=-ENOSYS) return __syscall_ret(r); ... with no #ifdef. #ifdef SYS_anything is only valid in musl when the existence of the syscall is arch-specific. The defines come from musl itself, so trying to use it for something version-specific does not make sense; it would be unconditionally true or false. Rich ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fexecve: implement in terms of execveat when it exists 2018-09-02 17:11 ` Rich Felker @ 2018-09-02 17:42 ` Joseph C. Sible 2018-09-04 23:30 ` Rich Felker 0 siblings, 1 reply; 4+ messages in thread From: Joseph C. Sible @ 2018-09-02 17:42 UTC (permalink / raw) To: musl On Sun, Sep 2, 2018 at 1:11 PM Rich Felker <dalias@libc.org> wrote: > > On Sun, Sep 02, 2018 at 12:04:55AM -0400, Joseph Sible wrote: > > This lets fexecve work even when /proc isn't mounted. > > --- > > src/process/fexecve.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/src/process/fexecve.c b/src/process/fexecve.c > > index 6507b42..905487e 100644 > > --- a/src/process/fexecve.c > > +++ b/src/process/fexecve.c > > @@ -1,13 +1,20 @@ > > +#define _GNU_SOURCE > > #include <unistd.h> > > #include <errno.h> > > +#include <fcntl.h> > > +#include "syscall.h" > > > > void __procfdname(char *, unsigned); > > > > int fexecve(int fd, char *const argv[], char *const envp[]) > > { > > +#ifdef SYS_execveat > > + return syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > > +#else > > char buf[15 + 3*sizeof(int)]; > > __procfdname(buf, fd); > > execve(buf, argv, envp); > > if (errno == ENOENT) errno = EBADF; > > return -1; > > +#endif > > } > > -- > > 2.7.4 > > This breaks programs running on any kernel older than 3.19. > > Instead it needs to be something like > > int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > if (r!=-ENOSYS) return __syscall_ret(r); > ... > > with no #ifdef. #ifdef SYS_anything is only valid in musl when the > existence of the syscall is arch-specific. The defines come from musl > itself, so trying to use it for something version-specific does not > make sense; it would be unconditionally true or false. > > Rich Good catch. Updated patch below. -- >8 -- Subject: [PATCH v2] fexecve: implement in terms of execveat when it exists This lets fexecve work even when /proc isn't mounted. --- src/process/fexecve.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/process/fexecve.c b/src/process/fexecve.c index 6507b42..5cac05e 100644 --- a/src/process/fexecve.c +++ b/src/process/fexecve.c @@ -1,10 +1,15 @@ +#define _GNU_SOURCE #include <unistd.h> #include <errno.h> +#include <fcntl.h> +#include "syscall.h" void __procfdname(char *, unsigned); int fexecve(int fd, char *const argv[], char *const envp[]) { + int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); + if(r != -ENOSYS) return __syscall_ret(r); char buf[15 + 3*sizeof(int)]; __procfdname(buf, fd); execve(buf, argv, envp); -- 2.7.4 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fexecve: implement in terms of execveat when it exists 2018-09-02 17:42 ` Joseph C. Sible @ 2018-09-04 23:30 ` Rich Felker 0 siblings, 0 replies; 4+ messages in thread From: Rich Felker @ 2018-09-04 23:30 UTC (permalink / raw) To: musl On Sun, Sep 02, 2018 at 01:42:26PM -0400, Joseph C. Sible wrote: > On Sun, Sep 2, 2018 at 1:11 PM Rich Felker <dalias@libc.org> wrote: > > > > On Sun, Sep 02, 2018 at 12:04:55AM -0400, Joseph Sible wrote: > > > This lets fexecve work even when /proc isn't mounted. > > > --- > > > src/process/fexecve.c | 7 +++++++ > > > 1 file changed, 7 insertions(+) > > > > > > diff --git a/src/process/fexecve.c b/src/process/fexecve.c > > > index 6507b42..905487e 100644 > > > --- a/src/process/fexecve.c > > > +++ b/src/process/fexecve.c > > > @@ -1,13 +1,20 @@ > > > +#define _GNU_SOURCE > > > #include <unistd.h> > > > #include <errno.h> > > > +#include <fcntl.h> > > > +#include "syscall.h" > > > > > > void __procfdname(char *, unsigned); > > > > > > int fexecve(int fd, char *const argv[], char *const envp[]) > > > { > > > +#ifdef SYS_execveat > > > + return syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > > > +#else > > > char buf[15 + 3*sizeof(int)]; > > > __procfdname(buf, fd); > > > execve(buf, argv, envp); > > > if (errno == ENOENT) errno = EBADF; > > > return -1; > > > +#endif > > > } > > > -- > > > 2.7.4 > > > > This breaks programs running on any kernel older than 3.19. > > > > Instead it needs to be something like > > > > int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > > if (r!=-ENOSYS) return __syscall_ret(r); > > ... > > > > with no #ifdef. #ifdef SYS_anything is only valid in musl when the > > existence of the syscall is arch-specific. The defines come from musl > > itself, so trying to use it for something version-specific does not > > make sense; it would be unconditionally true or false. > > > > Rich > > Good catch. Updated patch below. > -- >8 -- > Subject: [PATCH v2] fexecve: implement in terms of execveat when it exists > > This lets fexecve work even when /proc isn't mounted. > --- > src/process/fexecve.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/src/process/fexecve.c b/src/process/fexecve.c > index 6507b42..5cac05e 100644 > --- a/src/process/fexecve.c > +++ b/src/process/fexecve.c > @@ -1,10 +1,15 @@ > +#define _GNU_SOURCE > #include <unistd.h> > #include <errno.h> > +#include <fcntl.h> > +#include "syscall.h" > > void __procfdname(char *, unsigned); > > int fexecve(int fd, char *const argv[], char *const envp[]) > { > + int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); > + if(r != -ENOSYS) return __syscall_ret(r); > char buf[15 + 3*sizeof(int)]; > __procfdname(buf, fd); > execve(buf, argv, envp); > -- > 2.7.4 Thanks, merging. In the future please send patches as attachments (preferably type text/plain if it's easy to pick) unless you're sure they'll apply correctly with git-am from the body. Rich ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-04 23:30 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-09-02 4:04 [PATCH] fexecve: implement in terms of execveat when it exists Joseph Sible 2018-09-02 17:11 ` Rich Felker 2018-09-02 17:42 ` Joseph C. Sible 2018-09-04 23:30 ` Rich Felker
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/musl/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).