From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13171 Path: news.gmane.org!.POSTED!not-for-mail From: "Joseph C. Sible" Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fexecve: implement in terms of execveat when it exists Date: Sun, 2 Sep 2018 13:42:26 -0400 Message-ID: References: <20180902171124.GW1878@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1535910038 8501 195.159.176.226 (2 Sep 2018 17:40:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Sep 2018 17:40:38 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-13187-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 02 19:40:34 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fwWMU-00028X-0v for gllmg-musl@m.gmane.org; Sun, 02 Sep 2018 19:40:34 +0200 Original-Received: (qmail 23647 invoked by uid 550); 2 Sep 2018 17:42:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 23622 invoked from network); 2 Sep 2018 17:42:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=3NwDC+kCtbXXXGyYttSuCA/8W4oUkC9NGL4OR0hzTic=; b=CYt2GikyFRYfasCHObnJm0dICdOxlowf3l5Pe/ruhVSJV4WkMkvxRzgWB8A6TXXE8V oegESl+ahBrIxLt7jB0rc7mje6GxjgJIVvDAPmEapuwtxeMyO5WQZq+hFnpYHDGXMeQQ 48KLtSGI0BFgstWDLs+8lorxX6AegIlf6QvVO8+4aQDITec4UVWMFBFj1bCUVg0TvpD4 T75gmPvompTRd355myRDOHhfCFavCfr+UXTKLQTzQdkR7BMXrx6Qz2zoPtmKEIp8Zl/y 6Dc+gFDeHFMP/uHNlLkFq3jK+OW27hTQJgEsmR1c2T4wPAzGkTCUFxx7/M1zSqWEodxM Fbag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=3NwDC+kCtbXXXGyYttSuCA/8W4oUkC9NGL4OR0hzTic=; b=shP2rs9UF3OCEqXi5ucHVerLv1CXOs2r6zalfTPeSAfdkfOVVBF/x46GzzjmhUG+ca WgRxACr5ABVhnX141VtyCqriwv4iuQ/7rsgRP7AFf30Y+LQyhrx+uB5/1NfA5Wwk7wTv FwLAUgBztcL9O/Ty7FaqwG5mFV2rJIKhq8aW6TQ8nXiiXwpN/usXt5++F8g4sgfAjIph G6/yL6ZPA4zcc3lqnp1qw4P9NI2Ns+1EFHe9+h1yarg90tWM8xqCxA3G8Kq2Dqr8Q/jV S+/PdfveaxBIi0EfHKl+Y4MPmxYsi4i9moFxPcQ8mgUctKlDlcLVjvNNuUvQEVkGnjju QMhQ== X-Gm-Message-State: APzg51BMUt4xqqeMpaFfHHB4wHicYG6AwYpSCxghLfhIruOaUz7p2OPJ ML+y9ykAcxggh8Di6FDvE6HK7+fll5NIxXGvEGUDCVW2 X-Google-Smtp-Source: ANB0VdaHWdobFI9q5oFCKPr2rK7aIl+XRwtDBS/iD5iGps+ZQYkfXNLezOCWvuubHOC1PandWWMNYiYXL5ggcRkACFE= X-Received: by 2002:a0c:d788:: with SMTP id z8-v6mr23384196qvi.71.1535910147587; Sun, 02 Sep 2018 10:42:27 -0700 (PDT) In-Reply-To: <20180902171124.GW1878@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:13171 Archived-At: On Sun, Sep 2, 2018 at 1:11 PM Rich Felker 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 > > #include > > +#include > > +#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 #include +#include +#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