Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1725715pxb; Wed, 9 Feb 2022 03:12:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhLvKBUn+9TZJQYPVN1IQeCR177UlRzAw3bF1ZCIYUlEIAU5fPgbayqsy6KwFnHYZnGVms X-Received: by 2002:a17:90b:1d0d:: with SMTP id on13mr2801881pjb.144.1644405141540; Wed, 09 Feb 2022 03:12:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644405141; cv=none; d=google.com; s=arc-20160816; b=nxOHZTBovmQaJy7a68IVnaXkFT3Qu4c9QX6os4Q+Rpmr9owapKuQ2TIPprtJ2wTMkC 6/ilG1ASJBpfeJ7sBC2Oc+4V/Fqpp6kN3JTE+KTLIG+UKx063cISinieUrCp8ZWT0a8t 0uthItUKWQpgEDXa1wIJJSEVey+6iTA2JgP9CmhiyroogcnvQTz5XoiOE9iQ82obPaWz pV7N8+b53AjBS77/mqnCs74TtJBPY+pUf/jJiw4o7b8dCUVssRlETyPXA9P5Y2ZnV9dc QJKmZHtvT158PPy/oe2v0JOdNBzZMW6SEhOGXlmT45AEo9zeji+X4OAX22UXkpaKCfGe DVbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UTfAT1Hok7vbd9nwBDygtmdlTmBXQHB20CRg587OktM=; b=wRRrBYm2tPhX6fCi77HbJxG/RgUXHPDel+afyxe3eb8qYgn9Ezb3eY4Xa+9yxQIqSl K82vXsDtIy2qu0rIVCn41IyOQUXxU8iKjBMyCQ8Rmg/fhKyxAT7ObBntrzZtuY4aPuIV +aOI9fI+gfqdI2Yg9jAbri0WStFTuoyDnR7HuIRwmcpibMWnhfTFaVp6+DMqPU3KRPJv cF/p0tuEoV+jRQK6t2VHlsBnRLHxqQ5AbYqZRqIMGCy9YsjhlqozVaQoWItnpPYzJSJ3 4vJgDuCZnXr6v2iOfe4nipx1Mo9CYTfzklaOqRnxtUBJw6R2TXbw8r2j2MZIVmrXSbQm VkKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sYQ9tuXX; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e16si8879985plx.445.2022.02.09.03.12.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:12:21 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sYQ9tuXX; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E930EE065086; Wed, 9 Feb 2022 01:42:10 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386285AbiBGLeS (ORCPT + 99 others); Mon, 7 Feb 2022 06:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383800AbiBGLXg (ORCPT ); Mon, 7 Feb 2022 06:23:36 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D313C0401DC; Mon, 7 Feb 2022 03:23:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E070C61388; Mon, 7 Feb 2022 11:23:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A654AC004E1; Mon, 7 Feb 2022 11:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233012; bh=f1ORtPDAHpcxACauP0gFG5EboxWBRvFWuxzNa3VLo2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYQ9tuXXO1+OBbZQChaES18CYnVB1SjvAaiV43hIXHGaBGUDodWOeGmpxPPtYcVft fjzmEnwdKweOu9HWqrMN/Uug0sea6iruvnDrgFFEcUmtK9VL1t+CF8uB6gVfbFnuPr 1x5iwulKIbB/siRL4xWeF3IfAVf0JohnOHdq3NCo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tristan Hume , "Peter Zijlstra (Intel)" , Adrian Hunter , stable@kernel.org Subject: [PATCH 5.10 63/74] perf/x86/intel/pt: Fix crash with stop filters in single-range mode Date: Mon, 7 Feb 2022 12:07:01 +0100 Message-Id: <20220207103759.295450979@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.232676988@linuxfoundation.org> References: <20220207103757.232676988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tristan Hume commit 1d9093457b243061a9bba23543c38726e864a643 upstream. Add a check for !buf->single before calling pt_buffer_region_size in a place where a missing check can cause a kernel crash. Fixes a bug introduced by commit 670638477aed ("perf/x86/intel/pt: Opportunistically use single range output mode"), which added a support for PT single-range output mode. Since that commit if a PT stop filter range is hit while tracing, the kernel will crash because of a null pointer dereference in pt_handle_status due to calling pt_buffer_region_size without a ToPA configured. The commit which introduced single-range mode guarded almost all uses of the ToPA buffer variables with checks of the buf->single variable, but missed the case where tracing was stopped by the PT hardware, which happens when execution hits a configured stop filter. Tested that hitting a stop filter while PT recording successfully records a trace with this patch but crashes without this patch. Fixes: 670638477aed ("perf/x86/intel/pt: Opportunistically use single range output mode") Signed-off-by: Tristan Hume Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Adrian Hunter Cc: stable@kernel.org Link: https://lkml.kernel.org/r/20220127220806.73664-1-tristan@thume.ca Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/pt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -897,8 +897,9 @@ static void pt_handle_status(struct pt * * means we are already losing data; need to let the decoder * know. */ - if (!intel_pt_validate_hw_cap(PT_CAP_topa_multiple_entries) || - buf->output_off == pt_buffer_region_size(buf)) { + if (!buf->single && + (!intel_pt_validate_hw_cap(PT_CAP_topa_multiple_entries) || + buf->output_off == pt_buffer_region_size(buf))) { perf_aux_output_flag(&pt->handle, PERF_AUX_FLAG_TRUNCATED); advance++;