| 1 | |
| 2 | |
| 3 | |
| 4 |
|
| 5 | err=0
|
| 6 |
|
| 7 | syscall="landlock_add_rule"
|
| 8 | non_syscall="timer:hrtimer_start"
|
| 9 |
|
| 10 | TESTPROG="perf test -w landlock"
|
| 11 |
|
| 12 | |
| 13 | . "$(dirname $0)"/lib/probe.sh
|
| 14 | skip_if_no_perf_trace || exit 2
|
| 15 | [ "$(id -u)" = 0 ] || exit 2
|
| 16 |
|
| 17 | check_vmlinux() {
|
| 18 | echo "Checking if vmlinux exists"
|
| 19 | if [ ! -f /sys/kernel/btf/vmlinux ]
|
| 20 | then
|
| 21 | echo "trace+enum test [Skipped missing vmlinux BTF support]"
|
| 22 | err=2
|
| 23 | fi
|
| 24 | }
|
| 25 |
|
| 26 | check_permissions() {
|
| 27 | if perf trace -e $syscall $TESTPROG 2>&1 | grep -q "Operation not permitted"
|
| 28 | then
|
| 29 | echo "trace+enum test [Skipped permissions]"
|
| 30 | err=2
|
| 31 | fi
|
| 32 | }
|
| 33 |
|
| 34 | trace_landlock() {
|
| 35 | echo "Tracing syscall ${syscall}"
|
| 36 |
|
| 37 | |
| 38 | if ! perf trace $TESTPROG 2>&1 | grep -q landlock
|
| 39 | then
|
| 40 | echo "No landlock system call found, skipping to non-syscall tracing."
|
| 41 | return
|
| 42 | fi
|
| 43 |
|
| 44 | output="$(perf trace -e $syscall $TESTPROG 2>&1)"
|
| 45 | if echo "$output" | grep -q -E ".*landlock_add_rule\(ruleset_fd: 11, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: 45\) = -1.*"
|
| 46 | then
|
| 47 | err=0
|
| 48 | else
|
| 49 | printf "[syscall failure] Failed to trace syscall $syscall, output:\n$output\n"
|
| 50 | err=1
|
| 51 | fi
|
| 52 | }
|
| 53 |
|
| 54 | trace_non_syscall() {
|
| 55 | echo "Tracing non-syscall tracepoint ${non_syscall}"
|
| 56 | output="$(perf trace -e $non_syscall --max-events=1 2>&1)"
|
| 57 | if echo "$output" | grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
|
| 58 | then
|
| 59 | err=0
|
| 60 | else
|
| 61 | printf "[tracepoint failure] Failed to trace tracepoint $non_syscall, output:\n$output\n"
|
| 62 | err=1
|
| 63 | fi
|
| 64 | }
|
| 65 |
|
| 66 | check_vmlinux
|
| 67 | if [ $err = 0 ]; then
|
| 68 | check_permissions
|
| 69 | fi
|
| 70 |
|
| 71 | if [ $err = 0 ]; then
|
| 72 | trace_landlock
|
| 73 | fi
|
| 74 |
|
| 75 | if [ $err = 0 ]; then
|
| 76 | trace_non_syscall
|
| 77 | fi
|
| 78 |
|
| 79 | exit $err
|