Skip to content

Commit 1f00666

Browse files
committed
selftests/landlock: Test handling of unknown scope
JIRA: https://issues.redhat.com/browse/RHEL-94688 Add a new ruleset_with_unknown_scope test designed to validate the behaviour of landlock_create_ruleset(2) when called with an unsupported or unknown scope mask. Signed-off-by: Tahera Fahimi <fahimitahera@gmail.com> Link: https://lore.kernel.org/r/74b363aaa7ddf80e1e5e132ce3d550a3a8bbf6da.1725494372.git.fahimitahera@gmail.com Signed-off-by: Mickaël Salaün <mic@digikod.net> (cherry picked from commit 5b6b63c) Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
1 parent c416803 commit 1f00666

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Landlock tests - Common scope restriction
4+
*
5+
* Copyright © 2024 Tahera Fahimi <fahimitahera@gmail.com>
6+
*/
7+
8+
#define _GNU_SOURCE
9+
#include <errno.h>
10+
#include <linux/landlock.h>
11+
#include <sys/prctl.h>
12+
13+
#include "common.h"
14+
15+
#define ACCESS_LAST LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET
16+
17+
TEST(ruleset_with_unknown_scope)
18+
{
19+
__u64 scoped_mask;
20+
21+
for (scoped_mask = 1ULL << 63; scoped_mask != ACCESS_LAST;
22+
scoped_mask >>= 1) {
23+
struct landlock_ruleset_attr ruleset_attr = {
24+
.scoped = scoped_mask,
25+
};
26+
27+
ASSERT_EQ(-1, landlock_create_ruleset(&ruleset_attr,
28+
sizeof(ruleset_attr), 0));
29+
ASSERT_EQ(EINVAL, errno);
30+
}
31+
}
32+
33+
TEST_HARNESS_MAIN

0 commit comments

Comments
 (0)