From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id B9E63385702C for ; Fri, 26 Mar 2021 20:36:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B9E63385702C Received: by mail-qk1-x733.google.com with SMTP id 7so6587635qka.7 for ; Fri, 26 Mar 2021 13:36:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cGVJm7wMR94sozj6FgK1ANPCOTwbyi7zwZ2lh6H87Ho=; b=gAHACyuKOT+M3sZm5yU1eoDqUBM6nTH/NLDw9UIdWRuVi9RQjmOcSgzSXTfosOAwsy GSJNDEtzw30ifvzQiqoa/MmCCJ9KV1D72Mh9OVpZYchoWB1t/+8rcewChB5oz/qBdK1D EDYwt+5awjQzoDdBq7UBS57kczDnYJOtupHz0nojo1a8ufY/iBAyTQf9VBvDPUHM2qMa p+1Zc+di7KT3QrKR5UmeA3RDR3QerJpEcItZy84aOtI+ljXmS8phd8AJlDOing4FyfeB eNbt5kWW8/RF5W+9mHFWXiNfg2l2AKq1cbVA40Xi11oQxiO/jN/wX1kGuwk1tcPf951L pYSg== X-Gm-Message-State: AOAM5314Izt64JMTQLO4d90oDWjFAKvDFhQduaUUjFchTu4K2/nqiTJP htLGX43uEbPoVjzyGpEYT1zhkQ== X-Google-Smtp-Source: ABdhPJyksOwYaUQt9mvYxbUWihM6+MwsbOgUN10xmSNFq1aOIWziuo2mXjOYg9GY0BXdI9cITzQPZQ== X-Received: by 2002:a37:7e87:: with SMTP id z129mr15545578qkc.243.1616790990919; Fri, 26 Mar 2021 13:36:30 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id l12sm6206044qtx.77.2021.03.26.13.36.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Mar 2021 13:36:30 -0700 (PDT) Subject: Re: [PATCH] Linux: Add execveat system call wrapper To: libc-alpha@sourceware.org, =?UTF-8?Q?Alexandra_H=c3=a1jkov=c3=a1?= References: <20200428122019.26826-1-ahajkova@redhat.com> <20210324135402.2685623-1-ahajkova@redhat.com> From: Adhemerval Zanella Message-ID: Date: Fri, 26 Mar 2021 17:36:28 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210324135402.2685623-1-ahajkova@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Mar 2021 20:36:35 -0000 On 24/03/2021 10:54, Alexandra Hájková via Libc-alpha wrote: > From: Alexandra Hájková > > Also add the test for the new wrapper. > --- > This version: > * was updated to use 2.24 symbol version > * "difrd < 0" check was dropped Patch looks in general, some comments below. > > NEWS | 5 + > include/unistd.h | 4 + > posix/Makefile | 4 +- > posix/Versions | 3 + > posix/execveat.c | 41 ++++ > posix/tst-execveat-compat.c | 32 ++++ > posix/tst-execveat.c | 180 ++++++++++++++++++ > posix/unistd.h | 5 + > sysdeps/mach/hurd/i386/libc.abilist | 1 + > sysdeps/unix/sysv/linux/aarch64/libc.abilist | 1 + > sysdeps/unix/sysv/linux/alpha/libc.abilist | 1 + > sysdeps/unix/sysv/linux/arm/be/libc.abilist | 1 + > sysdeps/unix/sysv/linux/arm/le/libc.abilist | 1 + > sysdeps/unix/sysv/linux/csky/libc.abilist | 1 + > sysdeps/unix/sysv/linux/execveat.c | 54 ++++++ > sysdeps/unix/sysv/linux/execveat_fallback.c | 69 +++++++ > sysdeps/unix/sysv/linux/hppa/libc.abilist | 1 + > sysdeps/unix/sysv/linux/i386/libc.abilist | 1 + > sysdeps/unix/sysv/linux/ia64/libc.abilist | 1 + > .../sysv/linux/m68k/coldfire/libc.abilist | 1 + > .../unix/sysv/linux/m68k/m680x0/libc.abilist | 1 + > .../sysv/linux/microblaze/be/libc.abilist | 1 + > .../sysv/linux/microblaze/le/libc.abilist | 1 + > .../sysv/linux/mips/mips32/fpu/libc.abilist | 1 + > .../sysv/linux/mips/mips32/nofpu/libc.abilist | 1 + > .../sysv/linux/mips/mips64/n32/libc.abilist | 1 + > .../sysv/linux/mips/mips64/n64/libc.abilist | 1 + > sysdeps/unix/sysv/linux/nios2/libc.abilist | 1 + > .../linux/powerpc/powerpc32/fpu/libc.abilist | 1 + > .../powerpc/powerpc32/nofpu/libc.abilist | 1 + > .../linux/powerpc/powerpc64/be/libc.abilist | 1 + > .../linux/powerpc/powerpc64/le/libc.abilist | 1 + > .../unix/sysv/linux/riscv/rv64/libc.abilist | 1 + > .../unix/sysv/linux/s390/s390-32/libc.abilist | 1 + > .../unix/sysv/linux/s390/s390-64/libc.abilist | 1 + > sysdeps/unix/sysv/linux/sh/be/libc.abilist | 1 + > sysdeps/unix/sysv/linux/sh/le/libc.abilist | 1 + > .../sysv/linux/sparc/sparc32/libc.abilist | 1 + > .../sysv/linux/sparc/sparc64/libc.abilist | 1 + > .../unix/sysv/linux/x86_64/64/libc.abilist | 1 + > .../unix/sysv/linux/x86_64/x32/libc.abilist | 1 + > 41 files changed, 427 insertions(+), 1 deletion(-) > create mode 100644 posix/execveat.c > create mode 100644 posix/tst-execveat-compat.c > create mode 100644 posix/tst-execveat.c > create mode 100644 sysdeps/unix/sysv/linux/execveat.c > create mode 100644 sysdeps/unix/sysv/linux/execveat_fallback.c > > diff --git a/NEWS b/NEWS > index aa0f10a891..a61071b494 100644 > --- a/NEWS > +++ b/NEWS > @@ -18,6 +18,11 @@ Major new features: > a dump of information related to IFUNC resolver operation and > glibc-hwcaps subdirectory selection. > > +* The function execveat has been added and it operates similar to execve. > + The syscall is already used to implement fexecve without requiring /proc to > + be mounted. Similar to fexecve, if the syscall is not supported a fallback > + which access /proc is used. > + > Deprecated and removed features, and other changes affecting compatibility: > > [Add deprecations, removals and changes affecting compatibility here] Ok. > diff --git a/include/unistd.h b/include/unistd.h > index 54becbc9eb..2dd901ed09 100644 > --- a/include/unistd.h > +++ b/include/unistd.h > @@ -192,6 +192,10 @@ extern int __libc_pause (void); > extern int __getlogin_r_loginuid (char *name, size_t namesize) > attribute_hidden; > > +extern int > +__execveat_fallback (int dirfd, const char *path, char *const argv[], > + char *const envp[], int flags); Add attribute_hidden since it is an internal function. But I think this is not really required, since you include the fallback file directly on both the testcase and the execveat.c (so there is no need of forward declaration). > + > # if IS_IN (rtld) > # include > # endif > diff --git a/posix/Makefile b/posix/Makefile > index be0c72f0bb..f0ebe34c8e 100644 > --- a/posix/Makefile > +++ b/posix/Makefile > @@ -66,7 +66,8 @@ routines := \ > posix_madvise \ > get_child_max sched_cpucount sched_cpualloc sched_cpufree \ > streams-compat \ > - shm-directory > + shm-directory \ > + execveat > > aux := init-posix environ > tests := test-errno tstgetopt testfnm runtests runptests \ Ok. > @@ -118,6 +119,7 @@ endif > > tests-internal := bug-regex5 bug-regex20 bug-regex33 \ > tst-rfc3484 tst-rfc3484-2 tst-rfc3484-3 > +tests-static-internal += tst-execveat-compat > tests-container := bug-ga2 > xtests := tst-getaddrinfo4 tst-getaddrinfo5 tst-sched_rr_get_interval > ifeq (yes,$(build-shared)) Ok. > diff --git a/posix/Versions b/posix/Versions > index cfd3819966..b77e251e00 100644 > --- a/posix/Versions > +++ b/posix/Versions > @@ -147,6 +147,9 @@ libc { > } > GLIBC_2.30 { > } > + GLIBC_2.34 { > + execveat; > + } > GLIBC_PRIVATE { > __libc_fork; __libc_pread; __libc_pwrite; > __nanosleep_nocancel; __pause_nocancel; Ok. > diff --git a/posix/execveat.c b/posix/execveat.c > new file mode 100644 > index 0000000000..3f0d0820e7 > --- /dev/null > +++ b/posix/execveat.c > @@ -0,0 +1,41 @@ > +/* Execute program relative to a directory file descriptor. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > + > +/* Replace the current process, executing PATH relative to DIFRD with > + * arguments ARGV and environment ENVP. > + * ARGV and ENVP are terminated by NULL pointers. */ > +int > +__execveat (int dirfd, const char *path, char *const argv[], char *const envp[], > + int flags) > +{ > + if (path == NULL || argv == NULL || envp == NULL) > + { > + __set_errno (EINVAL); > + return -1; > + } > + > + __set_errno (ENOSYS); > + return -1; > +} > +stub_warning (execveat) > + > +weak_alias (__execveat, execveat) Ok. > diff --git a/posix/tst-execveat-compat.c b/posix/tst-execveat-compat.c > new file mode 100644 > index 0000000000..082c67690d > --- /dev/null > +++ b/posix/tst-execveat-compat.c > @@ -0,0 +1,32 @@ > +/* Test the fallback implementation of execveat. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +/* Get the declaration of the official execveat function. */ > +#include > + > +/* Compile a local version of execveat. */ > +#include > + > +int > +__execveat_fallback (int dirfd, const char *path, char *const argv[], > + char *const envp[], int flags); Same as before, the protype declaration here is not required. > + > +/* Re-use the test, but run it against copy_file_range_compat defined > + above. */ > +#define execveat execveat_fallback > +#include "tst-execveat.c" Move this test to be Linux-only, since the fallback is only defined for Linux. > diff --git a/posix/tst-execveat.c b/posix/tst-execveat.c > new file mode 100644 > index 0000000000..52779de8cd > --- /dev/null > +++ b/posix/tst-execveat.c > @@ -0,0 +1,180 @@ > +/* Test execveat at the various corner cases. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +int > +call_execveat (int fd, const char *pathname, int flags, int expected_fail, > + int num) > +{ > + char *envp[] = { (char *) "FOO=3", NULL }; > + char *argv[] = { (char *) "sh", (char *) "-c", (char *) "exit $FOO", NULL }; > + pid_t pid; > + int status; > + > + if (test_verbose > 0) > + printf ("call line number: %d\n", num); > + > + pid = xfork (); > + if (pid == 0) > + { > + TEST_COMPARE (execveat (fd, pathname, argv, envp, flags), -1); > + if (errno == ENOSYS) > + FAIL_UNSUPPORTED ("execveat is unimplemented"); > + else if (errno == expected_fail) > + { > + if (test_verbose > 0) > + printf ("expected fail: errno %d\n", errno); > + _exit (0); > + } > + else > + FAIL_EXIT1 ("execveat failed: %m (%d)", errno); > + } > + xwaitpid (pid, &status, 0); > + > + if (WIFEXITED (status)) > + { > + if (WEXITSTATUS (status) == EXIT_UNSUPPORTED) > + FAIL_UNSUPPORTED ("execveat is unimplemented"); > + else if (expected_fail != 0) > + TEST_COMPARE (WEXITSTATUS (status), 0); > + else > + TEST_COMPARE (WEXITSTATUS (status), 3); > + } Also log a failure for !WIFEXITED (status). > + return 0; > +}> + > +static int > +do_test (void) > +{ > + DIR *dirp; > + int fd, fd_out; > + char *tmp_dir, *symlink_name, *tmp_sh; > + struct stat64 st; > + > + dirp = opendir ("/bin"); > + if (dirp == NULL) > + FAIL_EXIT1 ("failed to open /bin"); > + fd = dirfd (dirp); > + > + /* Call execveat for various fd/pathname combinations. */ > + > + /* Check the pathname relative to a valid dirfd. */ > + call_execveat (fd, "sh", 0, 0, __LINE__); > + xchdir ("/bin"); > + /* Use the special value AT_FDCWD as dirfd. Quoting open(2): > + If pathname is relative and dirfd is the special value AT_FDCWD, then > + pathname is interpreted relative to the current working directory of > + the calling process. */ > + call_execveat (AT_FDCWD, "sh", 0, 0, __LINE__); > + xclose (fd); Ok. > +#ifdef O_PATH > + /* Check the pathname relative to a valid dirfd with O_PATH. */ > + fd = xopen ("/bin", O_PATH | O_DIRECTORY, O_RDONLY); > + call_execveat (fd, "sh", 0, 0, __LINE__); > + xclose (fd); > + > + /* Check absolute pathname, dirfd should be ignored. */ > + call_execveat (AT_FDCWD, "/bin/sh", 0, 0, __LINE__); > + fd = xopen ("/usr", O_PATH | O_DIRECTORY, 0); > + /* Same check for absolute pathname, but with input file descriptor > + openend with different flags. The dirfd should be ignored. */ > + call_execveat (fd, "/bin/sh", 0, 0, __LINE__); > + xclose (fd); Ok. > +#endif > + > + fd = xopen ("/usr", O_RDONLY, 0); > + /* Same check for absolute pathname, but with input file descriptor > + openend with different flags. The dirfd should be ignored. */ > + call_execveat (fd, "/bin/sh", 0, 0, __LINE__); > + xclose (fd); > + Ok. > + fd = xopen ("/bin/sh", O_RDONLY, 0); > + /* Check relative pathname, where dirfd does not point to a directory. */ > + call_execveat (fd, "sh", 0, ENOTDIR, __LINE__); > + /* Check absolute pathname, but dirfd is a regular file. The dirfd > + should be ignored. */ > + call_execveat (fd, "/bin/sh", 0, 0, __LINE__); > + xclose (fd); > + Ok. > +#ifdef O_PATH > + /* Quoting open(2): O_PATH > + Obtain a file descriptor that can be used for two purposes: to > + indicate a location in the filesystem tree and to perform > + operations that act purely at the file descriptor level. */ > + fd = xopen ("/bin/sh", O_PATH, 0); > + /* Check the empty pathname. Dirfd is a regular file with O_PATH. */ > + call_execveat (fd, "", 0, ENOENT, __LINE__); Ok. > + /* Same check for an empty pathname, but with AT_EMPTY_PATH flag. > + Quoting open(2): > + If oldpath is an empty string, create a link to the file referenced > + by olddirfd (which may have been obtained using the open(2) O_PATH flag. */ > + call_execveat (fd, "", AT_EMPTY_PATH, 0, __LINE__); > + call_execveat (fd, "", AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW, 0, __LINE__); > + xclose (fd); > + Ok. > + /* Create a temporary directory "tmp_dir" and create a symbolik link tmp_sh > + pointing to /bin/sh inside the tmp_dir. Open dirfd as a symbolic link. */ Missing double space after period. > + tmp_dir = support_create_temp_directory ("tst-execveat_dir"); > + symlink_name = xasprintf ("%s/symlink", tmp_dir); > + xsymlink ("tmp_sh", symlink_name); > + add_temp_file (symlink_name); > + tmp_sh = xasprintf ("%s/tmp_sh", tmp_dir); > + add_temp_file (tmp_sh); > + fd_out = xopen (symlink_name, O_CREAT | O_WRONLY, 0); > + xstat ("/bin/sh", &st); > + fd = xopen ("/bin/sh", O_RDONLY, 0); > + xcopy_file_range (fd, 0, fd_out, 0, st.st_size, 0); > + xfchmod (fd_out, 0700); > + xclose (fd); > + xclose (fd_out); > + fd_out = xopen (symlink_name, O_PATH, 0); > + > + /* Check the empty pathname. Dirfd is a symbolic link. */ > + call_execveat (fd_out, "", 0, ENOENT, __LINE__); > + call_execveat (fd_out, "", AT_EMPTY_PATH, 0, __LINE__); > + call_execveat (fd_out, "", AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW, 0, > + __LINE__); > + xclose (fd_out); > + free (symlink_name); > + free (tmp_sh); > + free (tmp_dir); Ok. > +#endif > + > + /* Call execveat with closed fd, we expect this to fail with EBADF. */ > + call_execveat (fd, "sh", 0, EBADF, __LINE__); > + /* Call execveat with closed fd, we expect this to pass because the pathname is > + absolute. */ > + call_execveat (fd, "/bin/sh", 0, 0, __LINE__); > + > + return 0; > +} > + > +#include Ok. > diff --git a/posix/unistd.h b/posix/unistd.h > index 3f22763379..d9d8929f71 100644 > --- a/posix/unistd.h > +++ b/posix/unistd.h > @@ -295,6 +295,11 @@ extern int euidaccess (const char *__name, int __type) > /* An alias for `euidaccess', used by some other systems. */ > extern int eaccess (const char *__name, int __type) > __THROW __nonnull ((1)); > + > +/* Execute program relative to a directory file descriptor. */ > +extern int execveat (int __fd, const char *__path, char *const __argv[], > + char *const __envp[], int __flags) > + __THROW __nonnull ((2, 3)); > #endif > > #ifdef __USE_ATFILE Ok. > diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist > index e10a286d2e..bef66d105c 100644 > --- a/sysdeps/mach/hurd/i386/libc.abilist > +++ b/sysdeps/mach/hurd/i386/libc.abilist > @@ -2204,6 +2204,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist > index bac795262d..51f34d0f6d 100644 > --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist > @@ -2172,3 +2172,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist > index 897f70db22..7da53174ef 100644 > --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist > +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist > @@ -2254,6 +2254,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist > index 094236f713..108c41ae24 100644 > --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist > +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist > @@ -156,6 +156,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _Exit F > GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 > GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 > diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist > index 2bb4d31e81..a995a356a4 100644 > --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist > +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist > @@ -153,6 +153,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _Exit F > GLIBC_2.4 _IO_2_1_stderr_ D 0xa0 > GLIBC_2.4 _IO_2_1_stdin_ D 0xa0 > diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist > index d4291fecfb..33d0dfb2b7 100644 > --- a/sysdeps/unix/sysv/linux/csky/libc.abilist > +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist > @@ -2116,3 +2116,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F Ok. > diff --git a/sysdeps/unix/sysv/linux/execveat.c b/sysdeps/unix/sysv/linux/execveat.c > new file mode 100644 > index 0000000000..0576f36b98 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/execveat.c > @@ -0,0 +1,54 @@ > +/* Execute program relative to a directory file descriptor. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include Add a space here to outline that the execveat_fallback is not an header (although this is not really a code guideline enforcement). > +#ifndef __ASSUME_EXECVEAT > +# include "execveat_fallback.c" > +#endif > + > +/* Execute the file FD refers to, overlaying the running program image. > + ARGV and ENVP are passed to the new program, as for `execve'. */ > +int > +execveat (int dirfd, const char *path, char *const argv[], char *const envp[], > + int flags) > +{ > + /* Avoid implicit array coercion in syscall macros. */ > + INLINE_SYSCALL_CALL (execveat, dirfd, path, &argv[0], &envp[0], flags); > +#ifndef __ASSUME_EXECVEAT > + if (errno != ENOSYS) > + return -1; > + > + if ((flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW)) != 0) > + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); > + > + return __execveat_fallback (dirfd, path, argv, envp, flags); > +#endif > + > + return -1; > +} Ok. > diff --git a/sysdeps/unix/sysv/linux/execveat_fallback.c b/sysdeps/unix/sysv/linux/execveat_fallback.c > new file mode 100644 > index 0000000000..c4a37d3799 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/execveat_fallback.c > @@ -0,0 +1,69 @@ > +/* Execute program relative to a directory file descriptor. > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > + > +int > +__execveat_fallback (int dirfd, const char *path, char *const argv[], > + char *const envp[], int flags) > +{ > + int fd; > + > + if (path[0] == '\0' && (flags & AT_EMPTY_PATH) && dirfd >= 0) > + fd = dirfd; > + else > + { > + int oflags = O_CLOEXEC; > + if (flags & AT_SYMLINK_NOFOLLOW) > + oflags |= O_NOFOLLOW; > + fd = __openat_nocancel (dirfd, path, oflags); > + } > + if (fd < 0) > + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EBADFD); Wrong indentation (4 space instead of 2) and open bracket should have a space: if (....) fd = ... else { ... } This also applies to the rest of the file. > + > + struct fd_to_filename fdfilename; > + const char *gfilename = __fd_to_filename (fd, &fdfilename); > + > + /* We do not need the return value. */ > + __execve (gfilename, argv, envp); > + > + int save = errno; > + > + /* We come here only if the 'execve' call fails. Determine whether > + /proc is mounted. If not we return ENOSYS. */ > + struct stat64 st; > + if (__stat64 (FD_TO_FILENAME_PREFIX, &st) != 0 && errno == ENOENT) > + save = ENOSYS; > + > + if (fd != dirfd) > + __close_nocancel_nostatus (fd); > + __set_errno (save); > + > + return -1; > +} Ok. > diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist > index 1fd2a862f6..e1430bb232 100644 > --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist > +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist > @@ -2075,6 +2075,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist > index 943331f01e..7cb2d0dd6d 100644 > --- a/sysdeps/unix/sysv/linux/i386/libc.abilist > +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist > @@ -2242,6 +2242,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/ia64/libc.abilist b/sysdeps/unix/sysv/linux/ia64/libc.abilist > index f530151bde..2171cd3cb2 100644 > --- a/sysdeps/unix/sysv/linux/ia64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/ia64/libc.abilist > @@ -2107,6 +2107,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist > index 6e76b6dcaa..388eb76abf 100644 > --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist > +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist > @@ -157,6 +157,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _Exit F > GLIBC_2.4 _IO_2_1_stderr_ D 0x98 > GLIBC_2.4 _IO_2_1_stdin_ D 0x98 > diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist > index 7541b8289f..067ed53f2b 100644 > --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist > +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist > @@ -2187,6 +2187,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist > index 6cf1936c42..a792461b45 100644 > --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist > +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist > @@ -2167,3 +2167,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist > index 98730ebcda..0e09fe6322 100644 > --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist > +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist > @@ -2164,3 +2164,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist > index 92fa6cbc73..5d1b0b3d78 100644 > --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist > +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist > @@ -2158,6 +2158,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist > index 265a49e74e..a278c0a092 100644 > --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist > +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist > @@ -2156,6 +2156,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist > index cfa5e1111b..054d3436eb 100644 > --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist > @@ -2164,6 +2164,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist > index 8c03ac52cd..c22ef9f196 100644 > --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist > @@ -2158,6 +2158,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist > index 17f5609e06..c356e9f863 100644 > --- a/sysdeps/unix/sysv/linux/nios2/libc.abilist > +++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist > @@ -2205,3 +2205,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist > index 76a16e2a6d..d1de01f91d 100644 > --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist > +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist > @@ -2214,6 +2214,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist > index 697f072fd4..a1d52887bb 100644 > --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist > +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist > @@ -2247,6 +2247,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist > index 2647bb51f1..10cdabb11c 100644 > --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist > +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist > @@ -2077,6 +2077,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist > index 036b1c8345..70792ed87b 100644 > --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist > +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist > @@ -2367,3 +2367,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > index fb5ad9909f..9b71083136 100644 > --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist > @@ -2134,3 +2134,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist > index cead75acc5..aba76fbadd 100644 > --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist > @@ -2212,6 +2212,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist > index 31366dd7e6..6a5a765f4b 100644 > --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist > @@ -2113,6 +2113,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist > index a3a8be8910..b6629c244f 100644 > --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist > +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist > @@ -2082,6 +2082,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist > index 8f505c5045..e15ab4c569 100644 > --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist > +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist > @@ -2079,6 +2079,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist > index 53ef6304f1..11cad082d8 100644 > --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist > @@ -2203,6 +2203,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 _IO_fprintf F > GLIBC_2.4 _IO_printf F > GLIBC_2.4 _IO_sprintf F > diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist > index eba0cb156d..0ff8cb8739 100644 > --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist > @@ -2130,6 +2130,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist > index 17ce5dfd58..040d44d3a8 100644 > --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist > +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist > @@ -2089,6 +2089,7 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F > GLIBC_2.4 __confstr_chk F > GLIBC_2.4 __fgets_chk F > GLIBC_2.4 __fgets_unlocked_chk F > diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist > index 17a1c83903..4355e06891 100644 > --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist > +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist > @@ -2186,3 +2186,4 @@ GLIBC_2.33 mknodat F > GLIBC_2.33 stat F > GLIBC_2.33 stat64 F > GLIBC_2.34 __libc_start_main F > +GLIBC_2.34 execveat F It misses the abifile update for arc-linux-gnu{hf} and risc32-linux-gnu-rv32*