1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0 3 # description: Kprobe event argument syntax 4 5 [ -f kprobe_events ] || exit_unsupported # this is configurable 6 7 grep "x8/16/32/64" README > /dev/null || exit_unsupported # version issue 8 9 PROBEFUNC="vfs_read" 10 GOODREG= 11 BADREG= 12 GOODSYM="_sdata" 13 if ! grep -qw ${GOODSYM} /proc/kallsyms ; then 14 GOODSYM=$PROBEFUNC 15 fi 16 BADSYM="deaqswdefr" 17 SYMADDR=0x`grep -w ${GOODSYM} /proc/kallsyms | cut -f 1 -d " "` 18 GOODTYPE="x16" 19 BADTYPE="y16" 20 21 case `uname -m` in 22 x86_64|i[3456]86) 23 GOODREG=%ax 24 BADREG=%ex 25 ;; 26 aarch64) 27 GOODREG=%x0 28 BADREG=%ax 29 ;; 30 arm*) 31 GOODREG=%r0 32 BADREG=%ax 33 ;; 34 ppc*) 35 GOODREG=%r3 36 BADREG=%msr 37 ;; 38 *) 39 echo "Please implement other architecture here" 40 exit_untested 41 esac 42 43 test_goodarg() # Good-args 44 { 45 while [ "$1" ]; do 46 echo "p ${PROBEFUNC} $1" > kprobe_events 47 shift 1 48 done; 49 } 50 51 test_badarg() # Bad-args 52 { 53 while [ "$1" ]; do 54 ! echo "p ${PROBEFUNC} $1" > kprobe_events 55 shift 1 56 done; 57 } 58 59 echo > kprobe_events 60 61 : "Register access" 62 test_goodarg ${GOODREG} 63 test_badarg ${BADREG} 64 65 : "Symbol access" 66 test_goodarg "@${GOODSYM}" "@${SYMADDR}" "@${GOODSYM}+10" "@${GOODSYM}-10" 67 test_badarg "@" "@${BADSYM}" "@${GOODSYM}*10" "@${GOODSYM}/10" \ 68 "@${GOODSYM}%10" "@${GOODSYM}&10" "@${GOODSYM}|10" 69 70 : "Stack access" 71 test_goodarg "\$stack" "\$stack0" "\$stack1" 72 test_badarg "\$stackp" "\$stack0+10" "\$stack1-10" 73 74 : "Retval access" 75 echo "r ${PROBEFUNC} \$retval" > kprobe_events 76 ! echo "p ${PROBEFUNC} \$retval" > kprobe_events 77 78 # $comm was introduced in 4.8, older kernels reject it. 79 if grep -A1 "fetcharg:" README | grep -q '\$comm' ; then 80 : "Comm access" 81 test_goodarg "\$comm" 82 fi 83 84 : "Indirect memory access" 85 test_goodarg "+0(${GOODREG})" "-0(${GOODREG})" "+10(\$stack)" \ 86 "+0(\$stack1)" "+10(@${GOODSYM}-10)" "+0(+10(+20(\$stack)))" 87 test_badarg "+(${GOODREG})" "(${GOODREG}+10)" "-(${GOODREG})" "(${GOODREG})" \ 88 "+10(\$comm)" "+0(${GOODREG})+10" 89 90 : "Name assignment" 91 test_goodarg "varname=${GOODREG}" 92 test_badarg "varname=varname2=${GOODREG}" 93 94 : "Type syntax" 95 test_goodarg "${GOODREG}:${GOODTYPE}" 96 test_badarg "${GOODREG}::${GOODTYPE}" "${GOODREG}:${BADTYPE}" \ 97 "${GOODTYPE}:${GOODREG}" 98 99 : "Combination check" 100 101 test_goodarg "\$comm:string" "+0(\$stack):string" 102 test_badarg "\$comm:x64" "\$stack:string" "${GOODREG}:string" 103