Skip to content

Commit abc07cd

Browse files
vitkyrkaJiri Slaby
authored and
Jiri Slaby
committed
tracing/syscalls: Ignore numbers outside NR_syscalls' range
commit 086ba77 upstream. ARM has some private syscalls (for example, set_tls(2)) which lie outside the range of NR_syscalls. If any of these are called while syscall tracing is being performed, out-of-bounds array access will occur in the ftrace and perf sys_{enter,exit} handlers. # trace-cmd record -e raw_syscalls:* true && trace-cmd report ... true-653 [000] 384.675777: sys_enter: NR 192 (0, 1000, 3, 4000022, ffffffff, 0) true-653 [000] 384.675812: sys_exit: NR 192 = 1995915264 true-653 [000] 384.675971: sys_enter: NR 983045 (76f74480, 76f74000, 76f74b28, 76f74480, 76f76f74, 1) true-653 [000] 384.675988: sys_exit: NR 983045 = 0 ... # trace-cmd record -e syscalls:* true [ 17.289329] Unable to handle kernel paging request at virtual address aaaaaace [ 17.289590] pgd = 9e71c000 [ 17.289696] [aaaaaace] *pgd=00000000 [ 17.289985] Internal error: Oops: 5 [#1] PREEMPT SMP ARM [ 17.290169] Modules linked in: [ 17.290391] CPU: 0 PID: 704 Comm: true Not tainted 3.18.0-rc2+ #21 [ 17.290585] task: 9f4dab00 ti: 9e710000 task.ti: 9e710000 [ 17.290747] PC is at ftrace_syscall_enter+0x48/0x1f8 [ 17.290866] LR is at syscall_trace_enter+0x124/0x184 Fix this by ignoring out-of-NR_syscalls-bounds syscall numbers. Commit cd0980f "tracing: Check invalid syscall nr while tracing syscalls" added the check for less than zero, but it should have also checked for greater than NR_syscalls. Link: http://lkml.kernel.org/p/[email protected] Fixes: cd0980f "tracing: Check invalid syscall nr while tracing syscalls" Signed-off-by: Rabin Vincent <[email protected]> Signed-off-by: Steven Rostedt <[email protected]> Signed-off-by: Jiri Slaby <[email protected]>
1 parent a7a2830 commit abc07cd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/trace/trace_syscalls.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
312312
int size;
313313

314314
syscall_nr = trace_get_syscall_nr(current, regs);
315-
if (syscall_nr < 0)
315+
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
316316
return;
317317
if (!test_bit(syscall_nr, tr->enabled_enter_syscalls))
318318
return;
@@ -354,7 +354,7 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
354354
int syscall_nr;
355355

356356
syscall_nr = trace_get_syscall_nr(current, regs);
357-
if (syscall_nr < 0)
357+
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
358358
return;
359359
if (!test_bit(syscall_nr, tr->enabled_exit_syscalls))
360360
return;
@@ -557,7 +557,7 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id)
557557
int size;
558558

559559
syscall_nr = trace_get_syscall_nr(current, regs);
560-
if (syscall_nr < 0)
560+
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
561561
return;
562562
if (!test_bit(syscall_nr, enabled_perf_enter_syscalls))
563563
return;
@@ -631,7 +631,7 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
631631
int size;
632632

633633
syscall_nr = trace_get_syscall_nr(current, regs);
634-
if (syscall_nr < 0)
634+
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
635635
return;
636636
if (!test_bit(syscall_nr, enabled_perf_exit_syscalls))
637637
return;

0 commit comments

Comments
 (0)