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]
Date:   Tue, 13 Apr 2021 14:15:16 +0200
From:   Jiri Olsa <jolsa@...nel.org>
To:     Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andriin@...com>
Cc:     netdev@...r.kernel.org, bpf@...r.kernel.org,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...omium.org>, Daniel Xu <dxu@...uu.xyz>,
        Steven Rostedt <rostedt@...dmis.org>,
        Jesper Brouer <jbrouer@...hat.com>,
        Toke Høiland-Jørgensen <toke@...hat.com>,
        Viktor Malik <vmalik@...hat.com>
Subject: [PATCHv2 RFC bpf-next 7/7] selftests/bpf: Add ftrace probe test

Adding simple ftrace probe test that configures ftrace
probe and verifies the 'ip' argument matches the probed
functions addresses.

Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
 .../selftests/bpf/prog_tests/ftrace_test.c    | 48 +++++++++++++++++++
 .../testing/selftests/bpf/progs/ftrace_test.c | 17 +++++++
 2 files changed, 65 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/ftrace_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/ftrace_test.c

diff --git a/tools/testing/selftests/bpf/prog_tests/ftrace_test.c b/tools/testing/selftests/bpf/prog_tests/ftrace_test.c
new file mode 100644
index 000000000000..34d6dbe88251
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/ftrace_test.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "ftrace_test.skel.h"
+
+void test_ftrace_test(void)
+{
+	struct ftrace_test *ftrace_skel = NULL;
+	__u32 duration = 0, retval;
+	int err, prog_fd;
+	__u64 *ips;
+	int idx, i;
+
+	ftrace_skel = ftrace_test__open_and_load();
+	if (!ASSERT_OK_PTR(ftrace_skel, "ftrace_skel_load"))
+		goto cleanup;
+
+	err = ftrace_test__attach(ftrace_skel);
+	if (!ASSERT_OK(err, "ftrace_attach"))
+		goto cleanup;
+
+	prog_fd = bpf_program__fd(ftrace_skel->progs.test);
+	err = bpf_prog_test_run(prog_fd, 1, NULL, 0,
+				NULL, NULL, &retval, &duration);
+	ASSERT_OK(err || retval, "test_run");
+
+	ips = ftrace_skel->bss->ips;
+	idx = ftrace_skel->bss->idx;
+
+	if (!ASSERT_EQ(idx, 8, "idx"))
+		goto cleanup;
+
+	for (i = 0; i < 8; i++) {
+		unsigned long long addr;
+		char func[50];
+
+		snprintf(func, sizeof(func), "bpf_fentry_test%d", i + 1);
+
+		err = kallsyms_find(func, &addr);
+		if (!ASSERT_OK(err, "kallsyms_find"))
+			goto cleanup;
+
+		if (!ASSERT_EQ(ips[i],  addr, "ips_addr"))
+			goto cleanup;
+	}
+
+cleanup:
+	ftrace_test__destroy(ftrace_skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/ftrace_test.c b/tools/testing/selftests/bpf/progs/ftrace_test.c
new file mode 100644
index 000000000000..b2a55aa10318
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/ftrace_test.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+__u64 ips[9] = { };
+unsigned int idx = 0;
+
+SEC("fentry.ftrace/bpf_fentry_test*")
+int BPF_PROG(test, __u64 ip, __u64 parent_ip)
+{
+	if (idx >= 0 && idx < 8)
+		ips[idx++] = ip;
+	return 0;
+}
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ