lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230127130541.1250865-14-chenguokai17@mails.ucas.ac.cn>
Date:   Fri, 27 Jan 2023 21:05:41 +0800
From:   Chen Guokai <chenguokai17@...ls.ucas.ac.cn>
To:     paul.walmsley@...ive.com, palmer@...belt.com,
        aou@...s.berkeley.edu, rostedt@...dmis.org, mingo@...hat.com,
        sfr@...b.auug.org.au
Cc:     linux-riscv@...ts.infradead.org, linux-kernel@...r.kernel.org,
        liaochang1@...wei.com
Subject: [PATCH v6 13/13] selftest/kprobes: Add testcase for kprobe SYM[+offs]

From: Liao Chang <liaochang1@...wei.com>

This testcase set multiple kprobes to the function that contains a
series of complex opcode pattern, it helps discover some subtle bugs in
the instruction decoder and kprobe jump optimization.

Signed-off-by: Liao Chang <liaochang1@...wei.com>
---
 .../ftrace/test.d/kprobe/kprobe_sym_offs.tc   | 49 +++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/kprobe/kprobe_sym_offs.tc

diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_sym_offs.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_sym_offs.tc
new file mode 100644
index 000000000000..0007bec48308
--- /dev/null
+++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_sym_offs.tc
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: Kprobe dynamic event with offset
+# requires: kprobe_events
+TARGET_FUNC=vfs_write
+
+dec_addr() { # hexaddr
+  printf "%d" "0x"`echo $1 | tail -c 8`
+}
+
+set_offs() { # target next
+  SYMADDR=$1
+  ENDADDR=$2
+  A1=`dec_addr $SYMADDR`
+  A2=`dec_addr $ENDADDR`
+  NEXT=`expr $A2 - $A1` # offset to previous symbol
+}
+
+# Get the instruction number between two contiguous symbols
+set_offs `grep -A1 -w ${TARGET_FUNC} /proc/kallsyms | cut -f 1 -d " " | xargs`
+
+# Instruction length depends on the machine architecute.
+case `uname -m` in
+  arm64) LEN=4;;
+  riscv32|riscv64) LEN=2;;
+  *) LEN=2;;
+esac
+
+N=0
+OFFS=0
+echo "Setup up kprobes on each instruction in function $TARGET_FUNC"
+while true; do
+  N=$(($N+1))
+  ! echo p ${TARGET_FUNC}+${OFFS} >> kprobe_events
+  OFFS=$(($OFFS+$LEN))
+  test $OFFS -eq $NEXT && break
+done
+
+L=`cat kprobe_events | wc -l`
+echo "The number of kprobes events ($L) not $N in function $TARGET_FUNC"
+
+echo 1 > events/kprobes/enable
+# Trigger vfs_write to test kprobes
+cat kprobe_events >> $testlog
+echo 0 > events/kprobes/enable
+echo > kprobe_events
+echo "Waiting for unoptimizing & freeing"
+sleep 5
+echo "Done"
-- 
2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ