unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: "Alexandra Hájková via Libc-alpha" <libc-alpha@sourceware.org>
Cc: "Alexandra Hájková" <ahajkova@redhat.com>
Subject: Re: [PATCH] Linux: Add execveat system call wrapper
Date: Mon, 12 Apr 2021 13:14:13 +0200	[thread overview]
Message-ID: <87y2dn7o1m.fsf@igel.home> (raw)
In-Reply-To: <20210405163228.2431406-1-ahajkova@redhat.com> ("Alexandra Hájková via Libc-alpha"'s message of "Mon, 5 Apr 2021 18:32:28 +0200")

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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +#include <stddef.h>
> +#include <unistd.h>
> +
> +/* 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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +#include <stddef.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <sys/stat.h>
> +
> +#include <sysdep.h>
> +#include <sys/syscall.h>
> +#include <kernel-features.h>
> +#include <fd_to_filename.h>
> +#include <not-cancel.h>
> +
> +#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
> +   <https://www.gnu.org/licenses/>.  */
> +
> +#include <errno.h>
> +#include <stddef.h>
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <sys/stat.h>
> +
> +#include <sysdep.h>
> +#include <sys/syscall.h>
> +#include <kernel-features.h>
> +#include <fd_to_filename.h>
> +#include <not-cancel.h>
> +
> +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
> +   <http://www.gnu.org/licenses/>.  */
> +
> +/* Get the declaration of the official execveat function.  */
> +#include <unistd.h>
> +
> +/* Compile a local version of execveat.  */
> +#include <sysdeps/unix/sysv/linux/execveat_fallback.c>
> +
> +/* 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."

  parent reply	other threads:[~2021-04-12 11:14 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28 12:20 [PATCH] Linux: Add execveat system call wrapper Alexandra Hájková via Libc-alpha
2020-04-28 14:17 ` Florian Weimer
2020-04-28 15:03   ` Joseph Myers
2020-04-28 15:03 ` Joseph Myers
2020-04-28 15:08   ` Florian Weimer
2020-04-28 15:29     ` Joseph Myers
2020-04-28 17:15       ` Florian Weimer
2020-04-28 17:19         ` Joseph Myers
2020-04-28 17:44 ` Adhemerval Zanella via Libc-alpha
2020-04-28 17:50   ` Florian Weimer
2020-04-28 18:31     ` Adhemerval Zanella via Libc-alpha
2020-04-30 11:15 ` Florian Weimer via Libc-alpha
2020-04-30 12:28   ` Adhemerval Zanella via Libc-alpha
2020-04-30 12:55     ` Florian Weimer via Libc-alpha
2020-04-30 19:03       ` Adhemerval Zanella via Libc-alpha
2020-04-30 12:32 ` Adhemerval Zanella via Libc-alpha
2020-11-06 21:03 ` Alexandra Hájková via Libc-alpha
2020-11-06 22:15   ` Joseph Myers
2020-11-09 18:43     ` Florian Weimer via Libc-alpha
2020-11-09 21:34   ` Yann Droneaud
2020-11-26 11:31     ` Alexandra Petlanova Hajkova via Libc-alpha
2020-11-09 20:39 ` Adhemerval Zanella via Libc-alpha
2020-12-03 13:55   ` Florian Weimer via Libc-alpha
2020-11-26 21:28 ` Alexandra Hájková via Libc-alpha
2020-11-27 14:58   ` Adhemerval Zanella via Libc-alpha
2020-11-27 17:32     ` Florian Weimer via Libc-alpha
2020-11-27 17:38       ` Adhemerval Zanella via Libc-alpha
2020-12-03 14:20 ` Alexandra Hájková via Libc-alpha
2020-12-03 14:37   ` Andreas Schwab
2020-12-08 14:44   ` Adhemerval Zanella via Libc-alpha
2020-12-08 15:18     ` Florian Weimer via Libc-alpha
2020-12-08 16:41       ` Adhemerval Zanella via Libc-alpha
2021-03-15 21:42 ` Alexandra Hájková via Libc-alpha
2021-03-15 22:12   ` Joseph Myers
2021-03-15 22:17   ` Dmitry V. Levin
2021-03-24 13:54 ` Alexandra Hájková via Libc-alpha
2021-03-26 20:36   ` Adhemerval Zanella via Libc-alpha
2021-04-02 12:13     ` Alexandra Hájková via Libc-alpha
2021-04-02 13:29       ` Adhemerval Zanella via Libc-alpha
2021-04-05 16:32 ` Alexandra Hájková via Libc-alpha
2021-04-12 10:26   ` Alexandra Hájková via Libc-alpha
2021-04-12 11:14   ` Andreas Schwab [this message]
2021-04-12 19:26 ` Alexandra Hájková via Libc-alpha
2021-04-13 19:27   ` Adhemerval Zanella via Libc-alpha
2021-04-21 18:11 ` Alexandra Hájková via Libc-alpha
2021-05-03 19:20   ` Adhemerval Zanella via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2dn7o1m.fsf@igel.home \
    --to=schwab@linux-m68k.org \
    --cc=ahajkova@redhat.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).