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