Steven Rostedt (VMware)
704adfb5a9
tracing: Do not reference char * as a string in histograms
The histogram logic was allowing events with char * pointers to be used as
normal strings. But it was easy to crash the kernel with:
# echo 'hist:keys=filename' > events/syscalls/sys_enter_openat/trigger
And open some files, and boom!
BUG: unable to handle page fault for address: 00007f2ced0c3280
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 1173fa067 P4D 1173fa067 PUD 1171b6067 PMD 1171dd067 PTE 0
Oops: 0000 [#1] PREEMPT SMP
CPU: 6 PID: 1810 Comm: cat Not tainted 5.13.0-rc5-test+ #61
Hardware name: Hewlett-Packard HP Compaq Pro 6300 SFF/339A, BIOS K01
v03.03 07/14/2016
RIP: 0010:strlen+0x0/0x20
Code: f6 82 80 2a 0b a9 20 74 11 0f b6 50 01 48 83 c0 01 f6 82 80 2a 0b
a9 20 75 ef c3 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 <80> 3f 00 74
10 48 89 f8 48 83 c0 01 80 38 00 75 f7 48 29 f8 c3
RSP: 0018:ffffbdbf81567b50 EFLAGS: 00010246
RAX: 0000000000000003 RBX: ffff93815cdb3800 RCX: ffff9382401a22d0
RDX: 0000000000000100 RSI: 0000000000000000 RDI: 00007f2ced0c3280
RBP: 0000000000000100 R08: ffff9382409ff074 R09: ffffbdbf81567c98
R10: ffff9382409ff074 R11: 0000000000000000 R12: ffff9382409ff074
R13: 0000000000000001 R14: ffff93815a744f00 R15: 00007f2ced0c3280
FS: 00007f2ced0f8580(0000) GS:ffff93825a800000(0000)
knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f2ced0c3280 CR3: 0000000107069005 CR4: 00000000001706e0
Call Trace:
event_hist_trigger+0x463/0x5f0
? find_held_lock+0x32/0x90
? sched_clock_cpu+0xe/0xd0
? lock_release+0x155/0x440
? kernel_init_free_pages+0x6d/0x90
? preempt_count_sub+0x9b/0xd0
? kernel_init_free_pages+0x6d/0x90
? get_page_from_freelist+0x12c4/0x1680
? __rb_reserve_next+0xe5/0x460
? ring_buffer_lock_reserve+0x12a/0x3f0
event_triggers_call+0x52/0xe0
ftrace_syscall_enter+0x264/0x2c0
syscall_trace_enter.constprop.0+0x1ee/0x210
do_syscall_64+0x1c/0x80
entry_SYSCALL_64_after_hwframe+0x44/0xae
Where it triggered a fault on strlen(key) where key was the filename.
The reason is that filename is a char * to user space, and the histogram
code just blindly dereferenced it, with obvious bad results.
I originally tried to use strncpy_from_user/kernel_nofault() but found
that there's other places that its dereferenced and not worth the effort.
Just do not allow "char *" to act like strings.
Link: https://lkml.kernel.org/r/20210715000206.025df9d2@rorschach.local.home
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Cc: stable@vger.kernel.org
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Tom Zanussi <zanussi@kernel.org>
Fixes: 79e577cbce ("tracing: Support string type key properly")
Fixes: 5967bd5c42 ("tracing: Let filter_assign_type() detect FILTER_PTR_STRING")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
2021-07-15 17:06:13 -04:00
..
2021-06-02 21:59:22 +02:00
2021-05-24 12:45:26 -04:00
2021-05-07 00:26:34 -07:00
2021-04-27 18:09:44 -07:00
2021-05-04 10:58:49 -07:00
2021-04-26 09:41:15 -07:00
2021-05-21 06:12:52 -10:00
2021-05-07 00:26:32 -07:00
2021-05-05 12:39:29 -07:00
2021-05-18 10:58:02 -07:00
2021-04-27 18:14:38 -07:00
2021-05-18 12:53:51 +02:00
2021-04-08 19:37:21 +02:00
2021-03-30 15:34:17 +02:00
2021-03-24 17:20:18 -07:00
2021-05-12 10:41:28 +02:00
2021-05-11 21:28:04 +02:00
2021-07-15 17:06:13 -04:00
2021-05-02 00:43:35 +09:00
2020-12-15 22:46:15 -08:00
2021-05-07 00:26:33 -07:00
2021-02-23 10:25:27 -05:00
2020-12-03 14:58:35 +01:00
2020-12-03 14:58:35 +01:00
2021-03-22 15:23:32 -04:00
2021-03-24 12:11:48 -04:00
2021-03-22 15:23:32 -04:00
2021-04-27 13:50:58 -07:00
2021-01-24 14:27:16 +01:00
2021-04-08 16:04:20 -07:00
2021-04-21 13:55:43 +02:00
2020-12-15 22:46:18 -08:00
2021-05-06 19:24:11 -07:00
2021-05-06 19:24:13 -07:00
2020-12-15 22:46:19 -08:00
2021-05-06 19:24:13 -07:00
2021-03-27 14:09:10 -06:00
2021-05-06 20:19:04 +02:00
2021-04-25 05:26:10 +09:00
2021-02-26 09:41:03 -08:00
2021-04-30 11:20:42 -07:00
2021-03-19 13:16:44 +01:00
2021-04-08 16:04:21 -07:00
2020-12-15 19:36:48 -08:00
2021-02-17 14:12:24 +01:00
2020-11-02 18:00:20 -08:00
2021-05-07 00:26:32 -07:00
2021-05-07 00:26:32 -07:00
2021-02-22 12:33:26 +00:00
2021-05-07 00:26:33 -07:00
2021-02-19 14:57:12 -05:00
2021-04-28 13:33:57 -07:00
2021-05-02 00:43:35 +09:00
2021-01-19 10:24:45 +01:00
2021-01-19 10:24:45 +01:00
2021-05-17 09:48:24 +02:00
2020-12-14 16:40:27 -08:00
2020-11-14 11:26:04 -08:00
2020-12-17 13:01:31 -08:00
2020-12-14 16:40:27 -08:00
2020-12-15 19:36:48 -08:00
2021-04-10 13:35:54 +02:00
2021-05-12 10:45:22 -07:00
2021-03-18 16:58:02 +01:00
2020-12-15 22:46:18 -08:00
2020-11-25 18:52:35 +01:00
2021-05-14 19:41:32 -07:00
2021-04-14 18:04:09 +02:00
2021-01-04 13:53:41 -08:00
2020-12-01 10:30:28 +00:00
2021-05-29 11:13:27 -07:00
2021-05-21 06:12:52 -10:00
2021-05-06 15:33:49 +02:00
2021-01-22 15:09:42 +01:00
2021-04-28 12:00:13 -07:00
2021-04-09 13:22:12 +02:00
2021-03-23 16:01:58 +01:00
2021-05-01 18:50:44 -07:00
2021-05-07 00:26:34 -07:00
2021-05-11 16:05:56 -07:00
2021-04-30 11:20:42 -07:00
2020-11-16 08:08:54 -08:00
2021-03-08 14:22:28 -08:00
2021-06-29 11:51:25 -04:00
2021-03-16 16:49:31 +01:00
2021-05-07 00:26:34 -07:00
2021-05-09 13:07:03 -07:00
2021-05-07 00:26:34 -07:00
2021-03-19 22:23:19 +01:00
2021-01-26 11:16:34 +00:00
2021-05-22 15:09:07 -10:00
2021-05-20 12:58:30 -04:00