From 8d7b3b6714cdbd8094249db5679c08af0dbee351 Mon Sep 17 00:00:00 2001 From: Mickaël Salaün Date: Wed, 19 Jan 2022 15:21:15 +0100 Subject: sys/linux/test: add landlock_fs_reparent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This test covers linking, renaming and exchanging (RENAME_EXCHANGE) checks handled in security/landlock/fs.c . Signed-off-by: Mickaël Salaün --- sys/linux/test/landlock_fs_reparent | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sys/linux/test/landlock_fs_reparent (limited to 'sys/linux/test/landlock_fs_reparent') diff --git a/sys/linux/test/landlock_fs_reparent b/sys/linux/test/landlock_fs_reparent new file mode 100644 index 000000000..08d78decb --- /dev/null +++ b/sys/linux/test/landlock_fs_reparent @@ -0,0 +1,39 @@ +# Creates a file hierarchy with a mount point. + +mkdirat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x1c0) +mkdirat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x1c0) +mknodat(0xffffffffffffff9c, &AUTO='./file1/file2\x00', 0x81c0, 0x0) +mkdirat(0xffffffffffffff9c, &AUTO='./file1/file3\x00', 0x1c0) +mkdirat(0xffffffffffffff9c, &AUTO='./file1/file4\x00', 0x1c0) +mount$tmpfs(0x0, &AUTO='./file1/file4\x00', &AUTO='tmpfs\x00', 0x0, 0x0) +mknodat(0xffffffffffffff9c, &AUTO='./file1/file4/file5\x00', 0x81c0, 0x0) +mkdirat(0xffffffffffffff9c, &AUTO='./file1/file4/file6\x00', 0x1c0) +mkdirat(0xffffffffffffff9c, &AUTO='./file1/file4/file7\x00', 0x1c0) + +# Creates a ruleset to restrict file linking/renaming and execution (to get an extra access right). + +r0 = landlock_create_ruleset(&AUTO={0x2001}, AUTO, 0x0) + +# Allows link and rename from and to file1. + +r1 = openat$dir(0xffffffffffffff9c, &AUTO='./file1\x00', 0x200000, 0x0) +landlock_add_rule$LANDLOCK_RULE_PATH_BENEATH(r0, AUTO, &AUTO={0x2000, r1}, 0x0) + +# No need to close FDs for this test. + +# Enforces the first ruleset. + +prctl$PR_SET_NO_NEW_PRIVS(0x26, 0x1) +landlock_restrict_self(r0, 0x0) + +# Denied link, rename and exchange. + +linkat(0xffffffffffffff9c, &AUTO='./file1/file2\x00', 0xffffffffffffff9c, &AUTO='./file0/file2\x00', 0x0) # EXDEV +renameat2(0xffffffffffffff9c, &AUTO='./file1/file3\x00', 0xffffffffffffff9c, &AUTO='./file0/file3\x00', 0x0) # EXDEV +renameat2(0xffffffffffffff9c, &AUTO='./file1/file2\x00', 0xffffffffffffff9c, &AUTO='./file0\x00', 0x2) # EXDEV + +# Allowed link, rename and exchange with access right beneath the mount point. + +linkat(0xffffffffffffff9c, &AUTO='./file1/file4/file5\x00', 0xffffffffffffff9c, &AUTO='./file1/file4/file7/file5\x00', 0x0) +renameat2(0xffffffffffffff9c, &AUTO='./file1/file4/file6\x00', 0xffffffffffffff9c, &AUTO='./file1/file4/file7/file6\x00', 0x0) +renameat2(0xffffffffffffff9c, &AUTO='./file1/file4/file5\x00', 0xffffffffffffff9c, &AUTO='./file1/file4/file7/file6\x00', 0x2) -- cgit mrf-deployment