File perf-augmented_raw_syscalls-augment-sockaddr-arg-in-connect.patch of Package perf
106
1
From: Arnaldo Carvalho de Melo <acme@redhat.com>
2
Date: Tue, 16 Jul 2019 16:28:14 -0300
3
Subject: perf augmented_raw_syscalls: Augment sockaddr arg in 'connect'
4
MIME-Version: 1.0
5
Content-Type: text/plain; charset=UTF-8
6
Content-Transfer-Encoding: 8bit
7
Git-commit: 212b9ab6775b5f340de848b5b6eef6968ccf7f20
8
Patch-mainline: v5.4-rc1
9
References: jsc#SLE-13661
10
11
We already had a beautifier for an augmented sockaddr payload, but that
12
was when we were hooking on each syscalls:sys_enter_foo tracepoints,
13
since now we're almost doing that by doing a tail call from
14
raw_syscalls:sys_enter, its almost the same, we can reuse it straight
15
away.
16
17
# perf trace -e connec* ssh www.bla.com
18
connect(3</var/lib/sss/mc/passwd>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 0x6e) = -1 ENOENT (No such file or directory)
19
connect(3</var/lib/sss/mc/passwd>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 0x6e) = -1 ENOENT (No such file or directory)
20
connect(4<socket:[16604782]>, { .family: PF_LOCAL, path: /var/lib/sss/pipes/nss }, 0x6e) = 0
21
connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 0x6e) = -1 ENOENT (No such file or directory)
22
connect(7, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 0x6e) = -1 ENOENT (No such file or directory)
23
connect(5</etc/hosts>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 0x6e) = -1 ENOENT (No such file or directory)
24
connect(5</etc/hosts>, { .family: PF_LOCAL, path: /var/run/nscd/socket }, 0x6e) = -1 ENOENT (No such file or directory)
25
connect(5</etc/hosts>, { .family: PF_INET, port: 53, addr: 192.168.44.1 }, 0x10) = 0
26
connect(5</etc/hosts>, { .family: PF_INET, port: 22, addr: 146.112.61.108 }, 0x10) = 0
27
connect(5</etc/hosts>, { .family: PF_INET6, port: 22, addr: ::ffff:146.112.61.108 }, 0x1c) = 0
28
^C#
29
30
Cc: Adrian Hunter <adrian.hunter@intel.com>
31
Cc: Jiri Olsa <jolsa@kernel.org>
32
Cc: Luis Cláudio Gonçalves <lclaudio@redhat.com>
33
Cc: Namhyung Kim <namhyung@kernel.org>
34
Link: https://lkml.kernel.org/n/tip-5xkrbcpjsgnr3zt1aqdd7nvc@git.kernel.org
35
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
36
Signed-off-by: Tony Jones <tonyj@suse.de>
37
---
38
tools/perf/examples/bpf/augmented_raw_syscalls.c | 35 ++++++++++++++++++++----
39
1 file changed, 30 insertions(+), 5 deletions(-)
40
41
diff --git a/tools/perf/examples/bpf/augmented_raw_syscalls.c b/tools/perf/examples/bpf/augmented_raw_syscalls.c
42
index 77bb6a0edce3..d7a292d7ee2f 100644
43
--- a/tools/perf/examples/bpf/augmented_raw_syscalls.c
44
+++ b/tools/perf/examples/bpf/augmented_raw_syscalls.c
45
46
47
#include <unistd.h>
48
#include <linux/limits.h>
49
+#include <linux/socket.h>
50
#include <pid_filter.h>
51
52
/* bpf-output associated map */
53
54
55
struct augmented_args_payload {
56
struct syscall_enter_args args;
57
- struct {
58
- struct augmented_filename filename;
59
- struct augmented_filename filename2;
60
- };
61
+ union {
62
+ struct {
63
+ struct augmented_filename filename,
64
+ filename2;
65
+ };
66
+ struct sockaddr_storage saddr;
67
+ };
68
};
69
70
bpf_map(augmented_args_tmp, PERCPU_ARRAY, int, struct augmented_args_payload, 1);
71
72
}
73
74
/*
75
- * This will be tail_called from SEC("raw_syscalls:sys_enter"), so will find in
76
+ * These will be tail_called from SEC("raw_syscalls:sys_enter"), so will find in
77
* augmented_args_tmp what was read by that raw_syscalls:sys_enter and go
78
* on from there, reading the first syscall arg as a string, i.e. open's
79
* filename.
80
*/
81
+SEC("!syscalls:sys_enter_connect")
82
+int sys_enter_connect(struct syscall_enter_args *args)
83
+{
84
+ int key = 0;
85
+ struct augmented_args_payload *augmented_args = bpf_map_lookup_elem(&augmented_args_tmp, &key);
86
+ const void *sockaddr_arg = (const void *)args->args[1];
87
+ unsigned int socklen = args->args[2];
88
+ unsigned int len = sizeof(augmented_args->args);
89
+
90
+ if (augmented_args == NULL)
91
+ return 1; /* Failure: don't filter */
92
+
93
+ if (socklen > sizeof(augmented_args->saddr))
94
+ socklen = sizeof(augmented_args->saddr);
95
+
96
+ probe_read(&augmented_args->saddr, socklen, sockaddr_arg);
97
+
98
+ /* If perf_event_output fails, return non-zero so that it gets recorded unaugmented */
99
+ return perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, augmented_args, len + socklen);
100
+}
101
+
102
SEC("!syscalls:sys_enter_open")
103
int sys_enter_open(struct syscall_enter_args *args)
104
{
105
106