Skip to content

Commit 0577b0c

Browse files
committed
sys/linux/test: add landlock_fs_disconnected
Test access through disconnected directory. This test should trigger a warning without this patch: https://lore.kernel.org/all/[email protected]/ An ongoing kernel patch series will be applied to change handling of disconnected directories: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 972ed59 commit 0577b0c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Test access through a disconnected directory.
2+
3+
# Create a tmpfs mount.
4+
5+
mkdirat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x1c0)
6+
mount$tmpfs(0x0, &AUTO='./file0\x00', &AUTO='tmpfs\x00', 0x0, 0x0)
7+
8+
# Create directories and a test file in the tmpfs mount.
9+
10+
mkdirat(0xffffffffffffff9c, &AUTO='./file0/file1\x00', 0x1c0)
11+
mkdirat(0xffffffffffffff9c, &AUTO='./file0/file1/file2\x00', 0x1c0)
12+
mkdirat(0xffffffffffffff9c, &AUTO='./file0/file1/file2/file3\x00', 0x1c0)
13+
mkdirat(0xffffffffffffff9c, &AUTO='./file0/file1/file2/file3/file4\x00', 0x1c0)
14+
mknodat(0xffffffffffffff9c, &AUTO='./file0/file1/file2/file3/file5\x00', 0x81c0, 0x0)
15+
mkdirat(0xffffffffffffff9c, &AUTO='./file0/file6\x00', 0x1c0)
16+
17+
# Creates first bind mount from file3 to file3. This is an optional call useful
18+
# to extend coverage of is_access_to_paths_allowed().
19+
20+
mount$bind(&AUTO='./file0/file1/file2/file3\x00', &AUTO='./file0/file1/file2/file3\x00', 0x0, 0x1000, 0x0)
21+
22+
# Creates second recursive bind mount from file1 to file6.
23+
24+
mount$bind(&AUTO='./file0/file1\x00', &AUTO='./file0/file6\x00', 0x0, 0x5000, 0x0)
25+
26+
# Opens directory from the bind mount.
27+
28+
r0 = openat$dir(0xffffffffffffff9c, &AUTO='./file0/file6/file2\x00', 0x0, 0x0)
29+
30+
# Moves file2 to make it a disconnected directory.
31+
32+
renameat2(0xffffffffffffff9c, &AUTO='./file0/file1/file2\x00', 0xffffffffffffff9c, &AUTO='./file0/file2\x00', 0x0)
33+
34+
# Creates a ruleset with read and refer restrictions.
35+
36+
r1 = landlock_create_ruleset(&AUTO={0x2004, 0x0, 0x0}, AUTO, 0x0)
37+
38+
# Adds a rule to allow read on one side of the rename. This is an optional call
39+
# useful to extend coverage of collect_domain_accesses().
40+
41+
r2 = openat$dir(0xffffffffffffff9c, &AUTO='./file0/file2/file3/file4\x00', 0x0, 0x0)
42+
landlock_add_rule$LANDLOCK_RULE_PATH_BENEATH(r1, AUTO, &AUTO={0x4, r2}, 0x0)
43+
44+
prctl$PR_SET_NO_NEW_PRIVS(0x26, 0x1)
45+
landlock_restrict_self(r1, 0x0)
46+
47+
# Tries to open and rename a file from the disconnected directory.
48+
49+
openat(r0, &AUTO='file3/file5\x00', 0x0, 0x0) # EACCES
50+
renameat2(r0, &AUTO='file3/file5\x00', r0, &AUTO='file3/file4/file5\x00', 0x0) # EXDEV

0 commit comments

Comments
 (0)