From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RDNS_DYNAMIC,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id C82C81F4B4 for ; Mon, 12 Apr 2021 11:14:23 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83040389683D; Mon, 12 Apr 2021 11:14:22 +0000 (GMT) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by sourceware.org (Postfix) with ESMTPS id B0FD0388A031 for ; Mon, 12 Apr 2021 11:14:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B0FD0388A031 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=whitebox@nefkom.net Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4FJmMq65myz1s31j; Mon, 12 Apr 2021 13:14:15 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4FJmMq5qLTz1r1MF; Mon, 12 Apr 2021 13:14:15 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id mGi7ycq2MZjU; Mon, 12 Apr 2021 13:14:14 +0200 (CEST) X-Auth-Info: EZmCj2DuoQKPz5cD3qxzIuAS4aTbvCjB8TYgr84O60eNJRps+uuJgTb27r4S6b0y Received: from igel.home (ppp-46-244-166-146.dynamic.mnet-online.de [46.244.166.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Mon, 12 Apr 2021 13:14:14 +0200 (CEST) Received: by igel.home (Postfix, from userid 1000) id 75C672C3644; Mon, 12 Apr 2021 13:14:13 +0200 (CEST) From: Andreas Schwab To: Alexandra =?utf-8?B?SMOhamtvdsOh?= via Libc-alpha Subject: Re: [PATCH] Linux: Add execveat system call wrapper References: <20200428122019.26826-1-ahajkova@redhat.com> <20210405163228.2431406-1-ahajkova@redhat.com> X-Yow: I HAVE to buy a new ``DODGE MISER'' and two dozen JORDACHE JEANS because my viewscreen is ``USER-FRIENDLY''!! Date: Mon, 12 Apr 2021 13:14:13 +0200 In-Reply-To: <20210405163228.2431406-1-ahajkova@redhat.com> ("Alexandra =?utf-8?B?SMOhamtvdsOh?= via Libc-alpha"'s message of "Mon, 5 Apr 2021 18:32:28 +0200") Message-ID: <87y2dn7o1m.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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: , Cc: Alexandra =?utf-8?B?SMOhamtvdsOh?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" On Apr 05 2021, Alexandra Hájková via Libc-alpha wrote: > 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. > > > [Add deprecations, removals and changes affecting compatibility here] There is something missing here. > 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. */ Comment style. > diff --git a/sysdeps/unix/sysv/linux/execveat.c b/sysdeps/unix/sysv/linux/execveat.c > new file mode 100644 > index 0000000000..9deab0a2b4 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/execveat.c > @@ -0,0 +1,55 @@ > +/* 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 > + > +#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); Wrong indentation. > +#ifndef __ASSUME_EXECVEAT > + if (errno != ENOSYS) > + return -1; > + > + if ((flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW)) != 0) > + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); Wrong indentation. > diff --git a/sysdeps/unix/sysv/linux/execveat_fallback.c b/sysdeps/unix/sysv/linux/execveat_fallback.c > new file mode 100644 > index 0000000000..6249c76079 > --- /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); I think this should return the errno from __openat_nocancel. > diff --git a/sysdeps/unix/sysv/linux/tst-execveat-compat.c b/sysdeps/unix/sysv/linux/tst-execveat-compat.c > new file mode 100644 > index 0000000000..a0ba77bb1d > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-execveat-compat.c > @@ -0,0 +1,28 @@ > +/* 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 > + > +/* Re-use the test, but run it against copy_file_range_compat defined Pasto: execveat_fallback Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."