File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,11 +4,39 @@ use "eval"
44use "os"
55use "str"
66
7+ def detect_landlock()
8+ uname = test.run("uname -s")
9+ if uname["status"] != 0 || uname["output"] != "Linux"
10+ return "non-linux"
11+ end
12+ # Probe: run a sandboxed program that should be denied access to /etc.
13+ # If landlock is actually enforced, os.read_file fails and "LANDLOCK_DENIED"
14+ # is printed. If the kernel lacks landlock support, BestEffort() silently
15+ # degrades and the read succeeds.
16+ probe = <<~RUGO
17+ sandbox rox: ["/usr"]
18+ import "os"
19+ data = try os.read_file("/etc/os-release") or e
20+ "LANDLOCK_DENIED"
21+ end
22+ puts(data)
23+ RUGO
24+ r = eval.run(probe)
25+ if str.contains(r["output"], "LANDLOCK_DENIED")
26+ return "available"
27+ end
28+ return "unsupported-kernel"
29+ end
30+
31+ LANDLOCK_STATE = detect_landlock()
32+
733def skip_if_no_landlock()
8- result = test.run("uname -s")
9- if result["status"] != 0 || result["output"] != "Linux"
34+ if LANDLOCK_STATE == "non-linux"
1035 test.skip("Landlock requires Linux")
1136 end
37+ if LANDLOCK_STATE != "available"
38+ test.skip("Landlock not enforced on this kernel")
39+ end
1240end
1341
1442# ββ Codegen / emit tests ββββββββββββββββββββββββββββββββββββββββββββ
You canβt perform that action at this time.
0 commit comments