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