Skip to content

Commit 00f795e

Browse files
KAGA-KOKOgregkh
authored andcommitted
perf/x86/amd/ibs: Don't access non-started event
[ Upstream commit d2753e6 ] Paul Menzel reported the following bug: > Enabling the undefined behavior sanitizer and building GNU/Linux 4.18-rc5+ > (with some unrelated commits) with GCC 8.1.0 from Debian Sid/unstable, the > warning below is shown. > > > [ 2.111913] > > ================================================================================ > > [ 2.111917] UBSAN: Undefined behaviour in arch/x86/events/amd/ibs.c:582:24 > > [ 2.111919] member access within null pointer of type 'struct perf_event' > > [ 2.111926] CPU: 0 PID: 144 Comm: udevadm Not tainted 4.18.0-rc5-00316-g4864b68cedf2 raspberrypi#104 > > [ 2.111928] Hardware name: ASROCK E350M1/E350M1, BIOS TIMELESS 01/01/1970 > > [ 2.111930] Call Trace: > > [ 2.111943] dump_stack+0x55/0x89 > > [ 2.111949] ubsan_epilogue+0xb/0x33 > > [ 2.111953] handle_null_ptr_deref+0x7f/0x90 > > [ 2.111958] __ubsan_handle_type_mismatch_v1+0x55/0x60 > > [ 2.111964] perf_ibs_handle_irq+0x596/0x620 The code dereferences event before checking the STARTED bit. Patch below should cure the issue. The warning should not trigger, if I analyzed the thing correctly. (And Paul's testing confirms this.) Reported-by: Paul Menzel <[email protected]> Tested-by: Paul Menzel <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul Menzel <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Vince Weaver <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 385b40b commit 00f795e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/x86/events/amd/ibs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
579579
{
580580
struct cpu_perf_ibs *pcpu = this_cpu_ptr(perf_ibs->pcpu);
581581
struct perf_event *event = pcpu->event;
582-
struct hw_perf_event *hwc = &event->hw;
582+
struct hw_perf_event *hwc;
583583
struct perf_sample_data data;
584584
struct perf_raw_record raw;
585585
struct pt_regs regs;
@@ -602,6 +602,10 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
602602
return 0;
603603
}
604604

605+
if (WARN_ON_ONCE(!event))
606+
goto fail;
607+
608+
hwc = &event->hw;
605609
msr = hwc->config_base;
606610
buf = ibs_data.regs;
607611
rdmsrl(msr, *buf);

0 commit comments

Comments
 (0)