Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1727805pxb; Wed, 9 Feb 2022 03:15:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx2wH6LCTLKE9bpyHiuC1SO9Uq743fxylG4KFScSyQxprqoxnETTL09RF7G3PK83j3zoFV2 X-Received: by 2002:a17:902:a9c5:: with SMTP id b5mr1593137plr.167.1644405341302; Wed, 09 Feb 2022 03:15:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644405341; cv=none; d=google.com; s=arc-20160816; b=cP7ovfls2oXdOuhSqTikcwXp5alDP0MLGc3UOTm06U+6aS0yW8nhT2rMH6Q1u5PtMW 4ERQb4r+kkdBsbGRVkqfuOxfz3ygrQQPBO7Zy9D1mYGCIWQxgqoIIVEYlFUBChbCN8fj o8PfzagampFZ3dDPR9X1do/Tnf2bED3SjjMskNoQ25v99zSBwQNZT4PfQQKDnrB+82WJ wQnQxAq5SPiK78fW+vv+W5GSJpS98XklgNlIncmGA71DDKrZouzLlVnx4upYA6a5UXyz ul21hjnvfxiJ1qqqf5Bq79dGwG6hajWVJjmHVLfemfD3TXrSrMu1+A7dEp26cPi4QdaB 6kAg== 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=mlmyOT8YW4rGksqGiuQDnHePk+42136hs8QHmLSxCSluHJGVmm00Hmw7Tvk38LrMoB c03qwuHpkPPPXKDX8TTv3aQyPGHXoX6Nik2U/Qq6wv3hxRkAqttLubkaXFqN+e5fW0WH Q69y2J0M90mjH+F0r6SDvf+68fClUM6Ky6NOrbfx/cVABEhPi48AVoGWYdp+IsU61NUA l2s86F4Fw3lJRJNOurSPlAqK7BsGiqfAbf6g3LkWUFeSZ/SEctHQWK+2M+XfIgSGdBHe RoaqnJBg4Q+/6rMHiIR50cqCmBFaINfX8X+78r08I8Z+fefonXC7KboFDqVzq9g/IRk8 DSbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FyH0591S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o2si4709048pji.104.2022.02.09.03.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:15:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FyH0591S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 B93BEDD5BD04; Wed, 9 Feb 2022 01:44:23 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391319AbiBGMBY (ORCPT + 99 others); Mon, 7 Feb 2022 07:01:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383182AbiBGLgD (ORCPT ); Mon, 7 Feb 2022 06:36:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3323C0401C0; Mon, 7 Feb 2022 03:36:01 -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 1CF7E6091A; Mon, 7 Feb 2022 11:36:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 642DDC004E1; Mon, 7 Feb 2022 11:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233760; bh=f1ORtPDAHpcxACauP0gFG5EboxWBRvFWuxzNa3VLo2w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FyH0591SOjN3aGAdvTqGjtNjPRDog2JXFvBhVdZoSX+mBoD3YVSvtri/7F+HU4Jib 7G2E+MaVhXAsbdFzkMncto2rmKfnM2Ec7OzRdpHQezzns39Uxx2dhORobTpgHLQ29W 0u6qNXf3mvdI2aLyT1v4FzmXNtqsz28bjt28EG7k= 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.16 111/126] perf/x86/intel/pt: Fix crash with stop filters in single-range mode Date: Mon, 7 Feb 2022 12:07:22 +0100 Message-Id: <20220207103807.890497222@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@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++;