summaryrefslogtreecommitdiff
path: root/samples/check-exec
diff options
context:
space:
mode:
authorMickaël Salaün <mic@digikod.net>2025-01-15 15:47:50 +0100
committerKees Cook <kees@kernel.org>2025-01-27 11:37:18 -0800
commit38567b972a22706e9a1a52b2c4bc9ea4b5ed00ed (patch)
treebd2c8a4a850adeb734137401210ba37730e8b3a6 /samples/check-exec
parent95b3cdafd7cb74414070893445a9b731793f7b55 (diff)
downloadlinux-38567b972a22706e9a1a52b2c4bc9ea4b5ed00ed.tar.gz
linux-38567b972a22706e9a1a52b2c4bc9ea4b5ed00ed.tar.bz2
linux-38567b972a22706e9a1a52b2c4bc9ea4b5ed00ed.zip
selftests: Handle old glibc without execveat(2)
Add an execveat(2) wrapper because glibc < 2.34 does not have one. This fixes the check-exec tests and samples. Cc: Günther Noack <gnoack@google.com> Cc: Jeff Xu <jeffxu@chromium.org> Cc: Kees Cook <kees@kernel.org> Cc: Mimi Zohar <zohar@linux.ibm.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Roberto Sassu <roberto.sassu@huawei.com> Cc: Serge Hallyn <serge@hallyn.com> Cc: Stefan Berger <stefanb@linux.ibm.com> Cc: Stephen Rothwell <sfr@canb.auug.org.au> Reported-by: Nathan Chancellor <nathan@kernel.org> Closes: https://lore.kernel.org/r/20250114205645.GA2825031@ax162 Signed-off-by: Mickaël Salaün <mic@digikod.net> Reviewed-by: Günther Noack <gnoack3000@gmail.com> Link: https://lore.kernel.org/r/20250115144753.311152-1-mic@digikod.net Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'samples/check-exec')
-rw-r--r--samples/check-exec/inc.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/samples/check-exec/inc.c b/samples/check-exec/inc.c
index 94b87569d2a2..7f6ef06a2f06 100644
--- a/samples/check-exec/inc.c
+++ b/samples/check-exec/inc.c
@@ -21,8 +21,15 @@
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
+#include <sys/syscall.h>
#include <unistd.h>
+static int sys_execveat(int dirfd, const char *pathname, char *const argv[],
+ char *const envp[], int flags)
+{
+ return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
+}
+
/* Returns 1 on error, 0 otherwise. */
static int interpret_buffer(char *buffer, size_t buffer_size)
{
@@ -78,8 +85,8 @@ static int interpret_stream(FILE *script, char *const script_name,
* script execution. We must use the script file descriptor instead of
* the script path name to avoid race conditions.
*/
- err = execveat(fileno(script), "", script_argv, envp,
- AT_EMPTY_PATH | AT_EXECVE_CHECK);
+ err = sys_execveat(fileno(script), "", script_argv, envp,
+ AT_EMPTY_PATH | AT_EXECVE_CHECK);
if (err && restrict_stream) {
perror("ERROR: Script execution check");
return 1;