[PATCH v1 6/9] selftests/landlock: Extend layout1.inherit_superset

From: Mickaël Salaün
Date: Wed Nov 11 2020 - 16:35:16 EST


These additional checks test that layers are handled as expected in the
superset use case, which complete the inherit_subset checks.

Cc: James Morris <jmorris@xxxxxxxxx>
Cc: Jann Horn <jannh@xxxxxxxxxx>
Cc: Serge E. Hallyn <serge@xxxxxxxxxx>
Signed-off-by: Mickaël Salaün <mic@xxxxxxxxxxx>
---
tools/testing/selftests/landlock/fs_test.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 1885174b2770..c2f65034e4ee 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -907,6 +907,10 @@ TEST_F(layout1, inherit_superset)
open_fd = open(dir_s1d3, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
ASSERT_LE(0, open_fd);
ASSERT_EQ(0, close(open_fd));
+ /* File access is allowed for file1_s1d3. */
+ open_fd = open(file1_s1d3, O_RDONLY | O_CLOEXEC);
+ ASSERT_LE(0, open_fd);
+ ASSERT_EQ(0, close(open_fd));

/* Now dir_s1d2, parent of dir_s1d3, gets a new rule tied to it. */
add_path_beneath(_metadata, ruleset_fd, LANDLOCK_ACCESS_FS_READ_FILE |
@@ -922,6 +926,10 @@ TEST_F(layout1, inherit_superset)
open_fd = open(dir_s1d3, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
ASSERT_LE(0, open_fd);
ASSERT_EQ(0, close(open_fd));
+ /* File access is now denied for file1_s1d3. */
+ open_fd = open(file1_s1d3, O_RDONLY | O_CLOEXEC);
+ ASSERT_LE(-1, open_fd);
+ ASSERT_EQ(EACCES, errno);
}

TEST_F(layout1, max_layers)
--
2.29.2