• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: Kprobe event parser error log check
4# requires: kprobe_events error_log
5
6check_error() { # command-with-error-pos-by-^
7    ftrace_errlog_check 'trace_kprobe' "$1" 'kprobe_events'
8}
9
10if grep -q 'r\[maxactive\]' README; then
11check_error 'p^100 vfs_read'		# MAXACT_NO_KPROBE
12check_error 'r^1a111 vfs_read'		# BAD_MAXACT
13check_error 'r^100000 vfs_read'		# MAXACT_TOO_BIG
14fi
15
16check_error 'p ^non_exist_func'		# BAD_PROBE_ADDR (enoent)
17check_error 'p ^hoge-fuga'		# BAD_PROBE_ADDR (bad syntax)
18check_error 'p ^hoge+1000-1000'		# BAD_PROBE_ADDR (bad syntax)
19check_error 'r ^vfs_read+10'		# BAD_RETPROBE
20check_error 'p:^/bar vfs_read'		# NO_GROUP_NAME
21check_error 'p:^12345678901234567890123456789012345678901234567890123456789012345/bar vfs_read'	# GROUP_TOO_LONG
22
23check_error 'p:^foo.1/bar vfs_read'	# BAD_GROUP_NAME
24check_error 'p:foo/^12345678901234567890123456789012345678901234567890123456789012345 vfs_read'	# EVENT_TOO_LONG
25check_error 'p:foo/^bar.1 vfs_read'	# BAD_EVENT_NAME
26
27check_error 'p vfs_read ^$retval'	# RETVAL_ON_PROBE
28check_error 'p vfs_read ^$stack10000'	# BAD_STACK_NUM
29
30if grep -q '$arg<N>' README; then
31check_error 'p vfs_read ^$arg10000'	# BAD_ARG_NUM
32fi
33
34check_error 'p vfs_read ^$none_var'	# BAD_VAR
35
36check_error 'p vfs_read ^%none_reg'	# BAD_REG_NAME
37check_error 'p vfs_read ^@12345678abcde'	# BAD_MEM_ADDR
38check_error 'p vfs_read ^@+10'		# FILE_ON_KPROBE
39
40grep -q "imm-value" README && \
41check_error 'p vfs_read arg1=\^x'	# BAD_IMM
42grep -q "imm-string" README && \
43check_error 'p vfs_read arg1=\"abcd^'	# IMMSTR_NO_CLOSE
44
45check_error 'p vfs_read ^+0@0)'		# DEREF_NEED_BRACE
46check_error 'p vfs_read ^+0ab1(@0)'	# BAD_DEREF_OFFS
47check_error 'p vfs_read +0(+0(@0^)'	# DEREF_OPEN_BRACE
48
49if grep -A1 "fetcharg:" README | grep -q '\$comm' ; then
50check_error 'p vfs_read +0(^$comm)'	# COMM_CANT_DEREF
51fi
52
53check_error 'p vfs_read ^&1'		# BAD_FETCH_ARG
54
55
56# We've introduced this limitation with array support
57if grep -q ' <type>\\\[<array-size>\\\]' README; then
58check_error 'p vfs_read +0(^+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(+0(@0))))))))))))))'	# TOO_MANY_OPS?
59check_error 'p vfs_read +0(@11):u8[10^'		# ARRAY_NO_CLOSE
60check_error 'p vfs_read +0(@11):u8[10]^a'	# BAD_ARRAY_SUFFIX
61check_error 'p vfs_read +0(@11):u8[^10a]'	# BAD_ARRAY_NUM
62check_error 'p vfs_read +0(@11):u8[^256]'	# ARRAY_TOO_BIG
63fi
64
65check_error 'p vfs_read @11:^unknown_type'	# BAD_TYPE
66check_error 'p vfs_read $stack0:^string'	# BAD_STRING
67check_error 'p vfs_read @11:^b10@a/16'		# BAD_BITFIELD
68
69check_error 'p vfs_read ^arg123456789012345678901234567890=@11'	# ARG_NAME_TOO_LOG
70check_error 'p vfs_read ^=@11'			# NO_ARG_NAME
71check_error 'p vfs_read ^var.1=@11'		# BAD_ARG_NAME
72check_error 'p vfs_read var1=@11 ^var1=@12'	# USED_ARG_NAME
73check_error 'p vfs_read ^+1234567(+1234567(+1234567(+1234567(+1234567(+1234567(@1234))))))'	# ARG_TOO_LONG
74check_error 'p vfs_read arg1=^'			# NO_ARG_BODY
75
76# instruction boundary check is valid on x86 (at this moment)
77case $(uname -m) in
78  x86_64|i[3456]86)
79    echo 'p vfs_read' > kprobe_events
80    if grep -q FTRACE ../kprobes/list ; then
81	check_error 'p ^vfs_read+3'		# BAD_INSN_BNDRY (only if function-tracer is enabled)
82    fi
83    ;;
84esac
85
86# multiprobe errors
87if grep -q "Create/append/" README && grep -q "imm-value" README; then
88echo "p:kprobes/testevent $FUNCTION_FORK" > kprobe_events
89check_error '^r:kprobes/testevent do_exit'	# DIFF_PROBE_TYPE
90
91# Explicitly use printf "%s" to not interpret \1
92printf "%s" "p:kprobes/testevent $FUNCTION_FORK abcd=\\1" > kprobe_events
93check_error "p:kprobes/testevent $FUNCTION_FORK ^bcd=\\1"	# DIFF_ARG_TYPE
94check_error "p:kprobes/testevent $FUNCTION_FORK ^abcd=\\1:u8"	# DIFF_ARG_TYPE
95check_error "p:kprobes/testevent $FUNCTION_FORK ^abcd=\\\"foo\"" # DIFF_ARG_TYPE
96check_error "^p:kprobes/testevent $FUNCTION_FORK abcd=\\1"	# SAME_PROBE
97fi
98
99# %return suffix errors
100if grep -q "place (kretprobe): .*%return.*" README; then
101check_error 'p vfs_read^%hoge'		# BAD_ADDR_SUFFIX
102check_error 'p ^vfs_read+10%return'	# BAD_RETPROBE
103fi
104
105exit 0
106