From: Andreas Schwab <schwab@suse.de>
To: libc-alpha@sourceware.org
Subject: [PATCH] Use execveat syscall in fexecve
Date: Thu, 07 Sep 2017 09:06:00 -0000 [thread overview]
Message-ID: <mvm8thqdgj1.fsf@suse.de> (raw)
By using execveat we no longer depend on /proc. The execveat syscall was
introduced in 3.19, except for a few late comers.
* sysdeps/unix/sysv/linux/fexecve.c (fexecve) [__NR_execveat]: Try
execveat first.
[!__ASSUME_EXECVEAT]: Fall back to /proc if execveat is
unimplemented.
* sysdeps/unix/sysv/linux/kernel-features.h (__ASSUME_EXECVEAT)
[__LINUX_KERNEL_VERSION >= 0x031300]: Define.
* sysdeps/unix/sysv/linux/alpha/kernel-features.h
(__ASSUME_EXECVEAT) [__LINUX_KERNEL_VERSION < 0x040200]: Undef.
* sysdeps/unix/sysv/linux/hppa/kernel-features.h
(__ASSUME_EXECVEAT) [__LINUX_KERNEL_VERSION < 0x040000]: Undef.
* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
(__ASSUME_EXECVEAT) [__LINUX_KERNEL_VERSION < 0x040000]: Undef.
---
sysdeps/unix/sysv/linux/alpha/kernel-features.h | 5 +++++
sysdeps/unix/sysv/linux/fexecve.c | 15 +++++++++++++++
sysdeps/unix/sysv/linux/hppa/kernel-features.h | 5 +++++
sysdeps/unix/sysv/linux/kernel-features.h | 5 +++++
sysdeps/unix/sysv/linux/microblaze/kernel-features.h | 5 +++++
5 files changed, 35 insertions(+)
diff --git a/sysdeps/unix/sysv/linux/alpha/kernel-features.h b/sysdeps/unix/sysv/linux/alpha/kernel-features.h
index 53f7611f93..5bc2ddb713 100644
--- a/sysdeps/unix/sysv/linux/alpha/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/alpha/kernel-features.h
@@ -35,4 +35,9 @@
#define __ASSUME_RECV_SYSCALL 1
#define __ASSUME_SEND_SYSCALL 1
+/* Support for the execveat syscall was added in 4.2. */
+#if __LINUX_KERNEL_VERSION < 0x040200
+# undef __ASSUME_EXECVEAT
+#endif
+
#endif /* _KERNEL_FEATURES_H */
diff --git a/sysdeps/unix/sysv/linux/fexecve.c b/sysdeps/unix/sysv/linux/fexecve.c
index 30fa719b56..3bf5de507f 100644
--- a/sysdeps/unix/sysv/linux/fexecve.c
+++ b/sysdeps/unix/sysv/linux/fexecve.c
@@ -19,8 +19,13 @@
#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>
+
/* Execute the file FD refers to, overlaying the running program image.
ARGV and ENVP are passed to the new program, as for `execve'. */
@@ -33,6 +38,15 @@ fexecve (int fd, char *const argv[], char *const envp[])
return -1;
}
+#ifdef __NR_execveat
+ INLINE_SYSCALL (execveat, 5, fd, "", argv, envp, AT_EMPTY_PATH);
+# ifndef __ASSUME_EXECVEAT
+ if (errno != ENOSYS)
+ return -1;
+# endif
+#endif
+
+#ifndef __ASSUME_EXECVEAT
/* We use the /proc filesystem to get the information. If it is not
mounted we fail. */
char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3];
@@ -50,6 +64,7 @@ fexecve (int fd, char *const argv[], char *const envp[])
save = ENOSYS;
__set_errno (save);
+#endif
return -1;
}
diff --git a/sysdeps/unix/sysv/linux/hppa/kernel-features.h b/sysdeps/unix/sysv/linux/hppa/kernel-features.h
index 0e73a5c0df..f25a840040 100644
--- a/sysdeps/unix/sysv/linux/hppa/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/hppa/kernel-features.h
@@ -27,3 +27,8 @@
#define __ASSUME_RECV_SYSCALL 1
#define __ASSUME_SEND_SYSCALL 1
+
+/* Support for the execveat syscall was added in 4.0. */
+#if __LINUX_KERNEL_VERSION < 0x040000
+# undef __ASSUME_EXECVEAT
+#endif
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 9495db4fef..2e1fe6597a 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -102,3 +102,8 @@
implementation does not assume the __ASSUME_* and instead use a fallback
implementation based on p{read,write}v and returning an error for
non supported flags. */
+
+/* Support for the execveat syscall was added in 3.19. */
+#if __LINUX_KERNEL_VERSION >= 0x031300
+# define __ASSUME_EXECVEAT 1
+#endif
diff --git a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
index 0257524777..6575df2a95 100644
--- a/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/microblaze/kernel-features.h
@@ -47,3 +47,8 @@
#if __LINUX_KERNEL_VERSION < 0x030300
# undef __ASSUME_SENDMMSG_SYSCALL
#endif
+
+/* Support for the execveat syscall was added in 4.0. */
+#if __LINUX_KERNEL_VERSION < 0x040000
+# undef __ASSUME_EXECVEAT
+#endif
--
2.14.1
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
next reply other threads:[~2017-09-07 9:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-07 9:06 Andreas Schwab [this message]
2017-09-07 11:27 ` Florian Weimer
2017-09-11 10:23 ` [PATCH v2] " Andreas Schwab
2017-09-11 20:30 ` Adhemerval Zanella
2017-09-11 20:38 ` Joseph Myers
2017-09-11 20:59 ` Florian Weimer
2017-09-11 22:58 ` Adhemerval Zanella
2017-09-14 8:05 ` Andreas Schwab
2017-09-14 13:44 ` Adhemerval Zanella
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mvm8thqdgj1.fsf@suse.de \
--to=schwab@suse.de \
--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).