Prateek Sood
5ce7528c4d
tracing: Fix race in perf_trace_buf initialization
commit 6b1340cc00edeadd52ebd8a45171f38c8de2a387 upstream.
A race condition exists while initialiazing perf_trace_buf from
perf_trace_init() and perf_kprobe_init().
CPU0 CPU1
perf_trace_init()
mutex_lock(&event_mutex)
perf_trace_event_init()
perf_trace_event_reg()
total_ref_count == 0
buf = alloc_percpu()
perf_trace_buf[i] = buf
tp_event->class->reg() //fails perf_kprobe_init()
goto fail perf_trace_event_init()
perf_trace_event_reg()
fail:
total_ref_count == 0
total_ref_count == 0
buf = alloc_percpu()
perf_trace_buf[i] = buf
tp_event->class->reg()
total_ref_count++
free_percpu(perf_trace_buf[i])
perf_trace_buf[i] = NULL
Any subsequent call to perf_trace_event_reg() will observe total_ref_count > 0,
causing the perf_trace_buf to be always NULL. This can result in perf_trace_buf
getting accessed from perf_trace_buf_alloc() without being initialized. Acquiring
event_mutex in perf_kprobe_init() before calling perf_trace_event_init() should
fix this race.
The race caused the following bug:
Unable to handle kernel paging request at virtual address 0000003106f2003c
Mem abort info:
ESR = 0x96000045
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000045
CM = 0, WnR = 1
user pgtable: 4k pages, 39-bit VAs, pgdp = ffffffc034b9b000
[0000003106f2003c] pgd=0000000000000000, pud=0000000000000000
Internal error: Oops: 96000045 [#1] PREEMPT SMP
Process syz-executor (pid: 18393, stack limit = 0xffffffc093190000)
pstate: 80400005 (Nzcv daif +PAN -UAO)
pc : __memset+0x20/0x1ac
lr : memset+0x3c/0x50
sp : ffffffc09319fc50
__memset+0x20/0x1ac
perf_trace_buf_alloc+0x140/0x1a0
perf_trace_sys_enter+0x158/0x310
syscall_trace_enter+0x348/0x7c0
el0_svc_common+0x11c/0x368
el0_svc_handler+0x12c/0x198
el0_svc+0x8/0xc
Ramdumps showed the following:
total_ref_count = 3
perf_trace_buf = (
0x0 -> NULL,
0x0 -> NULL,
0x0 -> NULL,
0x0 -> NULL)
Link: http://lkml.kernel.org/r/1571120245-4186-1-git-send-email-prsood@codeaurora.org
Cc: stable@vger.kernel.org
Fixes: e12f03d703 ("perf/core: Implement the 'perf_kprobe' PMU")
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Prateek Sood <prsood@codeaurora.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-10-29 09:20:03 +01:00
..
2019-10-07 18:57:19 +02:00
2019-08-09 17:52:35 +02:00
2019-02-12 19:47:19 +01:00
2019-01-13 09:51:05 +01:00
2019-10-29 09:20:03 +01:00
2019-09-19 09:09:34 +02:00
2019-10-07 18:57:10 +02:00
2019-10-11 18:21:06 +02:00
2019-06-11 12:20:52 +02:00
2019-10-05 13:10:01 +02:00
2019-05-31 06:46:30 -07:00
2019-10-11 18:21:22 +02:00
2019-10-11 18:21:28 +02:00
2019-10-29 09:20:03 +01:00
2019-05-31 06:46:05 -07:00
2018-08-17 09:41:28 -07:00
2018-07-18 11:43:36 -04:00
2018-07-17 14:45:08 -04:00
2019-05-31 06:46:17 -07:00
2018-08-15 10:46:54 -07:00
2018-11-13 11:08:47 -08:00
2019-07-21 09:03:11 +02:00
2018-08-22 10:52:47 -07:00
2019-07-31 07:27:11 +02:00
2019-10-11 18:21:23 +02:00
2019-08-09 17:52:34 +02:00
2019-10-17 13:45:19 -07:00
2018-08-06 12:35:20 +02:00
2019-05-10 17:54:11 +02:00
2019-04-20 09:16:02 +02:00
2019-05-31 06:46:19 -07:00
2019-06-04 08:02:34 +02:00
2019-09-21 07:17:02 +02:00
2018-08-02 08:06:54 +09:00
2019-02-12 19:47:20 +01:00
2019-10-07 18:57:28 +02:00
2018-07-16 12:31:57 -07:00
2019-10-05 13:09:54 +02:00
2018-08-13 11:25:07 -07:00
2019-06-19 08:18:01 +02:00
2019-01-13 09:51:04 +01:00
2019-09-19 09:09:40 +02:00
2019-07-26 09:14:25 +02:00
2019-10-17 13:44:46 -07:00
2019-07-26 09:14:01 +02:00
2019-01-13 09:51:06 +01:00
2019-07-10 09:53:41 +02:00
2018-08-06 12:35:20 +02:00
2019-03-13 14:02:35 -07:00
2019-09-16 08:22:20 +02:00
2019-06-09 09:17:20 +02:00
2019-02-12 19:47:25 +01:00
2018-08-03 15:52:10 +02:00
2018-08-13 11:25:07 -07:00
2019-06-15 11:54:01 +02:00
2019-06-15 11:53:59 +02:00
2018-10-17 15:35:29 -04:00
2018-11-13 11:09:00 -08:00
2018-08-22 10:52:47 -07:00
2018-08-11 02:05:53 -05:00
2018-08-30 12:56:40 +02:00
2019-04-03 06:26:29 +02:00
2019-05-02 09:58:56 +02:00