Files
twx-linux/include/linux
Jiri Olsa b1b0ca701b perf/x86: Add check_period PMU callback
commit 81ec3f3c4c upstream.

Vince (and later on Ravi) reported crashes in the BTS code during
fuzzing with the following backtrace:

  general protection fault: 0000 [#1] SMP PTI
  ...
  RIP: 0010:perf_prepare_sample+0x8f/0x510
  ...
  Call Trace:
   <IRQ>
   ? intel_pmu_drain_bts_buffer+0x194/0x230
   intel_pmu_drain_bts_buffer+0x160/0x230
   ? tick_nohz_irq_exit+0x31/0x40
   ? smp_call_function_single_interrupt+0x48/0xe0
   ? call_function_single_interrupt+0xf/0x20
   ? call_function_single_interrupt+0xa/0x20
   ? x86_schedule_events+0x1a0/0x2f0
   ? x86_pmu_commit_txn+0xb4/0x100
   ? find_busiest_group+0x47/0x5d0
   ? perf_event_set_state.part.42+0x12/0x50
   ? perf_mux_hrtimer_restart+0x40/0xb0
   intel_pmu_disable_event+0xae/0x100
   ? intel_pmu_disable_event+0xae/0x100
   x86_pmu_stop+0x7a/0xb0
   x86_pmu_del+0x57/0x120
   event_sched_out.isra.101+0x83/0x180
   group_sched_out.part.103+0x57/0xe0
   ctx_sched_out+0x188/0x240
   ctx_resched+0xa8/0xd0
   __perf_event_enable+0x193/0x1e0
   event_function+0x8e/0xc0
   remote_function+0x41/0x50
   flush_smp_call_function_queue+0x68/0x100
   generic_smp_call_function_single_interrupt+0x13/0x30
   smp_call_function_single_interrupt+0x3e/0xe0
   call_function_single_interrupt+0xf/0x20
   </IRQ>

The reason is that while event init code does several checks
for BTS events and prevents several unwanted config bits for
BTS event (like precise_ip), the PERF_EVENT_IOC_PERIOD allows
to create BTS event without those checks being done.

Following sequence will cause the crash:

If we create an 'almost' BTS event with precise_ip and callchains,
and it into a BTS event it will crash the perf_prepare_sample()
function because precise_ip events are expected to come
in with callchain data initialized, but that's not the
case for intel_pmu_drain_bts_buffer() caller.

Adding a check_period callback to be called before the period
is changed via PERF_EVENT_IOC_PERIOD. It will deny the change
if the event would become BTS. Plus adding also the limit_period
check as well.

Reported-by: Vince Weaver <vincent.weaver@maine.edu>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: <stable@vger.kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20190204123532.GA4794@krava
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-20 10:20:52 +01:00
..
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2018-04-24 09:36:39 +02:00
2011-03-11 14:25:50 +00:00
…
2017-07-03 16:56:28 -06:00
2018-02-22 15:42:23 +01:00
…
…
2017-08-30 14:40:40 +02:00
…
…
2018-08-03 07:50:38 +02:00
2012-02-20 19:46:36 +11:00
2016-10-28 08:48:16 -06:00
2018-02-22 15:42:23 +01:00
…
2017-07-17 13:42:48 +02:00
…
2012-10-16 18:49:15 -07:00
…
…
…
…
2017-08-07 17:22:14 +02:00
2014-12-31 13:06:50 -05:00
2018-02-22 15:42:23 +01:00
2014-10-09 11:35:48 +03:00
…
2018-06-21 04:02:49 +09:00
…
…
2017-03-21 10:15:47 +02:00
…
2010-02-09 11:13:56 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
2017-06-21 14:37:12 -04:00
2018-02-22 15:42:24 +01:00
…
…
…
…
…
…
2017-08-15 18:23:52 +02:00
2013-06-17 16:38:57 -07:00
2017-01-05 15:01:55 -06:00
…
…
…
2014-03-13 12:11:00 +10:30
2016-01-28 14:19:12 -08:00
…
…
…
2016-03-22 15:36:02 -07:00
…
…
…
…
2016-12-25 17:21:23 +01:00
…
…
…
…
…
2017-08-28 20:51:22 +02:00
…
…
…
…
2018-02-22 15:42:23 +01:00
…
…
…
2017-07-06 11:30:07 -04:00
…
…
2017-09-25 08:56:05 -06:00
…
…
…
…
…
…
…
…
2017-05-26 10:10:37 +02:00
…
…
…
…
…
…
…
2018-09-09 19:55:54 +02:00
2017-08-06 20:55:29 -07:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2013-04-30 15:50:12 +05:30
…
…
…
…
…
…
2018-11-13 11:15:11 -08:00
…
2015-10-01 09:57:59 -07:00
…
…
…
…
…
…
2017-07-24 17:50:37 +02:00
2014-11-28 16:08:16 +01:00
…
…
…
…
…
2017-08-31 18:50:14 +02:00
…
…
2017-08-15 09:02:07 -07:00
2011-01-13 08:03:24 -08:00
2013-10-17 15:53:09 -04:00
…
2017-08-15 09:02:08 -07:00