Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1821779imm; Mon, 3 Sep 2018 10:18:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbuhjxaZyltrS8xdt0vXOQcBbcaXSVwLx5dfhsaXAFbOMFTGwnPpFA/W/PmmwvfIpPj2WkR X-Received: by 2002:a63:4b1f:: with SMTP id y31-v6mr27019239pga.14.1535995116634; Mon, 03 Sep 2018 10:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995116; cv=none; d=google.com; s=arc-20160816; b=WDuWmc8XTSisEpGnYDrVVlTQw0TZGq7XLniALbMOS6x466tcL1zStctdEf/G/lMo7v 3zXgW4AC4OyBeud7P65yfoWPq5XMf4kMgmRdAhAKg6YLlHtWM8+3mkDmzT0ccERFkp4h 8nHomHB8mJQnbMYVP0RDngj1IesX+NW+ZNlvp+8vgCe6SIzT54yBLTSQ0MvZqYDqw6OI zhQF+7nvKfM1SzxcakMKbUq9sMDpaS6noYWPGhU66V0kM8eTvySDSf//i0/hAS9ZcXz4 MGsj5m7Rp2U3tWYTHJfV3mPJyjKxeV9kwk/1C3jYWv1NexYfk8eyz7VeyeNX2SYsyWi9 hecw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=2rfyWzn/rpNKnu/d1JDITGIvFborAeeYnwp+uxYmqBo=; b=NN/XQi1dT7bnkD+gvRyQCrwaIVrjeU69UpNls5ar6zrCfqPi2aZAEE1kJhEjYU6gTi Zhk9Ma8GX2S40n8l8PGcPAASgP9lu6lzB8aXIhYNVQjFjqSxWhCWnqj8t4aaveId4RPb rzVTtByAXt0c4wqXPQb2qFqpKEWJwbp7F0/jX4J0S291INz6Xk6HZs3hO8n+Qy8DI1zg D2ojUyAZx0t8+cZMoKCKz+nHPjT3cOZtlSa/7NckJ8uW6ARjtYPONxTUUVIVq6KCPLCV rTt4ouTfkS6uqv9Obb0FLvQeZ7rZdunoPffcP10Dm8gHteCCOVpMe8A4pxDp7M8BoM6m Eclg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15-v6si3075156pgi.646.2018.09.03.10.18.21; Mon, 03 Sep 2018 10:18:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729793AbeICViX (ORCPT + 99 others); Mon, 3 Sep 2018 17:38:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42756 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728154AbeICViW (ORCPT ); Mon, 3 Sep 2018 17:38:22 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 54B82D10; Mon, 3 Sep 2018 17:17:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Menzel , Thomas Gleixner , Alexander Shishkin , Arnaldo Carvalho de Melo , Borislav Petkov , Jiri Olsa , Linus Torvalds , Paul Menzel , Peter Zijlstra , Stephane Eranian , Vince Weaver , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 042/165] perf/x86/amd/ibs: Dont access non-started event Date: Mon, 3 Sep 2018 18:55:28 +0200 Message-Id: <20180903165657.250753353@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner [ Upstream commit d2753e6b4882a637a0e8fb3b9c2e15f33265300e ] 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 #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 Tested-by: Paul Menzel Signed-off-by: Thomas Gleixner Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Borislav Petkov Cc: Jiri Olsa Cc: Linus Torvalds Cc: Paul Menzel Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Vince Weaver Link: http://lkml.kernel.org/r/alpine.DEB.2.21.1807200958390.1580@nanos.tec.linutronix.de Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/amd/ibs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -579,7 +579,7 @@ static int perf_ibs_handle_irq(struct pe { struct cpu_perf_ibs *pcpu = this_cpu_ptr(perf_ibs->pcpu); struct perf_event *event = pcpu->event; - struct hw_perf_event *hwc = &event->hw; + struct hw_perf_event *hwc; struct perf_sample_data data; struct perf_raw_record raw; struct pt_regs regs; @@ -602,6 +602,10 @@ fail: return 0; } + if (WARN_ON_ONCE(!event)) + goto fail; + + hwc = &event->hw; msr = hwc->config_base; buf = ibs_data.regs; rdmsrl(msr, *buf);