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: <20240618152652.3446472-6-howardchu95@gmail.com>
Date: Tue, 18 Jun 2024 23:26:52 +0800
From: Howard Chu <howardchu95@...il.com>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Jiri Olsa <jolsa@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Ian Rogers <irogers@...gle.com>,
	Adrian Hunter <adrian.hunter@...el.com>,
	Kan Liang <kan.liang@...ux.intel.com>,
	linux-kernel@...r.kernel.org,
	linux-perf-users@...r.kernel.org
Subject: [PATCH v1 5/5] perf trace: Add test for enum augmentation

Check for vmlinux's existence in sysfs as prerequisite.

Compile and run a script which calls landlock_add_rule syscall,
trace the syscall to judge if the output is desirable.

Trace the non-syscall tracepoint 'timer:hrtimer_init' and
'timer:hrtimer_start', see if the 'mode' argument is augmented,
the 'mode' enum argument has the prefix of 'HRTIMER_MODE_'
in its name.

Signed-off-by: Howard Chu <howardchu95@...il.com>
---
 tools/perf/tests/shell/trace_btf_enum.sh | 104 +++++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100755 tools/perf/tests/shell/trace_btf_enum.sh

diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh
new file mode 100755
index 000000000000..14c73b0b594d
--- /dev/null
+++ b/tools/perf/tests/shell/trace_btf_enum.sh
@@ -0,0 +1,104 @@
+#!/bin/sh
+# perf trace enum augmentation tests
+# SPDX-License-Identifier: GPL-2.0
+
+err=0
+set -e
+
+syscall="landlock_add_rule"
+non_syscall="timer:hrtimer_init,timer:hrtimer_start"
+
+landlock_script=$(mktemp /tmp/landlock-XXXXX.c)
+landlock_ex=$(echo $landlock_script | sed -E 's/(.*).c$/\1/g')
+
+landlock_fd=24
+landlock_flags=25
+
+. "$(dirname $0)"/lib/probe.sh
+skip_if_no_perf_trace || exit 2
+
+enum_aug_prereq() {
+  echo "Checking perf trace enum augmentation prerequisites"
+  if ! ls /sys/kernel/btf/vmlinux 1>/dev/null 2>&1
+  then
+    echo "trace+enum test [Skipped missing vmlinux BTF support]"
+    err=2
+    return
+  fi
+}
+
+prepare_landlock_script() {
+  echo "Preparing script for ${syscall} syscall"
+
+  cat > $landlock_script << EOF
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <linux/landlock.h>
+#include <sys/syscall.h>
+
+int main()
+{
+	int fd = ${landlock_fd};
+	int flags = ${landlock_flags};
+	struct landlock_path_beneath_attr path_beneath_attr = {
+	    .allowed_access = LANDLOCK_ACCESS_FS_READ_FILE,
+	};
+	struct landlock_net_port_attr net_port_attr = {
+	    .allowed_access = LANDLOCK_ACCESS_NET_CONNECT_TCP,
+	    .port = 443,
+	};
+
+	syscall(SYS_landlock_add_rule, fd, LANDLOCK_RULE_PATH_BENEATH,
+		&path_beneath_attr, flags);
+
+	syscall(SYS_landlock_add_rule, fd, LANDLOCK_RULE_NET_PORT,
+		&net_port_attr, flags);
+
+	return 0;
+}
+EOF
+
+  gcc $landlock_script -o $landlock_ex
+}
+
+trace_landlock() {
+  echo "Tracing syscall ${syscall}"
+  if perf trace -e $syscall $landlock_ex 2>&1 | \
+     grep -q -E ".*landlock_add_rule\(ruleset_fd: ${landlock_fd}, rule_type: (LANDLOCK_RULE_PATH_BENEATH|LANDLOCK_RULE_NET_PORT), rule_attr: 0x[a-f0-9]+, flags: ${landlock_flags}\) = -1.*"
+  then
+    err=0
+  else
+    err=1
+  fi
+}
+
+trace_non_syscall() {
+  echo "Tracing non-syscall tracepoint ${non-syscall}"
+  if perf trace -e $non_syscall --max-events=1 2>&1 | \
+     grep -q -E '.*timer:hrtimer_.*\(.*mode: HRTIMER_MODE_.*\)$'
+  then
+    err=0
+  else
+    err=1
+  fi
+}
+
+cleanup() {
+  rm -f $landlock_script $landlock_ex
+}
+
+enum_aug_prereq
+
+prepare_landlock_script
+
+if [ $err = 0 ]; then
+  trace_landlock
+fi
+
+if [ $err = 0 ]; then
+  trace_non_syscall
+fi
+
+cleanup
+
+exit $err
-- 
2.45.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ