Skip to content

Commit bdd4f86

Browse files
committed
Merge tag 'AT_EXECVE_CHECK-v6.14-rc1-fix1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull AT_EXECVE_CHECK selftest fix from Kees Cook: "Fixes the AT_EXECVE_CHECK selftests which didn't run on old versions of glibc" * tag 'AT_EXECVE_CHECK-v6.14-rc1-fix1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: selftests: Handle old glibc without execveat(2)
2 parents 73512f2 + 38567b9 commit bdd4f86

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

samples/check-exec/inc.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121
#include <stdlib.h>
2222
#include <string.h>
2323
#include <sys/prctl.h>
24+
#include <sys/syscall.h>
2425
#include <unistd.h>
2526

27+
static int sys_execveat(int dirfd, const char *pathname, char *const argv[],
28+
char *const envp[], int flags)
29+
{
30+
return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
31+
}
32+
2633
/* Returns 1 on error, 0 otherwise. */
2734
static int interpret_buffer(char *buffer, size_t buffer_size)
2835
{
@@ -78,8 +85,8 @@ static int interpret_stream(FILE *script, char *const script_name,
7885
* script execution. We must use the script file descriptor instead of
7986
* the script path name to avoid race conditions.
8087
*/
81-
err = execveat(fileno(script), "", script_argv, envp,
82-
AT_EMPTY_PATH | AT_EXECVE_CHECK);
88+
err = sys_execveat(fileno(script), "", script_argv, envp,
89+
AT_EMPTY_PATH | AT_EXECVE_CHECK);
8390
if (err && restrict_stream) {
8491
perror("ERROR: Script execution check");
8592
return 1;

tools/testing/selftests/exec/check-exec.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <sys/prctl.h>
2323
#include <sys/socket.h>
2424
#include <sys/stat.h>
25+
#include <sys/syscall.h>
2526
#include <sys/sysmacros.h>
2627
#include <unistd.h>
2728

@@ -31,6 +32,12 @@
3132

3233
#include "../kselftest_harness.h"
3334

35+
static int sys_execveat(int dirfd, const char *pathname, char *const argv[],
36+
char *const envp[], int flags)
37+
{
38+
return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
39+
}
40+
3441
static void drop_privileges(struct __test_metadata *const _metadata)
3542
{
3643
const unsigned int noroot = SECBIT_NOROOT | SECBIT_NOROOT_LOCKED;
@@ -219,8 +226,8 @@ static void test_exec_fd(struct __test_metadata *_metadata, const int fd,
219226
* test framework as an error. With AT_EXECVE_CHECK, we only check a
220227
* potential successful execution.
221228
*/
222-
access_ret =
223-
execveat(fd, "", argv, NULL, AT_EMPTY_PATH | AT_EXECVE_CHECK);
229+
access_ret = sys_execveat(fd, "", argv, NULL,
230+
AT_EMPTY_PATH | AT_EXECVE_CHECK);
224231
access_errno = errno;
225232
if (err_code) {
226233
EXPECT_EQ(-1, access_ret);

tools/testing/selftests/landlock/fs_test.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ int open_tree(int dfd, const char *filename, unsigned int flags)
5959
}
6060
#endif
6161

62+
static int sys_execveat(int dirfd, const char *pathname, char *const argv[],
63+
char *const envp[], int flags)
64+
{
65+
return syscall(__NR_execveat, dirfd, pathname, argv, envp, flags);
66+
}
67+
6268
#ifndef RENAME_EXCHANGE
6369
#define RENAME_EXCHANGE (1 << 1)
6470
#endif
@@ -2024,8 +2030,8 @@ static void test_check_exec(struct __test_metadata *const _metadata,
20242030
int ret;
20252031
char *const argv[] = { (char *)path, NULL };
20262032

2027-
ret = execveat(AT_FDCWD, path, argv, NULL,
2028-
AT_EMPTY_PATH | AT_EXECVE_CHECK);
2033+
ret = sys_execveat(AT_FDCWD, path, argv, NULL,
2034+
AT_EMPTY_PATH | AT_EXECVE_CHECK);
20292035
if (err) {
20302036
EXPECT_EQ(-1, ret);
20312037
EXPECT_EQ(errno, err);

0 commit comments

Comments
 (0)