Commit | Line | Data |
---|---|---|
259b6cb3 MD |
1 | /* |
2 | * lttng-syscalls.c | |
3 | * | |
2faf7d1b | 4 | * LTTng syscall probes. |
259b6cb3 | 5 | * |
886d51a3 MD |
6 | * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
7 | * | |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; only | |
11 | * version 2.1 of the License. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
259b6cb3 MD |
21 | */ |
22 | ||
23 | #include <linux/module.h> | |
24 | #include <linux/slab.h> | |
6333ace3 | 25 | #include <linux/compat.h> |
abc0446a | 26 | #include <linux/err.h> |
80f87dd2 | 27 | #include <linux/bitmap.h> |
7ca580f8 MD |
28 | #include <linux/in.h> |
29 | #include <linux/in6.h> | |
2d2464bd | 30 | #include <linux/seq_file.h> |
d4291869 | 31 | #include <linux/stringify.h> |
082d4946 MD |
32 | #include <linux/file.h> |
33 | #include <linux/anon_inodes.h> | |
259b6cb3 MD |
34 | #include <asm/ptrace.h> |
35 | #include <asm/syscall.h> | |
36 | ||
241ae9a8 MD |
37 | #include <lib/bitfield.h> |
38 | #include <wrapper/tracepoint.h> | |
39 | #include <wrapper/file.h> | |
40 | #include <wrapper/rcu.h> | |
41 | #include <lttng-events.h> | |
259b6cb3 | 42 | |
6333ace3 | 43 | #ifndef CONFIG_COMPAT |
bfa949bf MD |
44 | # ifndef is_compat_task |
45 | # define is_compat_task() (0) | |
46 | # endif | |
6333ace3 MD |
47 | #endif |
48 | ||
1aa3298b MD |
49 | /* in_compat_syscall appears in kernel 4.6. */ |
50 | #ifndef in_compat_syscall | |
51 | #define in_compat_syscall() is_compat_task() | |
52 | #endif | |
53 | ||
5b7ac358 MD |
54 | enum sc_type { |
55 | SC_TYPE_ENTRY, | |
56 | SC_TYPE_EXIT, | |
57 | SC_TYPE_COMPAT_ENTRY, | |
58 | SC_TYPE_COMPAT_EXIT, | |
59 | }; | |
60 | ||
d4291869 MD |
61 | #define SYSCALL_ENTRY_TOK syscall_entry_ |
62 | #define COMPAT_SYSCALL_ENTRY_TOK compat_syscall_entry_ | |
63 | #define SYSCALL_EXIT_TOK syscall_exit_ | |
64 | #define COMPAT_SYSCALL_EXIT_TOK compat_syscall_exit_ | |
65 | ||
66 | #define SYSCALL_ENTRY_STR __stringify(SYSCALL_ENTRY_TOK) | |
67 | #define COMPAT_SYSCALL_ENTRY_STR __stringify(COMPAT_SYSCALL_ENTRY_TOK) | |
68 | #define SYSCALL_EXIT_STR __stringify(SYSCALL_EXIT_TOK) | |
69 | #define COMPAT_SYSCALL_EXIT_STR __stringify(COMPAT_SYSCALL_EXIT_TOK) | |
5b7ac358 | 70 | |
a93244f8 | 71 | static |
2faf7d1b | 72 | void syscall_entry_probe(void *__data, struct pt_regs *regs, long id); |
5b7ac358 MD |
73 | static |
74 | void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret); | |
259b6cb3 | 75 | |
3a523f5b MD |
76 | /* |
77 | * Forward declarations for old kernels. | |
78 | */ | |
79 | struct mmsghdr; | |
80 | struct rlimit64; | |
81 | struct oldold_utsname; | |
82 | struct old_utsname; | |
83 | struct sel_arg_struct; | |
84 | struct mmap_arg_struct; | |
c0b71117 | 85 | struct file_handle; |
a292e6f1 | 86 | struct user_msghdr; |
3a523f5b | 87 | |
80f87dd2 MD |
88 | #ifdef IA32_NR_syscalls |
89 | #define NR_compat_syscalls IA32_NR_syscalls | |
90 | #else | |
91 | #define NR_compat_syscalls NR_syscalls | |
92 | #endif | |
93 | ||
259b6cb3 MD |
94 | /* |
95 | * Create LTTng tracepoint probes. | |
96 | */ | |
97 | #define LTTNG_PACKAGE_BUILD | |
98 | #define CREATE_TRACE_POINTS | |
2655f9ad | 99 | #define TP_MODULE_NOINIT |
c075712b | 100 | #define TRACE_INCLUDE_PATH instrumentation/syscalls/headers |
259b6cb3 | 101 | |
a93244f8 MD |
102 | #define PARAMS(args...) args |
103 | ||
5b7ac358 | 104 | /* Handle unknown syscalls */ |
72a52753 | 105 | #undef TRACE_SYSTEM |
5b7ac358 | 106 | #define TRACE_SYSTEM syscalls_unknown |
241ae9a8 | 107 | #include <instrumentation/syscalls/headers/syscalls_unknown.h> |
5b7ac358 MD |
108 | #undef TRACE_SYSTEM |
109 | ||
fc4f7161 MD |
110 | #define SC_ENTER |
111 | ||
fc4f7161 MD |
112 | #undef sc_exit |
113 | #define sc_exit(...) | |
b75d00c4 MD |
114 | #undef sc_in |
115 | #define sc_in(...) __VA_ARGS__ | |
116 | #undef sc_out | |
117 | #define sc_out(...) | |
118 | #undef sc_inout | |
119 | #define sc_inout(...) __VA_ARGS__ | |
5b7ac358 MD |
120 | |
121 | /* Hijack probe callback for system call enter */ | |
a93244f8 | 122 | #undef TP_PROBE_CB |
259b6cb3 | 123 | #define TP_PROBE_CB(_template) &syscall_entry_probe |
57ede728 | 124 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
d4291869 | 125 | LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 126 | PARAMS(_fields)) |
265822ae | 127 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
d4291869 | 128 | LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae MD |
129 | PARAMS(_locvar), PARAMS(_code_pre), \ |
130 | PARAMS(_fields), PARAMS(_code_post)) | |
57ede728 MD |
131 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
132 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields)) | |
cb3ef14c | 133 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
d4291869 | 134 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name) |
141ddf28 MD |
135 | /* Enumerations only defined at first inclusion. */ |
136 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) \ | |
137 | LTTNG_TRACEPOINT_ENUM(_name, PARAMS(_values)) | |
a93244f8 | 138 | #undef TRACE_SYSTEM |
d4291869 | 139 | #define TRACE_SYSTEM syscall_entry_integers |
5b7ac358 | 140 | #define TRACE_INCLUDE_FILE syscalls_integers |
241ae9a8 | 141 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
5b7ac358 | 142 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 143 | #undef TRACE_SYSTEM |
d4291869 | 144 | #define TRACE_SYSTEM syscall_entry_pointers |
5b7ac358 | 145 | #define TRACE_INCLUDE_FILE syscalls_pointers |
241ae9a8 | 146 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> |
5b7ac358 | 147 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 148 | #undef TRACE_SYSTEM |
141ddf28 | 149 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
150 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
151 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
152 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
153 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
5b7ac358 | 154 | #undef TP_PROBE_CB |
3bc29f0a MD |
155 | #undef _TRACE_SYSCALLS_INTEGERS_H |
156 | #undef _TRACE_SYSCALLS_POINTERS_H | |
5b7ac358 MD |
157 | |
158 | /* Hijack probe callback for compat system call enter */ | |
a93244f8 | 159 | #define TP_PROBE_CB(_template) &syscall_entry_probe |
57ede728 | 160 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
d4291869 | 161 | LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 162 | PARAMS(_fields)) |
265822ae | 163 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
d4291869 | 164 | LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae | 165 | PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) |
57ede728 MD |
166 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
167 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields)) | |
cb3ef14c | 168 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
d4291869 MD |
169 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \ |
170 | compat_syscall_entry_##_name) | |
141ddf28 MD |
171 | /* Enumerations only defined at inital inclusion (not here). */ |
172 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) | |
d4291869 | 173 | #define TRACE_SYSTEM compat_syscall_entry_integers |
5b7ac358 | 174 | #define TRACE_INCLUDE_FILE compat_syscalls_integers |
241ae9a8 | 175 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
5b7ac358 MD |
176 | #undef TRACE_INCLUDE_FILE |
177 | #undef TRACE_SYSTEM | |
d4291869 | 178 | #define TRACE_SYSTEM compat_syscall_entry_pointers |
5b7ac358 | 179 | #define TRACE_INCLUDE_FILE compat_syscalls_pointers |
241ae9a8 | 180 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> |
5b7ac358 MD |
181 | #undef TRACE_INCLUDE_FILE |
182 | #undef TRACE_SYSTEM | |
141ddf28 | 183 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
184 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
185 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
186 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
187 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
5b7ac358 | 188 | #undef TP_PROBE_CB |
3bc29f0a MD |
189 | #undef _TRACE_SYSCALLS_INTEGERS_H |
190 | #undef _TRACE_SYSCALLS_POINTERS_H | |
5b7ac358 | 191 | |
fc4f7161 MD |
192 | #undef SC_ENTER |
193 | ||
194 | #define SC_EXIT | |
195 | ||
fc4f7161 MD |
196 | #undef sc_exit |
197 | #define sc_exit(...) __VA_ARGS__ | |
b75d00c4 MD |
198 | #undef sc_in |
199 | #define sc_in(...) | |
200 | #undef sc_out | |
201 | #define sc_out(...) __VA_ARGS__ | |
202 | #undef sc_inout | |
203 | #define sc_inout(...) __VA_ARGS__ | |
5b7ac358 MD |
204 | |
205 | /* Hijack probe callback for system call exit */ | |
206 | #define TP_PROBE_CB(_template) &syscall_exit_probe | |
57ede728 | 207 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
3bc29f0a | 208 | LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 209 | PARAMS(_fields)) |
265822ae | 210 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
3bc29f0a | 211 | LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae | 212 | PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) |
57ede728 MD |
213 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
214 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields)) | |
cb3ef14c MD |
215 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
216 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \ | |
5b7ac358 | 217 | syscall_exit_##_name) |
141ddf28 MD |
218 | /* Enumerations only defined at inital inclusion (not here). */ |
219 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) | |
5b7ac358 MD |
220 | #define TRACE_SYSTEM syscall_exit_integers |
221 | #define TRACE_INCLUDE_FILE syscalls_integers | |
241ae9a8 | 222 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
5b7ac358 MD |
223 | #undef TRACE_INCLUDE_FILE |
224 | #undef TRACE_SYSTEM | |
225 | #define TRACE_SYSTEM syscall_exit_pointers | |
226 | #define TRACE_INCLUDE_FILE syscalls_pointers | |
241ae9a8 | 227 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> |
5b7ac358 MD |
228 | #undef TRACE_INCLUDE_FILE |
229 | #undef TRACE_SYSTEM | |
141ddf28 | 230 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
231 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
232 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
233 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
234 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
5b7ac358 | 235 | #undef TP_PROBE_CB |
3bc29f0a MD |
236 | #undef _TRACE_SYSCALLS_INTEGERS_H |
237 | #undef _TRACE_SYSCALLS_POINTERS_H | |
5b7ac358 MD |
238 | |
239 | ||
240 | /* Hijack probe callback for compat system call exit */ | |
241 | #define TP_PROBE_CB(_template) &syscall_exit_probe | |
57ede728 | 242 | #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \ |
3bc29f0a | 243 | LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
57ede728 | 244 | PARAMS(_fields)) |
265822ae | 245 | #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code_pre, _fields, _code_post) \ |
3bc29f0a | 246 | LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \ |
265822ae | 247 | PARAMS(_locvar), PARAMS(_code_pre), PARAMS(_fields), PARAMS(_code_post)) |
57ede728 MD |
248 | #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \ |
249 | LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields)) | |
cb3ef14c | 250 | #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \ |
3bc29f0a | 251 | LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \ |
5b7ac358 | 252 | compat_syscall_exit_##_name) |
141ddf28 MD |
253 | /* Enumerations only defined at inital inclusion (not here). */ |
254 | #define SC_LTTNG_TRACEPOINT_ENUM(_name, _values) | |
5b7ac358 MD |
255 | #define TRACE_SYSTEM compat_syscall_exit_integers |
256 | #define TRACE_INCLUDE_FILE compat_syscalls_integers | |
241ae9a8 | 257 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
5b7ac358 | 258 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 259 | #undef TRACE_SYSTEM |
5b7ac358 MD |
260 | #define TRACE_SYSTEM compat_syscall_exit_pointers |
261 | #define TRACE_INCLUDE_FILE compat_syscalls_pointers | |
241ae9a8 | 262 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> |
5b7ac358 | 263 | #undef TRACE_INCLUDE_FILE |
a93244f8 | 264 | #undef TRACE_SYSTEM |
141ddf28 | 265 | #undef SC_LTTNG_TRACEPOINT_ENUM |
cb3ef14c MD |
266 | #undef SC_LTTNG_TRACEPOINT_EVENT_CODE |
267 | #undef SC_LTTNG_TRACEPOINT_EVENT | |
268 | #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS | |
269 | #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS | |
a93244f8 | 270 | #undef TP_PROBE_CB |
3bc29f0a MD |
271 | #undef _TRACE_SYSCALLS_INTEGERS_H |
272 | #undef _TRACE_SYSCALLS_POINTERS_H | |
5b7ac358 | 273 | |
fc4f7161 | 274 | #undef SC_EXIT |
259b6cb3 | 275 | |
2655f9ad | 276 | #undef TP_MODULE_NOINIT |
259b6cb3 MD |
277 | #undef LTTNG_PACKAGE_BUILD |
278 | #undef CREATE_TRACE_POINTS | |
279 | ||
a93244f8 MD |
280 | struct trace_syscall_entry { |
281 | void *func; | |
282 | const struct lttng_event_desc *desc; | |
283 | const struct lttng_event_field *fields; | |
284 | unsigned int nrargs; | |
285 | }; | |
286 | ||
287 | #define CREATE_SYSCALL_TABLE | |
288 | ||
fc4f7161 MD |
289 | #define SC_ENTER |
290 | ||
291 | #undef sc_exit | |
292 | #define sc_exit(...) | |
293 | ||
259b6cb3 | 294 | #undef TRACE_SYSCALL_TABLE |
f7bdf4db | 295 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ |
259b6cb3 | 296 | [ _nr ] = { \ |
d4291869 | 297 | .func = __event_probe__syscall_entry_##_template, \ |
259b6cb3 | 298 | .nrargs = (_nrargs), \ |
d4291869 MD |
299 | .fields = __event_fields___syscall_entry_##_template, \ |
300 | .desc = &__event_desc___syscall_entry_##_name, \ | |
259b6cb3 MD |
301 | }, |
302 | ||
5b7ac358 | 303 | /* Syscall enter tracing table */ |
49c50022 | 304 | static const struct trace_syscall_entry sc_table[] = { |
241ae9a8 MD |
305 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
306 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> | |
259b6cb3 MD |
307 | }; |
308 | ||
a93244f8 MD |
309 | #undef TRACE_SYSCALL_TABLE |
310 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ | |
311 | [ _nr ] = { \ | |
d4291869 | 312 | .func = __event_probe__compat_syscall_entry_##_template, \ |
a93244f8 | 313 | .nrargs = (_nrargs), \ |
d4291869 MD |
314 | .fields = __event_fields___compat_syscall_entry_##_template, \ |
315 | .desc = &__event_desc___compat_syscall_entry_##_name, \ | |
a93244f8 MD |
316 | }, |
317 | ||
5b7ac358 | 318 | /* Compat syscall enter table */ |
a93244f8 | 319 | const struct trace_syscall_entry compat_sc_table[] = { |
241ae9a8 MD |
320 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
321 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> | |
a93244f8 | 322 | }; |
259b6cb3 | 323 | |
fc4f7161 MD |
324 | #undef SC_ENTER |
325 | ||
326 | #define SC_EXIT | |
327 | ||
328 | #undef sc_exit | |
329 | #define sc_exit(...) __VA_ARGS__ | |
330 | ||
5b7ac358 MD |
331 | #undef TRACE_SYSCALL_TABLE |
332 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ | |
333 | [ _nr ] = { \ | |
334 | .func = __event_probe__syscall_exit_##_template, \ | |
335 | .nrargs = (_nrargs), \ | |
336 | .fields = __event_fields___syscall_exit_##_template, \ | |
337 | .desc = &__event_desc___syscall_exit_##_name, \ | |
338 | }, | |
339 | ||
340 | /* Syscall exit table */ | |
341 | static const struct trace_syscall_entry sc_exit_table[] = { | |
241ae9a8 MD |
342 | #include <instrumentation/syscalls/headers/syscalls_integers.h> |
343 | #include <instrumentation/syscalls/headers/syscalls_pointers.h> | |
5b7ac358 MD |
344 | }; |
345 | ||
346 | #undef TRACE_SYSCALL_TABLE | |
347 | #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \ | |
348 | [ _nr ] = { \ | |
349 | .func = __event_probe__compat_syscall_exit_##_template, \ | |
350 | .nrargs = (_nrargs), \ | |
351 | .fields = __event_fields___compat_syscall_exit_##_template, \ | |
352 | .desc = &__event_desc___compat_syscall_exit_##_name, \ | |
353 | }, | |
354 | ||
355 | /* Compat syscall exit table */ | |
356 | const struct trace_syscall_entry compat_sc_exit_table[] = { | |
241ae9a8 MD |
357 | #include <instrumentation/syscalls/headers/compat_syscalls_integers.h> |
358 | #include <instrumentation/syscalls/headers/compat_syscalls_pointers.h> | |
5b7ac358 MD |
359 | }; |
360 | ||
fc4f7161 MD |
361 | #undef SC_EXIT |
362 | ||
a93244f8 | 363 | #undef CREATE_SYSCALL_TABLE |
2faf7d1b | 364 | |
80f87dd2 MD |
365 | struct lttng_syscall_filter { |
366 | DECLARE_BITMAP(sc, NR_syscalls); | |
367 | DECLARE_BITMAP(sc_compat, NR_compat_syscalls); | |
368 | }; | |
369 | ||
a90917c3 | 370 | static void syscall_entry_unknown(struct lttng_event *event, |
f405cfce MD |
371 | struct pt_regs *regs, unsigned int id) |
372 | { | |
373 | unsigned long args[UNKNOWN_SYSCALL_NRARGS]; | |
f405cfce | 374 | |
f405cfce | 375 | syscall_get_arguments(current, regs, 0, UNKNOWN_SYSCALL_NRARGS, args); |
1aa3298b | 376 | if (unlikely(in_compat_syscall())) |
d4291869 | 377 | __event_probe__compat_syscall_entry_unknown(event, id, args); |
a93244f8 | 378 | else |
d4291869 | 379 | __event_probe__syscall_entry_unknown(event, id, args); |
f405cfce MD |
380 | } |
381 | ||
2faf7d1b | 382 | void syscall_entry_probe(void *__data, struct pt_regs *regs, long id) |
259b6cb3 | 383 | { |
a90917c3 MD |
384 | struct lttng_channel *chan = __data; |
385 | struct lttng_event *event, *unknown_event; | |
49c50022 MD |
386 | const struct trace_syscall_entry *table, *entry; |
387 | size_t table_len; | |
259b6cb3 | 388 | |
1aa3298b | 389 | if (unlikely(in_compat_syscall())) { |
80f87dd2 MD |
390 | struct lttng_syscall_filter *filter; |
391 | ||
49e2f4c4 | 392 | filter = lttng_rcu_dereference(chan->sc_filter); |
80f87dd2 | 393 | if (filter) { |
74f7b56a | 394 | if (id < 0 || id >= NR_compat_syscalls |
80f87dd2 MD |
395 | || !test_bit(id, filter->sc_compat)) { |
396 | /* System call filtered out. */ | |
397 | return; | |
398 | } | |
399 | } | |
49c50022 | 400 | table = compat_sc_table; |
a93244f8 | 401 | table_len = ARRAY_SIZE(compat_sc_table); |
49c50022 MD |
402 | unknown_event = chan->sc_compat_unknown; |
403 | } else { | |
80f87dd2 MD |
404 | struct lttng_syscall_filter *filter; |
405 | ||
49e2f4c4 | 406 | filter = lttng_rcu_dereference(chan->sc_filter); |
80f87dd2 | 407 | if (filter) { |
74f7b56a | 408 | if (id < 0 || id >= NR_syscalls |
80f87dd2 MD |
409 | || !test_bit(id, filter->sc)) { |
410 | /* System call filtered out. */ | |
411 | return; | |
412 | } | |
413 | } | |
49c50022 MD |
414 | table = sc_table; |
415 | table_len = ARRAY_SIZE(sc_table); | |
416 | unknown_event = chan->sc_unknown; | |
b76dc1a0 | 417 | } |
74f7b56a | 418 | if (unlikely(id < 0 || id >= table_len)) { |
49c50022 | 419 | syscall_entry_unknown(unknown_event, regs, id); |
259b6cb3 | 420 | return; |
f405cfce | 421 | } |
1aa3298b | 422 | if (unlikely(in_compat_syscall())) |
49c50022 MD |
423 | event = chan->compat_sc_table[id]; |
424 | else | |
425 | event = chan->sc_table[id]; | |
f405cfce | 426 | if (unlikely(!event)) { |
49c50022 | 427 | syscall_entry_unknown(unknown_event, regs, id); |
f405cfce MD |
428 | return; |
429 | } | |
49c50022 | 430 | entry = &table[id]; |
f405cfce | 431 | WARN_ON_ONCE(!entry); |
259b6cb3 MD |
432 | |
433 | switch (entry->nrargs) { | |
434 | case 0: | |
435 | { | |
436 | void (*fptr)(void *__data) = entry->func; | |
437 | ||
438 | fptr(event); | |
439 | break; | |
440 | } | |
441 | case 1: | |
442 | { | |
443 | void (*fptr)(void *__data, unsigned long arg0) = entry->func; | |
444 | unsigned long args[1]; | |
445 | ||
446 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
447 | fptr(event, args[0]); | |
448 | break; | |
449 | } | |
450 | case 2: | |
451 | { | |
452 | void (*fptr)(void *__data, | |
453 | unsigned long arg0, | |
454 | unsigned long arg1) = entry->func; | |
455 | unsigned long args[2]; | |
456 | ||
457 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
458 | fptr(event, args[0], args[1]); | |
459 | break; | |
460 | } | |
461 | case 3: | |
462 | { | |
463 | void (*fptr)(void *__data, | |
464 | unsigned long arg0, | |
465 | unsigned long arg1, | |
466 | unsigned long arg2) = entry->func; | |
467 | unsigned long args[3]; | |
468 | ||
469 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
470 | fptr(event, args[0], args[1], args[2]); | |
471 | break; | |
472 | } | |
473 | case 4: | |
474 | { | |
475 | void (*fptr)(void *__data, | |
476 | unsigned long arg0, | |
477 | unsigned long arg1, | |
478 | unsigned long arg2, | |
479 | unsigned long arg3) = entry->func; | |
480 | unsigned long args[4]; | |
481 | ||
482 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
483 | fptr(event, args[0], args[1], args[2], args[3]); | |
484 | break; | |
485 | } | |
486 | case 5: | |
487 | { | |
488 | void (*fptr)(void *__data, | |
489 | unsigned long arg0, | |
490 | unsigned long arg1, | |
491 | unsigned long arg2, | |
492 | unsigned long arg3, | |
493 | unsigned long arg4) = entry->func; | |
494 | unsigned long args[5]; | |
495 | ||
496 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
497 | fptr(event, args[0], args[1], args[2], args[3], args[4]); | |
498 | break; | |
499 | } | |
500 | case 6: | |
501 | { | |
502 | void (*fptr)(void *__data, | |
503 | unsigned long arg0, | |
504 | unsigned long arg1, | |
505 | unsigned long arg2, | |
506 | unsigned long arg3, | |
507 | unsigned long arg4, | |
508 | unsigned long arg5) = entry->func; | |
509 | unsigned long args[6]; | |
510 | ||
511 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
512 | fptr(event, args[0], args[1], args[2], | |
513 | args[3], args[4], args[5]); | |
514 | break; | |
515 | } | |
516 | default: | |
517 | break; | |
518 | } | |
519 | } | |
520 | ||
5b7ac358 | 521 | static void syscall_exit_unknown(struct lttng_event *event, |
74f7b56a | 522 | struct pt_regs *regs, int id, long ret) |
5b7ac358 MD |
523 | { |
524 | unsigned long args[UNKNOWN_SYSCALL_NRARGS]; | |
525 | ||
526 | syscall_get_arguments(current, regs, 0, UNKNOWN_SYSCALL_NRARGS, args); | |
1aa3298b | 527 | if (unlikely(in_compat_syscall())) |
5b7ac358 MD |
528 | __event_probe__compat_syscall_exit_unknown(event, id, ret, |
529 | args); | |
530 | else | |
531 | __event_probe__syscall_exit_unknown(event, id, ret, args); | |
532 | } | |
533 | ||
534 | void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret) | |
535 | { | |
536 | struct lttng_channel *chan = __data; | |
537 | struct lttng_event *event, *unknown_event; | |
538 | const struct trace_syscall_entry *table, *entry; | |
539 | size_t table_len; | |
540 | long id; | |
541 | ||
542 | id = syscall_get_nr(current, regs); | |
1aa3298b | 543 | if (unlikely(in_compat_syscall())) { |
5b7ac358 MD |
544 | struct lttng_syscall_filter *filter; |
545 | ||
49e2f4c4 | 546 | filter = lttng_rcu_dereference(chan->sc_filter); |
5b7ac358 | 547 | if (filter) { |
74f7b56a | 548 | if (id < 0 || id >= NR_compat_syscalls |
5b7ac358 MD |
549 | || !test_bit(id, filter->sc_compat)) { |
550 | /* System call filtered out. */ | |
551 | return; | |
552 | } | |
553 | } | |
554 | table = compat_sc_exit_table; | |
555 | table_len = ARRAY_SIZE(compat_sc_exit_table); | |
556 | unknown_event = chan->compat_sc_exit_unknown; | |
557 | } else { | |
558 | struct lttng_syscall_filter *filter; | |
559 | ||
49e2f4c4 | 560 | filter = lttng_rcu_dereference(chan->sc_filter); |
5b7ac358 | 561 | if (filter) { |
74f7b56a | 562 | if (id < 0 || id >= NR_syscalls |
5b7ac358 MD |
563 | || !test_bit(id, filter->sc)) { |
564 | /* System call filtered out. */ | |
565 | return; | |
566 | } | |
567 | } | |
568 | table = sc_exit_table; | |
569 | table_len = ARRAY_SIZE(sc_exit_table); | |
570 | unknown_event = chan->sc_exit_unknown; | |
571 | } | |
74f7b56a | 572 | if (unlikely(id < 0 || id >= table_len)) { |
5b7ac358 MD |
573 | syscall_exit_unknown(unknown_event, regs, id, ret); |
574 | return; | |
575 | } | |
1aa3298b | 576 | if (unlikely(in_compat_syscall())) |
5b7ac358 MD |
577 | event = chan->compat_sc_exit_table[id]; |
578 | else | |
579 | event = chan->sc_exit_table[id]; | |
580 | if (unlikely(!event)) { | |
581 | syscall_exit_unknown(unknown_event, regs, id, ret); | |
582 | return; | |
583 | } | |
584 | entry = &table[id]; | |
585 | WARN_ON_ONCE(!entry); | |
586 | ||
587 | switch (entry->nrargs) { | |
588 | case 0: | |
589 | { | |
fc4f7161 | 590 | void (*fptr)(void *__data, long ret) = entry->func; |
5b7ac358 | 591 | |
fc4f7161 | 592 | fptr(event, ret); |
5b7ac358 MD |
593 | break; |
594 | } | |
595 | case 1: | |
596 | { | |
597 | void (*fptr)(void *__data, | |
fc4f7161 | 598 | long ret, |
5b7ac358 MD |
599 | unsigned long arg0) = entry->func; |
600 | unsigned long args[1]; | |
601 | ||
602 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
fc4f7161 | 603 | fptr(event, ret, args[0]); |
5b7ac358 MD |
604 | break; |
605 | } | |
606 | case 2: | |
607 | { | |
608 | void (*fptr)(void *__data, | |
fc4f7161 | 609 | long ret, |
5b7ac358 MD |
610 | unsigned long arg0, |
611 | unsigned long arg1) = entry->func; | |
612 | unsigned long args[2]; | |
613 | ||
614 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
fc4f7161 | 615 | fptr(event, ret, args[0], args[1]); |
5b7ac358 MD |
616 | break; |
617 | } | |
618 | case 3: | |
619 | { | |
620 | void (*fptr)(void *__data, | |
fc4f7161 | 621 | long ret, |
5b7ac358 MD |
622 | unsigned long arg0, |
623 | unsigned long arg1, | |
624 | unsigned long arg2) = entry->func; | |
625 | unsigned long args[3]; | |
626 | ||
627 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
fc4f7161 | 628 | fptr(event, ret, args[0], args[1], args[2]); |
5b7ac358 MD |
629 | break; |
630 | } | |
631 | case 4: | |
632 | { | |
633 | void (*fptr)(void *__data, | |
fc4f7161 | 634 | long ret, |
5b7ac358 MD |
635 | unsigned long arg0, |
636 | unsigned long arg1, | |
637 | unsigned long arg2, | |
638 | unsigned long arg3) = entry->func; | |
639 | unsigned long args[4]; | |
640 | ||
641 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
fc4f7161 | 642 | fptr(event, ret, args[0], args[1], args[2], args[3]); |
5b7ac358 MD |
643 | break; |
644 | } | |
645 | case 5: | |
646 | { | |
647 | void (*fptr)(void *__data, | |
fc4f7161 | 648 | long ret, |
5b7ac358 MD |
649 | unsigned long arg0, |
650 | unsigned long arg1, | |
651 | unsigned long arg2, | |
652 | unsigned long arg3, | |
653 | unsigned long arg4) = entry->func; | |
654 | unsigned long args[5]; | |
655 | ||
656 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
fc4f7161 | 657 | fptr(event, ret, args[0], args[1], args[2], args[3], args[4]); |
5b7ac358 MD |
658 | break; |
659 | } | |
660 | case 6: | |
661 | { | |
662 | void (*fptr)(void *__data, | |
fc4f7161 | 663 | long ret, |
5b7ac358 MD |
664 | unsigned long arg0, |
665 | unsigned long arg1, | |
666 | unsigned long arg2, | |
667 | unsigned long arg3, | |
668 | unsigned long arg4, | |
669 | unsigned long arg5) = entry->func; | |
670 | unsigned long args[6]; | |
671 | ||
672 | syscall_get_arguments(current, regs, 0, entry->nrargs, args); | |
fc4f7161 | 673 | fptr(event, ret, args[0], args[1], args[2], |
5b7ac358 MD |
674 | args[3], args[4], args[5]); |
675 | break; | |
676 | } | |
677 | default: | |
678 | break; | |
679 | } | |
680 | } | |
681 | ||
33a39a3c MD |
682 | /* |
683 | * noinline to diminish caller stack size. | |
684 | * Should be called with sessions lock held. | |
685 | */ | |
49c50022 MD |
686 | static |
687 | int fill_table(const struct trace_syscall_entry *table, size_t table_len, | |
5b7ac358 MD |
688 | struct lttng_event **chan_table, struct lttng_channel *chan, |
689 | void *filter, enum sc_type type) | |
259b6cb3 | 690 | { |
2a0c4816 | 691 | const struct lttng_event_desc *desc; |
259b6cb3 | 692 | unsigned int i; |
49c50022 MD |
693 | |
694 | /* Allocate events for each syscall, insert into table */ | |
695 | for (i = 0; i < table_len; i++) { | |
696 | struct lttng_kernel_event ev; | |
2a0c4816 | 697 | desc = table[i].desc; |
49c50022 MD |
698 | |
699 | if (!desc) { | |
700 | /* Unknown syscall */ | |
701 | continue; | |
702 | } | |
703 | /* | |
704 | * Skip those already populated by previous failed | |
705 | * register for this channel. | |
706 | */ | |
707 | if (chan_table[i]) | |
708 | continue; | |
709 | memset(&ev, 0, sizeof(ev)); | |
5b7ac358 MD |
710 | switch (type) { |
711 | case SC_TYPE_ENTRY: | |
712 | strncpy(ev.name, SYSCALL_ENTRY_STR, | |
713 | LTTNG_KERNEL_SYM_NAME_LEN); | |
714 | break; | |
715 | case SC_TYPE_EXIT: | |
716 | strncpy(ev.name, SYSCALL_EXIT_STR, | |
717 | LTTNG_KERNEL_SYM_NAME_LEN); | |
718 | break; | |
719 | case SC_TYPE_COMPAT_ENTRY: | |
720 | strncpy(ev.name, COMPAT_SYSCALL_ENTRY_STR, | |
721 | LTTNG_KERNEL_SYM_NAME_LEN); | |
722 | break; | |
723 | case SC_TYPE_COMPAT_EXIT: | |
724 | strncpy(ev.name, COMPAT_SYSCALL_EXIT_STR, | |
725 | LTTNG_KERNEL_SYM_NAME_LEN); | |
726 | break; | |
727 | default: | |
728 | BUG_ON(1); | |
729 | break; | |
730 | } | |
731 | strncat(ev.name, desc->name, | |
732 | LTTNG_KERNEL_SYM_NAME_LEN - strlen(ev.name) - 1); | |
f8695253 | 733 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
33a39a3c MD |
734 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
735 | chan_table[i] = _lttng_event_create(chan, &ev, filter, | |
3c997079 | 736 | desc, ev.instrumentation); |
abc0446a MD |
737 | WARN_ON_ONCE(!chan_table[i]); |
738 | if (IS_ERR(chan_table[i])) { | |
49c50022 MD |
739 | /* |
740 | * If something goes wrong in event registration | |
741 | * after the first one, we have no choice but to | |
742 | * leave the previous events in there, until | |
743 | * deleted by session teardown. | |
744 | */ | |
abc0446a | 745 | return PTR_ERR(chan_table[i]); |
49c50022 MD |
746 | } |
747 | } | |
748 | return 0; | |
749 | } | |
750 | ||
33a39a3c MD |
751 | /* |
752 | * Should be called with sessions lock held. | |
753 | */ | |
a90917c3 | 754 | int lttng_syscalls_register(struct lttng_channel *chan, void *filter) |
49c50022 | 755 | { |
2a0c4816 | 756 | struct lttng_kernel_event ev; |
259b6cb3 MD |
757 | int ret; |
758 | ||
759 | wrapper_vmalloc_sync_all(); | |
259b6cb3 MD |
760 | |
761 | if (!chan->sc_table) { | |
762 | /* create syscall table mapping syscall to events */ | |
a90917c3 | 763 | chan->sc_table = kzalloc(sizeof(struct lttng_event *) |
259b6cb3 MD |
764 | * ARRAY_SIZE(sc_table), GFP_KERNEL); |
765 | if (!chan->sc_table) | |
766 | return -ENOMEM; | |
767 | } | |
5b7ac358 MD |
768 | if (!chan->sc_exit_table) { |
769 | /* create syscall table mapping syscall to events */ | |
770 | chan->sc_exit_table = kzalloc(sizeof(struct lttng_event *) | |
771 | * ARRAY_SIZE(sc_exit_table), GFP_KERNEL); | |
772 | if (!chan->sc_exit_table) | |
773 | return -ENOMEM; | |
774 | } | |
775 | ||
259b6cb3 | 776 | |
49c50022 MD |
777 | #ifdef CONFIG_COMPAT |
778 | if (!chan->compat_sc_table) { | |
779 | /* create syscall table mapping compat syscall to events */ | |
a90917c3 | 780 | chan->compat_sc_table = kzalloc(sizeof(struct lttng_event *) |
a93244f8 | 781 | * ARRAY_SIZE(compat_sc_table), GFP_KERNEL); |
49c50022 MD |
782 | if (!chan->compat_sc_table) |
783 | return -ENOMEM; | |
784 | } | |
5b7ac358 MD |
785 | |
786 | if (!chan->compat_sc_exit_table) { | |
787 | /* create syscall table mapping compat syscall to events */ | |
788 | chan->compat_sc_exit_table = kzalloc(sizeof(struct lttng_event *) | |
789 | * ARRAY_SIZE(compat_sc_exit_table), GFP_KERNEL); | |
790 | if (!chan->compat_sc_exit_table) | |
791 | return -ENOMEM; | |
792 | } | |
49c50022 | 793 | #endif |
f405cfce | 794 | if (!chan->sc_unknown) { |
f405cfce | 795 | const struct lttng_event_desc *desc = |
d4291869 | 796 | &__event_desc___syscall_entry_unknown; |
2f804c0a | 797 | |
f405cfce | 798 | memset(&ev, 0, sizeof(ev)); |
f8695253 MD |
799 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); |
800 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
801 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
802 | chan->sc_unknown = _lttng_event_create(chan, &ev, filter, | |
3c997079 MD |
803 | desc, |
804 | ev.instrumentation); | |
abc0446a MD |
805 | WARN_ON_ONCE(!chan->sc_unknown); |
806 | if (IS_ERR(chan->sc_unknown)) { | |
807 | return PTR_ERR(chan->sc_unknown); | |
f405cfce MD |
808 | } |
809 | } | |
810 | ||
b76dc1a0 | 811 | if (!chan->sc_compat_unknown) { |
b76dc1a0 | 812 | const struct lttng_event_desc *desc = |
d4291869 | 813 | &__event_desc___compat_syscall_entry_unknown; |
b76dc1a0 MD |
814 | |
815 | memset(&ev, 0, sizeof(ev)); | |
f8695253 MD |
816 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); |
817 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
818 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
819 | chan->sc_compat_unknown = _lttng_event_create(chan, &ev, filter, | |
3c997079 MD |
820 | desc, |
821 | ev.instrumentation); | |
abc0446a MD |
822 | WARN_ON_ONCE(!chan->sc_unknown); |
823 | if (IS_ERR(chan->sc_compat_unknown)) { | |
824 | return PTR_ERR(chan->sc_compat_unknown); | |
b76dc1a0 MD |
825 | } |
826 | } | |
827 | ||
5b7ac358 | 828 | if (!chan->compat_sc_exit_unknown) { |
2f804c0a | 829 | const struct lttng_event_desc *desc = |
5b7ac358 | 830 | &__event_desc___compat_syscall_exit_unknown; |
2f804c0a MD |
831 | |
832 | memset(&ev, 0, sizeof(ev)); | |
f8695253 MD |
833 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); |
834 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
835 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
836 | chan->compat_sc_exit_unknown = _lttng_event_create(chan, &ev, | |
3c997079 MD |
837 | filter, desc, |
838 | ev.instrumentation); | |
5b7ac358 MD |
839 | WARN_ON_ONCE(!chan->compat_sc_exit_unknown); |
840 | if (IS_ERR(chan->compat_sc_exit_unknown)) { | |
841 | return PTR_ERR(chan->compat_sc_exit_unknown); | |
842 | } | |
843 | } | |
844 | ||
845 | if (!chan->sc_exit_unknown) { | |
846 | const struct lttng_event_desc *desc = | |
847 | &__event_desc___syscall_exit_unknown; | |
848 | ||
849 | memset(&ev, 0, sizeof(ev)); | |
850 | strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN); | |
851 | ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
33a39a3c MD |
852 | ev.instrumentation = LTTNG_KERNEL_SYSCALL; |
853 | chan->sc_exit_unknown = _lttng_event_create(chan, &ev, filter, | |
3c997079 | 854 | desc, ev.instrumentation); |
5b7ac358 MD |
855 | WARN_ON_ONCE(!chan->sc_exit_unknown); |
856 | if (IS_ERR(chan->sc_exit_unknown)) { | |
857 | return PTR_ERR(chan->sc_exit_unknown); | |
2f804c0a MD |
858 | } |
859 | } | |
860 | ||
49c50022 | 861 | ret = fill_table(sc_table, ARRAY_SIZE(sc_table), |
5b7ac358 MD |
862 | chan->sc_table, chan, filter, SC_TYPE_ENTRY); |
863 | if (ret) | |
864 | return ret; | |
865 | ret = fill_table(sc_exit_table, ARRAY_SIZE(sc_exit_table), | |
866 | chan->sc_exit_table, chan, filter, SC_TYPE_EXIT); | |
49c50022 MD |
867 | if (ret) |
868 | return ret; | |
5b7ac358 | 869 | |
49c50022 | 870 | #ifdef CONFIG_COMPAT |
a93244f8 | 871 | ret = fill_table(compat_sc_table, ARRAY_SIZE(compat_sc_table), |
5b7ac358 MD |
872 | chan->compat_sc_table, chan, filter, |
873 | SC_TYPE_COMPAT_ENTRY); | |
874 | if (ret) | |
875 | return ret; | |
876 | ret = fill_table(compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table), | |
877 | chan->compat_sc_exit_table, chan, filter, | |
878 | SC_TYPE_COMPAT_EXIT); | |
49c50022 MD |
879 | if (ret) |
880 | return ret; | |
881 | #endif | |
80f87dd2 MD |
882 | if (!chan->sys_enter_registered) { |
883 | ret = lttng_wrapper_tracepoint_probe_register("sys_enter", | |
884 | (void *) syscall_entry_probe, chan); | |
885 | if (ret) | |
886 | return ret; | |
887 | chan->sys_enter_registered = 1; | |
888 | } | |
63728b02 MD |
889 | /* |
890 | * We change the name of sys_exit tracepoint due to namespace | |
891 | * conflict with sys_exit syscall entry. | |
892 | */ | |
80f87dd2 MD |
893 | if (!chan->sys_exit_registered) { |
894 | ret = lttng_wrapper_tracepoint_probe_register("sys_exit", | |
5b7ac358 | 895 | (void *) syscall_exit_probe, chan); |
80f87dd2 MD |
896 | if (ret) { |
897 | WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter", | |
898 | (void *) syscall_entry_probe, chan)); | |
899 | return ret; | |
900 | } | |
901 | chan->sys_exit_registered = 1; | |
63728b02 | 902 | } |
259b6cb3 MD |
903 | return ret; |
904 | } | |
905 | ||
906 | /* | |
907 | * Only called at session destruction. | |
908 | */ | |
a90917c3 | 909 | int lttng_syscalls_unregister(struct lttng_channel *chan) |
259b6cb3 MD |
910 | { |
911 | int ret; | |
912 | ||
913 | if (!chan->sc_table) | |
914 | return 0; | |
80f87dd2 MD |
915 | if (chan->sys_enter_registered) { |
916 | ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit", | |
5b7ac358 | 917 | (void *) syscall_exit_probe, chan); |
80f87dd2 MD |
918 | if (ret) |
919 | return ret; | |
920 | chan->sys_enter_registered = 0; | |
921 | } | |
922 | if (chan->sys_exit_registered) { | |
923 | ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter", | |
924 | (void *) syscall_entry_probe, chan); | |
925 | if (ret) | |
926 | return ret; | |
927 | chan->sys_exit_registered = 0; | |
928 | } | |
a90917c3 | 929 | /* lttng_event destroy will be performed by lttng_session_destroy() */ |
259b6cb3 | 930 | kfree(chan->sc_table); |
5b7ac358 | 931 | kfree(chan->sc_exit_table); |
49c50022 MD |
932 | #ifdef CONFIG_COMPAT |
933 | kfree(chan->compat_sc_table); | |
5b7ac358 | 934 | kfree(chan->compat_sc_exit_table); |
49c50022 | 935 | #endif |
80f87dd2 MD |
936 | kfree(chan->sc_filter); |
937 | return 0; | |
938 | } | |
939 | ||
940 | static | |
941 | int get_syscall_nr(const char *syscall_name) | |
942 | { | |
943 | int syscall_nr = -1; | |
944 | int i; | |
945 | ||
946 | for (i = 0; i < ARRAY_SIZE(sc_table); i++) { | |
947 | const struct trace_syscall_entry *entry; | |
5b7ac358 | 948 | const char *it_name; |
80f87dd2 MD |
949 | |
950 | entry = &sc_table[i]; | |
951 | if (!entry->desc) | |
952 | continue; | |
5b7ac358 MD |
953 | it_name = entry->desc->name; |
954 | it_name += strlen(SYSCALL_ENTRY_STR); | |
955 | if (!strcmp(syscall_name, it_name)) { | |
80f87dd2 MD |
956 | syscall_nr = i; |
957 | break; | |
958 | } | |
959 | } | |
960 | return syscall_nr; | |
961 | } | |
962 | ||
963 | static | |
964 | int get_compat_syscall_nr(const char *syscall_name) | |
965 | { | |
966 | int syscall_nr = -1; | |
967 | int i; | |
968 | ||
969 | for (i = 0; i < ARRAY_SIZE(compat_sc_table); i++) { | |
970 | const struct trace_syscall_entry *entry; | |
5b7ac358 | 971 | const char *it_name; |
80f87dd2 MD |
972 | |
973 | entry = &compat_sc_table[i]; | |
974 | if (!entry->desc) | |
975 | continue; | |
5b7ac358 MD |
976 | it_name = entry->desc->name; |
977 | it_name += strlen(COMPAT_SYSCALL_ENTRY_STR); | |
978 | if (!strcmp(syscall_name, it_name)) { | |
80f87dd2 MD |
979 | syscall_nr = i; |
980 | break; | |
981 | } | |
982 | } | |
983 | return syscall_nr; | |
984 | } | |
985 | ||
12e579db MD |
986 | static |
987 | uint32_t get_sc_tables_len(void) | |
988 | { | |
989 | return ARRAY_SIZE(sc_table) + ARRAY_SIZE(compat_sc_table); | |
990 | } | |
991 | ||
80f87dd2 MD |
992 | int lttng_syscall_filter_enable(struct lttng_channel *chan, |
993 | const char *name) | |
994 | { | |
995 | int syscall_nr, compat_syscall_nr, ret; | |
996 | struct lttng_syscall_filter *filter; | |
997 | ||
998 | WARN_ON_ONCE(!chan->sc_table); | |
999 | ||
1000 | if (!name) { | |
1001 | /* Enable all system calls by removing filter */ | |
1002 | if (chan->sc_filter) { | |
1003 | filter = chan->sc_filter; | |
1004 | rcu_assign_pointer(chan->sc_filter, NULL); | |
1005 | synchronize_trace(); | |
1006 | kfree(filter); | |
1007 | } | |
1008 | chan->syscall_all = 1; | |
1009 | return 0; | |
1010 | } | |
1011 | ||
1012 | if (!chan->sc_filter) { | |
1013 | if (chan->syscall_all) { | |
1014 | /* | |
1015 | * All syscalls are already enabled. | |
1016 | */ | |
1017 | return -EEXIST; | |
1018 | } | |
1019 | filter = kzalloc(sizeof(struct lttng_syscall_filter), | |
1020 | GFP_KERNEL); | |
1021 | if (!filter) | |
1022 | return -ENOMEM; | |
1023 | } else { | |
1024 | filter = chan->sc_filter; | |
1025 | } | |
1026 | syscall_nr = get_syscall_nr(name); | |
1027 | compat_syscall_nr = get_compat_syscall_nr(name); | |
1028 | if (syscall_nr < 0 && compat_syscall_nr < 0) { | |
1029 | ret = -ENOENT; | |
1030 | goto error; | |
1031 | } | |
1032 | if (syscall_nr >= 0) { | |
1033 | if (test_bit(syscall_nr, filter->sc)) { | |
1034 | ret = -EEXIST; | |
1035 | goto error; | |
1036 | } | |
1037 | bitmap_set(filter->sc, syscall_nr, 1); | |
1038 | } | |
1039 | if (compat_syscall_nr >= 0) { | |
1040 | if (test_bit(compat_syscall_nr, filter->sc_compat)) { | |
1041 | ret = -EEXIST; | |
1042 | goto error; | |
1043 | } | |
1044 | bitmap_set(filter->sc_compat, compat_syscall_nr, 1); | |
1045 | } | |
1046 | if (!chan->sc_filter) | |
1047 | rcu_assign_pointer(chan->sc_filter, filter); | |
1048 | return 0; | |
1049 | ||
1050 | error: | |
1051 | if (!chan->sc_filter) | |
1052 | kfree(filter); | |
1053 | return ret; | |
1054 | } | |
1055 | ||
1056 | int lttng_syscall_filter_disable(struct lttng_channel *chan, | |
1057 | const char *name) | |
1058 | { | |
1059 | int syscall_nr, compat_syscall_nr, ret; | |
1060 | struct lttng_syscall_filter *filter; | |
1061 | ||
1062 | WARN_ON_ONCE(!chan->sc_table); | |
1063 | ||
1064 | if (!chan->sc_filter) { | |
bcde0d5b MD |
1065 | if (!chan->syscall_all) |
1066 | return -EEXIST; | |
80f87dd2 MD |
1067 | filter = kzalloc(sizeof(struct lttng_syscall_filter), |
1068 | GFP_KERNEL); | |
1069 | if (!filter) | |
1070 | return -ENOMEM; | |
1071 | /* Trace all system calls, then apply disable. */ | |
1072 | bitmap_set(filter->sc, 0, NR_syscalls); | |
1073 | bitmap_set(filter->sc_compat, 0, NR_compat_syscalls); | |
1074 | } else { | |
1075 | filter = chan->sc_filter; | |
1076 | } | |
1077 | ||
72814741 | 1078 | if (!name) { |
404e87bf MD |
1079 | /* Fail if all syscalls are already disabled. */ |
1080 | if (bitmap_empty(filter->sc, NR_syscalls) | |
1081 | && bitmap_empty(filter->sc_compat, | |
1082 | NR_compat_syscalls)) { | |
1083 | ret = -EEXIST; | |
1084 | goto error; | |
1085 | } | |
1086 | ||
72814741 MD |
1087 | /* Disable all system calls */ |
1088 | bitmap_clear(filter->sc, 0, NR_syscalls); | |
1089 | bitmap_clear(filter->sc_compat, 0, NR_compat_syscalls); | |
1090 | goto apply_filter; | |
1091 | } | |
80f87dd2 MD |
1092 | syscall_nr = get_syscall_nr(name); |
1093 | compat_syscall_nr = get_compat_syscall_nr(name); | |
1094 | if (syscall_nr < 0 && compat_syscall_nr < 0) { | |
1095 | ret = -ENOENT; | |
1096 | goto error; | |
1097 | } | |
1098 | if (syscall_nr >= 0) { | |
cecef7f8 | 1099 | if (!test_bit(syscall_nr, filter->sc)) { |
80f87dd2 MD |
1100 | ret = -EEXIST; |
1101 | goto error; | |
1102 | } | |
cecef7f8 | 1103 | bitmap_clear(filter->sc, syscall_nr, 1); |
80f87dd2 MD |
1104 | } |
1105 | if (compat_syscall_nr >= 0) { | |
cecef7f8 | 1106 | if (!test_bit(compat_syscall_nr, filter->sc_compat)) { |
80f87dd2 MD |
1107 | ret = -EEXIST; |
1108 | goto error; | |
1109 | } | |
cecef7f8 | 1110 | bitmap_clear(filter->sc_compat, compat_syscall_nr, 1); |
80f87dd2 | 1111 | } |
72814741 | 1112 | apply_filter: |
80f87dd2 MD |
1113 | if (!chan->sc_filter) |
1114 | rcu_assign_pointer(chan->sc_filter, filter); | |
1115 | chan->syscall_all = 0; | |
259b6cb3 | 1116 | return 0; |
80f87dd2 MD |
1117 | |
1118 | error: | |
1119 | if (!chan->sc_filter) | |
1120 | kfree(filter); | |
1121 | return ret; | |
259b6cb3 | 1122 | } |
2d2464bd MD |
1123 | |
1124 | static | |
1125 | const struct trace_syscall_entry *syscall_list_get_entry(loff_t *pos) | |
1126 | { | |
1127 | const struct trace_syscall_entry *entry; | |
1128 | int iter = 0; | |
1129 | ||
1130 | for (entry = sc_table; | |
1131 | entry < sc_table + ARRAY_SIZE(sc_table); | |
1132 | entry++) { | |
1133 | if (iter++ >= *pos) | |
1134 | return entry; | |
1135 | } | |
1136 | for (entry = compat_sc_table; | |
1137 | entry < compat_sc_table + ARRAY_SIZE(compat_sc_table); | |
1138 | entry++) { | |
1139 | if (iter++ >= *pos) | |
1140 | return entry; | |
1141 | } | |
1142 | /* End of list */ | |
1143 | return NULL; | |
1144 | } | |
1145 | ||
1146 | static | |
1147 | void *syscall_list_start(struct seq_file *m, loff_t *pos) | |
1148 | { | |
1149 | return (void *) syscall_list_get_entry(pos); | |
1150 | } | |
1151 | ||
1152 | static | |
1153 | void *syscall_list_next(struct seq_file *m, void *p, loff_t *ppos) | |
1154 | { | |
1155 | (*ppos)++; | |
1156 | return (void *) syscall_list_get_entry(ppos); | |
1157 | } | |
1158 | ||
1159 | static | |
1160 | void syscall_list_stop(struct seq_file *m, void *p) | |
1161 | { | |
1162 | } | |
1163 | ||
12e579db MD |
1164 | static |
1165 | int get_sc_table(const struct trace_syscall_entry *entry, | |
1166 | const struct trace_syscall_entry **table, | |
1167 | unsigned int *bitness) | |
1168 | { | |
1169 | if (entry >= sc_table && entry < sc_table + ARRAY_SIZE(sc_table)) { | |
1170 | if (bitness) | |
1171 | *bitness = BITS_PER_LONG; | |
1172 | if (table) | |
1173 | *table = sc_table; | |
1174 | return 0; | |
1175 | } | |
1176 | if (!(entry >= compat_sc_table | |
1177 | && entry < compat_sc_table + ARRAY_SIZE(compat_sc_table))) { | |
1178 | return -EINVAL; | |
1179 | } | |
1180 | if (bitness) | |
1181 | *bitness = 32; | |
1182 | if (table) | |
1183 | *table = compat_sc_table; | |
1184 | return 0; | |
1185 | } | |
1186 | ||
2d2464bd MD |
1187 | static |
1188 | int syscall_list_show(struct seq_file *m, void *p) | |
1189 | { | |
1190 | const struct trace_syscall_entry *table, *entry = p; | |
1191 | unsigned int bitness; | |
d4291869 | 1192 | unsigned long index; |
12e579db | 1193 | int ret; |
d4291869 | 1194 | const char *name; |
2d2464bd | 1195 | |
12e579db MD |
1196 | ret = get_sc_table(entry, &table, &bitness); |
1197 | if (ret) | |
1198 | return ret; | |
f4855b46 MD |
1199 | if (!entry->desc) |
1200 | return 0; | |
d4291869 MD |
1201 | if (table == sc_table) { |
1202 | index = entry - table; | |
1203 | name = &entry->desc->name[strlen(SYSCALL_ENTRY_STR)]; | |
1204 | } else { | |
1205 | index = (entry - table) + ARRAY_SIZE(sc_table); | |
1206 | name = &entry->desc->name[strlen(COMPAT_SYSCALL_ENTRY_STR)]; | |
1207 | } | |
12e579db | 1208 | seq_printf(m, "syscall { index = %lu; name = %s; bitness = %u; };\n", |
d4291869 | 1209 | index, name, bitness); |
2d2464bd MD |
1210 | return 0; |
1211 | } | |
1212 | ||
1213 | static | |
1214 | const struct seq_operations lttng_syscall_list_seq_ops = { | |
1215 | .start = syscall_list_start, | |
1216 | .next = syscall_list_next, | |
1217 | .stop = syscall_list_stop, | |
1218 | .show = syscall_list_show, | |
1219 | }; | |
1220 | ||
1221 | static | |
1222 | int lttng_syscall_list_open(struct inode *inode, struct file *file) | |
1223 | { | |
1224 | return seq_open(file, <tng_syscall_list_seq_ops); | |
1225 | } | |
1226 | ||
1227 | const struct file_operations lttng_syscall_list_fops = { | |
1228 | .owner = THIS_MODULE, | |
1229 | .open = lttng_syscall_list_open, | |
1230 | .read = seq_read, | |
1231 | .llseek = seq_lseek, | |
1232 | .release = seq_release, | |
1233 | }; | |
12e579db MD |
1234 | |
1235 | long lttng_channel_syscall_mask(struct lttng_channel *channel, | |
1236 | struct lttng_kernel_syscall_mask __user *usyscall_mask) | |
1237 | { | |
1238 | uint32_t len, sc_tables_len, bitmask_len; | |
1239 | int ret = 0, bit; | |
1240 | char *tmp_mask; | |
1241 | struct lttng_syscall_filter *filter; | |
1242 | ||
1243 | ret = get_user(len, &usyscall_mask->len); | |
1244 | if (ret) | |
1245 | return ret; | |
1246 | sc_tables_len = get_sc_tables_len(); | |
1247 | bitmask_len = ALIGN(sc_tables_len, 8) >> 3; | |
1248 | if (len < sc_tables_len) { | |
1249 | return put_user(sc_tables_len, &usyscall_mask->len); | |
1250 | } | |
1251 | /* Array is large enough, we can copy array to user-space. */ | |
1252 | tmp_mask = kzalloc(bitmask_len, GFP_KERNEL); | |
1253 | if (!tmp_mask) | |
1254 | return -ENOMEM; | |
1255 | filter = channel->sc_filter; | |
1256 | ||
1257 | for (bit = 0; bit < ARRAY_SIZE(sc_table); bit++) { | |
2f25059d MD |
1258 | bool state; |
1259 | ||
1260 | if (channel->sc_table) { | |
1261 | if (filter) | |
1262 | state = test_bit(bit, filter->sc); | |
1263 | else | |
1264 | state = 1; | |
1265 | } else { | |
1266 | state = 0; | |
1267 | } | |
1268 | bt_bitfield_write_be(tmp_mask, char, bit, 1, state); | |
12e579db MD |
1269 | } |
1270 | for (; bit < sc_tables_len; bit++) { | |
2f25059d MD |
1271 | bool state; |
1272 | ||
1273 | if (channel->compat_sc_table) { | |
1274 | if (filter) | |
1275 | state = test_bit(bit - ARRAY_SIZE(sc_table), | |
1276 | filter->sc_compat); | |
1277 | else | |
1278 | state = 1; | |
1279 | } else { | |
1280 | state = 0; | |
1281 | } | |
1282 | bt_bitfield_write_be(tmp_mask, char, bit, 1, state); | |
12e579db MD |
1283 | } |
1284 | if (copy_to_user(usyscall_mask->mask, tmp_mask, bitmask_len)) | |
1285 | ret = -EFAULT; | |
1286 | kfree(tmp_mask); | |
1287 | return ret; | |
1288 | } | |
082d4946 MD |
1289 | |
1290 | int lttng_abi_syscall_list(void) | |
1291 | { | |
1292 | struct file *syscall_list_file; | |
1293 | int file_fd, ret; | |
1294 | ||
4ac10b76 | 1295 | file_fd = lttng_get_unused_fd(); |
082d4946 MD |
1296 | if (file_fd < 0) { |
1297 | ret = file_fd; | |
1298 | goto fd_error; | |
1299 | } | |
1300 | ||
1301 | syscall_list_file = anon_inode_getfile("[lttng_syscall_list]", | |
1302 | <tng_syscall_list_fops, | |
1303 | NULL, O_RDWR); | |
1304 | if (IS_ERR(syscall_list_file)) { | |
1305 | ret = PTR_ERR(syscall_list_file); | |
1306 | goto file_error; | |
1307 | } | |
1308 | ret = lttng_syscall_list_fops.open(NULL, syscall_list_file); | |
1309 | if (ret < 0) | |
1310 | goto open_error; | |
1311 | fd_install(file_fd, syscall_list_file); | |
082d4946 MD |
1312 | return file_fd; |
1313 | ||
1314 | open_error: | |
1315 | fput(syscall_list_file); | |
1316 | file_error: | |
1317 | put_unused_fd(file_fd); | |
1318 | fd_error: | |
1319 | return ret; | |
1320 | } |