Skip to content

Commit ec12a8d

Browse files
committed
selftests/landlock: Add test for invalid ruleset file descriptor
To align with fs_test's layout1.inval and layout0.proc_nsfs which test EBADFD for landlock_add_rule(2), create a new base_test's restrict_self_fd which test EBADFD for landlock_restrict_self(2). Cc: Günther Noack <gnoack@google.com> Cc: Paul Moore <paul@paul-moore.com> Link: https://lore.kernel.org/r/20250320190717.2287696-21-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent ec2798d commit ec12a8d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tools/testing/selftests/landlock/base_test.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ TEST(restrict_self_checks_ordering)
277277
ASSERT_EQ(0, close(ruleset_fd));
278278
}
279279

280+
TEST(restrict_self_fd)
281+
{
282+
int fd;
283+
284+
fd = open("/dev/null", O_RDONLY | O_CLOEXEC);
285+
ASSERT_LE(0, fd);
286+
287+
EXPECT_EQ(-1, landlock_restrict_self(fd, 0));
288+
EXPECT_EQ(EBADFD, errno);
289+
}
290+
280291
TEST(ruleset_fd_io)
281292
{
282293
struct landlock_ruleset_attr ruleset_attr = {

0 commit comments

Comments
 (0)