bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] tracing: perf_call_bpf: use struct trace_entry in struct syscall_tp_t
@ 2023-07-27 15:06 Yauheni Kaliuta
  2023-07-27 17:37 ` Yonghong Song
  0 siblings, 1 reply; 11+ messages in thread
From: Yauheni Kaliuta @ 2023-07-27 15:06 UTC (permalink / raw)
  To: bpf; +Cc: andrii, ast, Yauheni Kaliuta

bpf tracepoint program uses struct trace_event_raw_sys_enter as
argument where trace_entry is the first field. Use the same instead
of unsigned long long since if it's amended (for example by RT
patch) it accesses data with wrong offset.

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
---
 kernel/trace/trace_syscalls.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 942ddbdace4a..07f4fa395e99 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -555,12 +555,15 @@ static int perf_call_bpf_enter(struct trace_event_call *call, struct pt_regs *re
 			       struct syscall_trace_enter *rec)
 {
 	struct syscall_tp_t {
-		unsigned long long regs;
+		struct trace_entry ent;
 		unsigned long syscall_nr;
 		unsigned long args[SYSCALL_DEFINE_MAXARGS];
 	} param;
 	int i;
 
+	BUILD_BUG_ON(sizeof(param.ent) < sizeof(void *));
+
+	/* __bpf_prog_run() requires *regs as the first parameter */
 	*(struct pt_regs **)&param = regs;
 	param.syscall_nr = rec->nr;
 	for (i = 0; i < sys_data->nb_args; i++)
@@ -657,11 +660,14 @@ static int perf_call_bpf_exit(struct trace_event_call *call, struct pt_regs *reg
 			      struct syscall_trace_exit *rec)
 {
 	struct syscall_tp_t {
-		unsigned long long regs;
+		struct trace_entry ent;
 		unsigned long syscall_nr;
 		unsigned long ret;
 	} param;
 
+	BUILD_BUG_ON(sizeof(param.ent) < sizeof(void *));
+
+	/* __bpf_prog_run() requires *regs as the first parameter */
 	*(struct pt_regs **)&param = regs;
 	param.syscall_nr = rec->nr;
 	param.ret = rec->ret;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-08-01 18:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-27 15:06 [PATCH bpf-next] tracing: perf_call_bpf: use struct trace_entry in struct syscall_tp_t Yauheni Kaliuta
2023-07-27 17:37 ` Yonghong Song
2023-07-28 10:02   ` Yauheni Kaliuta
2023-07-28 14:27   ` [PATCH bpf-next v2] " Yauheni Kaliuta
2023-07-28 16:44     ` Yonghong Song
2023-07-31  8:07       ` Yauheni Kaliuta
2023-07-31 18:20         ` Yonghong Song
2023-08-01  7:49           ` Yauheni Kaliuta
2023-08-01  7:52     ` [PATCH bpf-next v3] " Yauheni Kaliuta
2023-08-01 14:31       ` Yonghong Song
2023-08-01 18:00       ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).