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: <20250426160027.177173-5-mannkafai@gmail.com>
Date: Sun, 27 Apr 2025 00:00:27 +0800
From: KaFai Wan <mannkafai@...il.com>
To: song@...nel.org,
	jolsa@...nel.org,
	ast@...nel.org,
	daniel@...earbox.net,
	andrii@...nel.org,
	martin.lau@...ux.dev,
	eddyz87@...il.com,
	yonghong.song@...ux.dev,
	john.fastabend@...il.com,
	kpsingh@...nel.org,
	sdf@...ichev.me,
	haoluo@...gle.com,
	mattbobrowski@...gle.com,
	rostedt@...dmis.org,
	mhiramat@...nel.org,
	mathieu.desnoyers@...icios.com,
	davem@...emloft.net,
	edumazet@...gle.com,
	kuba@...nel.org,
	pabeni@...hat.com,
	horms@...nel.org,
	mykolal@...com,
	shuah@...nel.org
Cc: linux-kernel@...r.kernel.org,
	bpf@...r.kernel.org,
	linux-trace-kernel@...r.kernel.org,
	netdev@...r.kernel.org,
	linux-kselftest@...r.kernel.org,
	leon.hwang@...ux.dev,
	mannkafai@...il.com
Subject: [PATCH bpf-next 4/4] selftests/bpf: Add tests for get_func_[arg|arg_cnt] helpers in raw tracepoint programs

Adding tests for get_func_[arg|arg_cnt] helpers in raw tracepoint programs.
Using these helpers in raw_tp/tp_btf programs.

Signed-off-by: KaFai Wan <mannkafai@...il.com>
---
 .../bpf/prog_tests/raw_tp_get_func_args.c     | 48 +++++++++++++++++++
 .../bpf/progs/test_raw_tp_get_func_args.c     | 47 ++++++++++++++++++
 2 files changed, 95 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/raw_tp_get_func_args.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_raw_tp_get_func_args.c

diff --git a/tools/testing/selftests/bpf/prog_tests/raw_tp_get_func_args.c b/tools/testing/selftests/bpf/prog_tests/raw_tp_get_func_args.c
new file mode 100644
index 000000000000..cbe9b441d8d9
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/raw_tp_get_func_args.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <linux/bpf.h>
+#include "bpf/libbpf_internal.h"
+#include "test_raw_tp_get_func_args.skel.h"
+
+static void test_raw_tp_args(bool is_tp_btf)
+{
+	__u64 args[2] = {0x1234ULL, 0x5678ULL};
+	int expected_retval = 0x1234 + 0x5678;
+	struct test_raw_tp_get_func_args *skel;
+	LIBBPF_OPTS(bpf_test_run_opts, opts,
+		.ctx_in = args,
+		.ctx_size_in = sizeof(args),
+	);
+	int err, prog_fd;
+
+	skel = test_raw_tp_get_func_args__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "skel_open"))
+		goto cleanup;
+
+	bpf_program__set_autoattach(skel->progs.tp_btf_test, is_tp_btf);
+	bpf_program__set_autoattach(skel->progs.raw_tp_test, !is_tp_btf);
+
+	err = test_raw_tp_get_func_args__attach(skel);
+	if (!ASSERT_OK(err, "skel_attach"))
+		goto cleanup;
+
+	if (is_tp_btf)
+		prog_fd = bpf_program__fd(skel->progs.tp_btf_test);
+	else
+		prog_fd = bpf_program__fd(skel->progs.raw_tp_test);
+	err = bpf_prog_test_run_opts(prog_fd, &opts);
+	ASSERT_OK(err, "test_run");
+	ASSERT_EQ(opts.retval, expected_retval, "check_retval");
+	ASSERT_EQ(skel->bss->test_result, 1, "test_result");
+
+cleanup:
+	test_raw_tp_get_func_args__destroy(skel);
+}
+
+void test_raw_tp_get_func_args(void)
+{
+	if (test__start_subtest("raw_tp"))
+		test_raw_tp_args(false);
+	if (test__start_subtest("tp_btf"))
+		test_raw_tp_args(true);
+}
diff --git a/tools/testing/selftests/bpf/progs/test_raw_tp_get_func_args.c b/tools/testing/selftests/bpf/progs/test_raw_tp_get_func_args.c
new file mode 100644
index 000000000000..5069bbd15283
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_raw_tp_get_func_args.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+#include <errno.h>
+
+__u64 test_result = 0;
+
+static __always_inline int check_args(void *ctx, struct task_struct *task,
+				      char *comm)
+{
+	__u64 cnt = bpf_get_func_arg_cnt(ctx);
+	__u64 a = 0, b = 0, z = 0;
+	__s64 err;
+
+	if ((__u64)task != 0x1234ULL || (__u64)comm != 0x5678ULL)
+		return 0;
+
+	test_result = cnt == 2;
+
+	/* valid arguments */
+	err = bpf_get_func_arg(ctx, 0, &a);
+	test_result &= err == 0 && a == 0x1234ULL;
+
+	err = bpf_get_func_arg(ctx, 1, &b);
+	test_result &= err == 0 && b == 0x5678ULL;
+
+	/* not valid argument */
+	err = bpf_get_func_arg(ctx, 2, &z);
+	test_result &= err == -EINVAL;
+
+	return a + b;
+}
+
+SEC("raw_tp/task_rename")
+int BPF_PROG(raw_tp_test, struct task_struct *task, char *comm)
+{
+	return check_args(ctx, task, comm);
+}
+
+SEC("tp_btf/task_rename")
+int BPF_PROG(tp_btf_test, struct task_struct *task, char *comm)
+{
+	return check_args(ctx, task, comm);
+}
+
+char _license[] SEC("license") = "GPL";
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ