aboutsummaryrefslogtreecommitdiffstats
path: root/sys/linux/test/landlock_fs_truncate
blob: 7429d74b3331f3c7b4b4c9f158952172c575ef03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Makes regular files.

mknodat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x81c0, 0x0)
mknodat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x81c0, 0x0)

# Opens each file in write mode before sandboxing.

r0 = openat$dir(0xffffffffffffff9c, &AUTO='./file0\x00', 0x1, 0x0)
r1 = openat$dir(0xffffffffffffff9c, &AUTO='./file1\x00', 0x1, 0x0)

# Creates a ruleset to restrict file truncation: LANDLOCK_ACCESS_FS_TRUNCATE.

r2 = landlock_create_ruleset(&AUTO={0x4000, 0x0, 0x0}, AUTO, 0x0)

# Allows truncation of file1.

landlock_add_rule$LANDLOCK_RULE_PATH_BENEATH(r2, AUTO, &AUTO={0x4000, 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(r2, 0x0)

# Opens each file in write mode after sandboxing.

r3 = openat$dir(0xffffffffffffff9c, &AUTO='./file0\x00', 0x1, 0x0)
r4 = openat$dir(0xffffffffffffff9c, &AUTO='./file1\x00', 0x1, 0x0)

# Denied truncation.

truncate(&AUTO='./file0\x00', 0x1) # EACCES
ftruncate(r3, 0x1) # EACCES

# Allowed truncation.

truncate(&AUTO='./file1\x00', 0x1)
ftruncate(r0, 0x1)
ftruncate(r1, 0x1)
ftruncate(r4, 0x1)