2015-11-20 12:02:30

by Dmitry Safonov

[permalink] [raw]
Subject: [PATCH 1/2] trace_syscalls: return unhandled trace type on warn

Having as an example print_syscall_exit(), return TRACE_TYPE_UNHANDLED
if entry type differs from syscall's metadata type.

Signed-off-by: Dmitry Safonov <[email protected]>
---
kernel/trace/trace_syscalls.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 0655afbea83f59..b9d4c3cc60aeba 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -126,7 +126,7 @@ print_syscall_enter(struct trace_iterator *iter, int flags,

if (entry->enter_event->event.type != ent->type) {
WARN_ON_ONCE(1);
- goto end;
+ return TRACE_TYPE_UNHANDLED;
}

trace_seq_printf(s, "%s(", entry->name);
--
2.6.2


2015-11-20 12:02:38

by Dmitry Safonov

[permalink] [raw]
Subject: [PATCH 2/2] trace_syscalls: cleanup: check syscall_nr with syscall_nr_to_meta

As syscall_nr_to_meta already checks for
(syscall_nr < 0 || syscall_nr >= NR_syscalls) - remove this checkups.

Signed-off-by: Dmitry Safonov <[email protected]>
---
kernel/trace/trace_syscalls.c | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index b9d4c3cc60aeba..7dc58306de1a3f 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -305,7 +305,8 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
int size;

syscall_nr = trace_get_syscall_nr(current, regs);
- if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
+ sys_data = syscall_nr_to_meta(syscall_nr);
+ if (!sys_data)
return;

/* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE) */
@@ -316,10 +317,6 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
if (trace_trigger_soft_disabled(trace_file))
return;

- sys_data = syscall_nr_to_meta(syscall_nr);
- if (!sys_data)
- return;
-
size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args;

local_save_flags(irq_flags);
@@ -352,7 +349,8 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
int syscall_nr;

syscall_nr = trace_get_syscall_nr(current, regs);
- if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
+ sys_data = syscall_nr_to_meta(syscall_nr);
+ if (!sys_data)
return;

/* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE()) */
@@ -363,10 +361,6 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
if (trace_trigger_soft_disabled(trace_file))
return;

- sys_data = syscall_nr_to_meta(syscall_nr);
- if (!sys_data)
- return;
-
local_save_flags(irq_flags);
pc = preempt_count();

@@ -556,15 +550,13 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id)
int size;

syscall_nr = trace_get_syscall_nr(current, regs);
- if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
- return;
- if (!test_bit(syscall_nr, enabled_perf_enter_syscalls))
- return;
-
sys_data = syscall_nr_to_meta(syscall_nr);
if (!sys_data)
return;

+ if (!test_bit(syscall_nr, enabled_perf_enter_syscalls))
+ return;
+
head = this_cpu_ptr(sys_data->enter_event->perf_events);
if (hlist_empty(head))
return;
@@ -630,15 +622,13 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
int size;

syscall_nr = trace_get_syscall_nr(current, regs);
- if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
- return;
- if (!test_bit(syscall_nr, enabled_perf_exit_syscalls))
- return;
-
sys_data = syscall_nr_to_meta(syscall_nr);
if (!sys_data)
return;

+ if (!test_bit(syscall_nr, enabled_perf_exit_syscalls))
+ return;
+
head = this_cpu_ptr(sys_data->exit_event->perf_events);
if (hlist_empty(head))
return;
--
2.6.2