Skip to content

Commit 0e7f90f

Browse files
l0kodkees
authored andcommitted
selftests/landlock: Add tests for execveat + AT_EXECVE_CHECK
Extend layout1.execute with the new AT_EXECVE_CHECK flag. The semantic with AT_EXECVE_CHECK is the same as with a simple execve(2), LANDLOCK_ACCESS_FS_EXECUTE is enforced the same way. Cc: Günther Noack <gnoack@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Paul Moore <paul@paul-moore.com> Signed-off-by: Mickaël Salaün <mic@digikod.net> Link: https://lore.kernel.org/r/20241212174223.389435-5-mic@digikod.net Signed-off-by: Kees Cook <kees@kernel.org>
1 parent b083cc8 commit 0e7f90f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tools/testing/selftests/landlock/fs_test.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include <linux/fs.h>
3838
#include <linux/mount.h>
3939

40+
/* Defines AT_EXECVE_CHECK without type conflicts. */
41+
#define _ASM_GENERIC_FCNTL_H
42+
#include <linux/fcntl.h>
43+
4044
#include "common.h"
4145

4246
#ifndef renameat2
@@ -2008,6 +2012,22 @@ static void test_execute(struct __test_metadata *const _metadata, const int err,
20082012
};
20092013
}
20102014

2015+
static void test_check_exec(struct __test_metadata *const _metadata,
2016+
const int err, const char *const path)
2017+
{
2018+
int ret;
2019+
char *const argv[] = { (char *)path, NULL };
2020+
2021+
ret = execveat(AT_FDCWD, path, argv, NULL,
2022+
AT_EMPTY_PATH | AT_EXECVE_CHECK);
2023+
if (err) {
2024+
EXPECT_EQ(-1, ret);
2025+
EXPECT_EQ(errno, err);
2026+
} else {
2027+
EXPECT_EQ(0, ret);
2028+
}
2029+
}
2030+
20112031
TEST_F_FORK(layout1, execute)
20122032
{
20132033
const struct rule rules[] = {
@@ -2025,20 +2045,27 @@ TEST_F_FORK(layout1, execute)
20252045
copy_binary(_metadata, file1_s1d2);
20262046
copy_binary(_metadata, file1_s1d3);
20272047

2048+
/* Checks before file1_s1d1 being denied. */
2049+
test_execute(_metadata, 0, file1_s1d1);
2050+
test_check_exec(_metadata, 0, file1_s1d1);
2051+
20282052
enforce_ruleset(_metadata, ruleset_fd);
20292053
ASSERT_EQ(0, close(ruleset_fd));
20302054

20312055
ASSERT_EQ(0, test_open(dir_s1d1, O_RDONLY));
20322056
ASSERT_EQ(0, test_open(file1_s1d1, O_RDONLY));
20332057
test_execute(_metadata, EACCES, file1_s1d1);
2058+
test_check_exec(_metadata, EACCES, file1_s1d1);
20342059

20352060
ASSERT_EQ(0, test_open(dir_s1d2, O_RDONLY));
20362061
ASSERT_EQ(0, test_open(file1_s1d2, O_RDONLY));
20372062
test_execute(_metadata, 0, file1_s1d2);
2063+
test_check_exec(_metadata, 0, file1_s1d2);
20382064

20392065
ASSERT_EQ(0, test_open(dir_s1d3, O_RDONLY));
20402066
ASSERT_EQ(0, test_open(file1_s1d3, O_RDONLY));
20412067
test_execute(_metadata, 0, file1_s1d3);
2068+
test_check_exec(_metadata, 0, file1_s1d3);
20422069
}
20432070

20442071
TEST_F_FORK(layout1, link)

0 commit comments

Comments
 (0)