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: <20250917072242.674528-3-zhaofuyu@vivo.com>
Date: Wed, 17 Sep 2025 15:22:41 +0800
From: Fuyu Zhao <zhaofuyu@...o.com>
To: ast@...nel.org,
	daniel@...earbox.net,
	andrii@...nel.org,
	martin.lau@...ux.dev,
	song@...nel.org,
	yonghong.song@...ux.dev,
	haoluo@...gle.com,
	jolsa@...nel.org,
	eddyz87@...il.com,
	kpsingh@...nel.org,
	sdf@...ichev.me,
	rostedt@...dmis.org,
	mhiramat@...nel.org,
	mathieu.desnoyers@...icios.com,
	shuah@...nel.org,
	willemb@...gle.com,
	kerneljasonxing@...il.com,
	paul.chaignon@...il.com,
	chen.dylane@...ux.dev,
	memxor@...il.com,
	martin.kelly@...wdstrike.com,
	zhaofuyu@...o.com,
	ameryhung@...il.com,
	linux-kernel@...r.kernel.org,
	bpf@...r.kernel.org,
	linux-trace-kernel@...r.kernel.org,
	linux-kselftest@...r.kernel.org
Cc: yikai.lin@...o.com
Subject: [RFC PATCH bpf-next v1 2/3] libbpf: Add support for BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE

Extend libbpf to support the new BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE
program type, making it available to user space applications through
the standard libbpf API.

Signed-off-by: Fuyu Zhao <zhaofuyu@...o.com>
---
 tools/include/uapi/linux/bpf.h |  2 ++
 tools/lib/bpf/bpf.c            |  1 +
 tools/lib/bpf/bpf.h            |  3 ++-
 tools/lib/bpf/libbpf.c         | 27 ++++++++++++++++++++++++++-
 tools/lib/bpf/libbpf.h         |  3 ++-
 5 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 233de8677382..7438836b3e4b 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1071,6 +1071,7 @@ enum bpf_prog_type {
 	BPF_PROG_TYPE_SK_LOOKUP,
 	BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
 	BPF_PROG_TYPE_NETFILTER,
+	BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE,
 	__MAX_BPF_PROG_TYPE
 };
 
@@ -1707,6 +1708,7 @@ union bpf_attr {
 		__u32		prog_fd;
 		__u32		:32;
 		__aligned_u64	cookie;
+		__aligned_u64   probe_name;
 	} raw_tracepoint;
 
 	struct { /* anonymous struct for BPF_BTF_LOAD */
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index ab40dbf9f020..95b73f94ce72 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -1235,6 +1235,7 @@ int bpf_raw_tracepoint_open_opts(int prog_fd, struct bpf_raw_tp_opts *opts)
 	attr.raw_tracepoint.prog_fd = prog_fd;
 	attr.raw_tracepoint.name = ptr_to_u64(OPTS_GET(opts, tp_name, NULL));
 	attr.raw_tracepoint.cookie = OPTS_GET(opts, cookie, 0);
+	attr.raw_tracepoint.probe_name = ptr_to_u64(OPTS_GET(opts, probe_name, NULL));
 
 	fd = sys_bpf_fd(BPF_RAW_TRACEPOINT_OPEN, &attr, attr_sz);
 	return libbpf_err_errno(fd);
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 7252150e7ad3..0ebedbd99fe5 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -630,9 +630,10 @@ struct bpf_raw_tp_opts {
 	size_t sz; /* size of this struct for forward/backward compatibility */
 	const char *tp_name;
 	__u64 cookie;
+	const char *probe_name;
 	size_t :0;
 };
-#define bpf_raw_tp_opts__last_field cookie
+#define bpf_raw_tp_opts__last_field probe_name
 
 LIBBPF_API int bpf_raw_tracepoint_open_opts(int prog_fd, struct bpf_raw_tp_opts *opts);
 LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index fe4fc5438678..ce67c917ba59 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9557,6 +9557,8 @@ static const struct bpf_sec_def section_defs[] = {
 	SEC_DEF("raw_tp+",		RAW_TRACEPOINT, 0, SEC_NONE, attach_raw_tp),
 	SEC_DEF("raw_tracepoint.w+",	RAW_TRACEPOINT_WRITABLE, 0, SEC_NONE, attach_raw_tp),
 	SEC_DEF("raw_tp.w+",		RAW_TRACEPOINT_WRITABLE, 0, SEC_NONE, attach_raw_tp),
+	SEC_DEF("raw_tracepoint.o+",	RAW_TRACEPOINT_OVERRIDE, 0, SEC_NONE, attach_raw_tp),
+	SEC_DEF("raw_tp.o+",		RAW_TRACEPOINT_OVERRIDE, 0, SEC_NONE, attach_raw_tp),
 	SEC_DEF("tp_btf+",		TRACING, BPF_TRACE_RAW_TP, SEC_ATTACH_BTF, attach_trace),
 	SEC_DEF("fentry+",		TRACING, BPF_TRACE_FENTRY, SEC_ATTACH_BTF, attach_trace),
 	SEC_DEF("fmod_ret+",		TRACING, BPF_MODIFY_RETURN, SEC_ATTACH_BTF, attach_trace),
@@ -12684,6 +12686,7 @@ bpf_program__attach_raw_tracepoint_opts(const struct bpf_program *prog,
 
 	raw_opts.tp_name = tp_name;
 	raw_opts.cookie = OPTS_GET(opts, cookie, 0);
+	raw_opts.probe_name = OPTS_GET(opts, probe_name, NULL);
 	pfd = bpf_raw_tracepoint_open_opts(prog_fd, &raw_opts);
 	if (pfd < 0) {
 		pfd = -errno;
@@ -12704,14 +12707,18 @@ struct bpf_link *bpf_program__attach_raw_tracepoint(const struct bpf_program *pr
 
 static int attach_raw_tp(const struct bpf_program *prog, long cookie, struct bpf_link **link)
 {
+	LIBBPF_OPTS(bpf_raw_tracepoint_opts, raw_opts);
 	static const char *const prefixes[] = {
 		"raw_tp",
 		"raw_tracepoint",
 		"raw_tp.w",
 		"raw_tracepoint.w",
+		"raw_tp.o",
+		"raw_tracepoint.o",
 	};
 	size_t i;
 	const char *tp_name = NULL;
+	char *dup = NULL, *sep = NULL;
 
 	*link = NULL;
 
@@ -12739,7 +12746,25 @@ static int attach_raw_tp(const struct bpf_program *prog, long cookie, struct bpf
 		return -EINVAL;
 	}
 
-	*link = bpf_program__attach_raw_tracepoint(prog, tp_name);
+	if (prog->type == BPF_PROG_TYPE_RAW_TRACEPOINT_OVERRIDE) {
+		dup = strdup(tp_name);
+		if (!dup)
+			return -ENOMEM;
+
+		sep = strchr(dup, ':');
+		if (!sep) {
+			free(dup);
+			return -EINVAL;
+		}
+		*sep = '\0';
+
+		tp_name = dup;
+		raw_opts.probe_name = sep + 1,
+		*link = bpf_program__attach_raw_tracepoint_opts(prog, tp_name, &raw_opts);
+		free(dup);
+	} else {
+		*link = bpf_program__attach_raw_tracepoint(prog, tp_name);
+	}
 	return libbpf_get_error(*link);
 }
 
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 2e91148d9b44..f4e9cb819b75 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -820,9 +820,10 @@ bpf_program__attach_tracepoint_opts(const struct bpf_program *prog,
 struct bpf_raw_tracepoint_opts {
 	size_t sz; /* size of this struct for forward/backward compatibility */
 	__u64 cookie;
+	const char *probe_name;
 	size_t :0;
 };
-#define bpf_raw_tracepoint_opts__last_field cookie
+#define bpf_raw_tracepoint_opts__last_field probe_name
 
 LIBBPF_API struct bpf_link *
 bpf_program__attach_raw_tracepoint(const struct bpf_program *prog,
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ