From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8ECE4C43219 for ; Fri, 3 May 2019 00:26:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BB6C2087F for ; Fri, 3 May 2019 00:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556843193; bh=0W/IEo/M2/Xmyn/H5AkhZO7nQPFZLmoXQI5hS0C/M78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Cpgpe/6QhuqQ5rr/v89kyV4Jk+EMaHfAFEvNh1WTSNd656Q0F0jPskUPF6hV/eciH d3Y9Ngqo970WqqZRV4yPfjw8JjNXeWBxW/uOWfxaotj222l2oGPl7wEYhaQfKVBZGM IlV3Csx1WSKD7qMoiwka9Nyrx7q1JB5PVL5QmGx4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbfECA0L (ORCPT ); Thu, 2 May 2019 20:26:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:44136 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726528AbfECA0J (ORCPT ); Thu, 2 May 2019 20:26:09 -0400 Received: from quaco.ghostprotocols.net (adsl-173-228-226-134.prtc.net [173.228.226.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62D8B217D4; Fri, 3 May 2019 00:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556843168; bh=0W/IEo/M2/Xmyn/H5AkhZO7nQPFZLmoXQI5hS0C/M78=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VTo6q/l2qk438aHpNfAnJH+BOBJkFvQFuSCy2mO9/y5QOUdX546/hkDlN49DmNTPy MtnXUyP/c2c5SsFnEux+Zj+jm24+0M3lc4emxPL77xyP+Qihg3dzVg8EjSXm3IBby9 dkhpOS5FNKkcqsbb+Xnk/VrNao/9ePm/QPa1gALY= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Robert Walker , Alexander Shishkin , Jiri Olsa , Mathieu Poirier , Mike Leach , Suzuki K Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 08/11] perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet Date: Thu, 2 May 2019 20:25:30 -0400 Message-Id: <20190503002533.29359-9-acme@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190503002533.29359-1-acme@kernel.org> References: <20190503002533.29359-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Robert Walker reported a segmentation fault is observed when process CoreSight trace data; this issue can be easily reproduced by the command 'perf report --itrace=i1000i' for decoding tracing data. If neither the 'b' flag (synthesize branches events) nor 'l' flag (synthesize last branch entries) are specified to option '--itrace', cs_etm_queue::prev_packet will not been initialised. After merging the code to support exception packets and sample flags, there introduced a number of uses of cs_etm_queue::prev_packet without checking whether it is valid, for these cases any accessing to uninitialised prev_packet will cause crash. As cs_etm_queue::prev_packet is used more widely now and it's already hard to follow which functions have been called in a context where the validity of cs_etm_queue::prev_packet has been checked, this patch always allocates memory for cs_etm_queue::prev_packet. Reported-by: Robert Walker Suggested-by: Robert Walker Signed-off-by: Leo Yan Tested-by: Robert Walker Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Mathieu Poirier Cc: Mike Leach Cc: Namhyung Kim Cc: Suzuki K Poulouse Cc: linux-arm-kernel@lists.infradead.org Fixes: 7100b12cf474 ("perf cs-etm: Generate branch sample for exception packet") Fixes: 24fff5eb2b93 ("perf cs-etm: Avoid stale branch samples when flush packet") Link: http://lkml.kernel.org/r/20190428083228.20246-1-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 7777cfc1ad8c..de488b43f440 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -422,11 +422,9 @@ static struct cs_etm_queue *cs_etm__alloc_queue(struct cs_etm_auxtrace *etm) if (!etmq->packet) goto out_free; - if (etm->synth_opts.last_branch || etm->sample_branches) { - etmq->prev_packet = zalloc(szp); - if (!etmq->prev_packet) - goto out_free; - } + etmq->prev_packet = zalloc(szp); + if (!etmq->prev_packet) + goto out_free; if (etm->synth_opts.last_branch) { size_t sz = sizeof(struct branch_stack); -- 2.20.1