[v1,6/9] selftests/landlock: Extend layout1.inherit_superset
diff mbox series

Message ID 20201111213442.434639-7-mic@digikod.net
State New, archived
Headers show
Series
  • Landlock fixes
Related show

Commit Message

Mickaël Salaün Nov. 11, 2020, 9:34 p.m. UTC
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@namei.org>
Cc: Jann Horn <jannh@google.com>
Cc: Serge E. Hallyn <serge@hallyn.com>
Signed-off-by: Mickaël Salaün <mic@digikod.net>
---
 tools/testing/selftests/landlock/fs_test.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Patch
diff mbox series

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)