diff options
| author | Mickaël Salaün <mic@linux.microsoft.com> | 2022-01-19 15:21:15 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-05-10 16:24:39 +0200 |
| commit | 8d7b3b6714cdbd8094249db5679c08af0dbee351 (patch) | |
| tree | eeacce1452ccc7a2dc4d46ae16b4e8613f271d6f /sys/linux/test/landlock_fs_reparent | |
| parent | 7f7d13d9e9b8d5df41751505d791aa78d4ff6702 (diff) | |
sys/linux/test: add landlock_fs_reparent
This test covers linking, renaming and exchanging (RENAME_EXCHANGE) checks
handled in security/landlock/fs.c .
Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com>
Diffstat (limited to 'sys/linux/test/landlock_fs_reparent')
| -rw-r--r-- | sys/linux/test/landlock_fs_reparent | 39 |
1 files changed, 39 insertions, 0 deletions
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) |
