Skip to content

Commit ba97697

Browse files
Ian Munsierostedt
authored andcommitted
tracing/syscalls: Don't add events for unmapped syscalls
FTRACE_SYSCALLS would create events for each and every system call, even if it had failed to map the system call's name with it's number. This resulted in a number of events being created that would not behave as expected. This could happen, for example, on architectures who's symbol names are unusual and will not match the system call name. It could also happen with system calls which were mapped to sys_ni_syscall. This patch changes the default system call number in the metadata to -1. If the system call name from the metadata is not successfully mapped to a system call number during boot, than the event initialisation routine will now return an error, preventing the event from being created. Signed-off-by: Ian Munsie <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Steven Rostedt <[email protected]>
1 parent 075de90 commit ba97697

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/linux/syscalls.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ extern struct trace_event_functions exit_syscall_print_funcs;
158158
static struct syscall_metadata __used \
159159
__syscall_meta_##sname = { \
160160
.name = "sys"#sname, \
161+
.syscall_nr = -1, /* Filled in at boot */ \
161162
.nb_args = nb, \
162163
.types = types_##sname, \
163164
.args = args_##sname, \
@@ -175,6 +176,7 @@ extern struct trace_event_functions exit_syscall_print_funcs;
175176
static struct syscall_metadata __used \
176177
__syscall_meta__##sname = { \
177178
.name = "sys_"#sname, \
179+
.syscall_nr = -1, /* Filled in at boot */ \
178180
.nb_args = 0, \
179181
.enter_event = &event_enter__##sname, \
180182
.exit_event = &event_exit__##sname, \

kernel/trace/trace_syscalls.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ void unreg_event_syscall_exit(struct ftrace_event_call *call)
424424
int init_syscall_trace(struct ftrace_event_call *call)
425425
{
426426
int id;
427+
int num;
428+
429+
num = ((struct syscall_metadata *)call->data)->syscall_nr;
430+
if (num < 0 || num >= NR_syscalls) {
431+
pr_debug("syscall %s metadata not mapped, disabling ftrace event\n",
432+
((struct syscall_metadata *)call->data)->name);
433+
return -ENOSYS;
434+
}
427435

428436
if (set_syscall_print_fmt(call) < 0)
429437
return -ENOMEM;

0 commit comments

Comments
 (0)