Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp176729yba; Thu, 2 May 2019 22:59:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5fsr2kNAjJ1A5adBPW/KKP3DyflQliuhj48Z0aFHh4GIoUQiXx9GFfdNmdCPgyl17C6yb X-Received: by 2002:aa7:87c3:: with SMTP id i3mr8319728pfo.85.1556863160271; Thu, 02 May 2019 22:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556863160; cv=none; d=google.com; s=arc-20160816; b=mZTRm/Inadf9YCUtOWeNiDNh9oggC2hDNvIIMEZcdZ4PlhEJacDBd0lII88KKnj9NL xppwibsBSINhRaEEKE/Bsg4X60prFbm67og6mm44hjZlithNkdeF5bmSZhGrg0hALw6Y RZ6fPAstqoMxkd1/fPz4rwl4J1uPfOz7azBBohw1RApObWXymtoZSkUnVZow/NofAUFH oG+wpkXUoAFrohzFGkHqpB/IRfGZEtQ10UoFbRvUGrdDs3c2SWBcRmbfFY821glBFFtt P5eBywHpupMqj1fDOifS3RBtY/yJZJeYSZJQzfJPHSHSJIMquF05T3m44I4oCmt+NxrK XR8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=kz6MNukui0KiADnNHmzlQuaCU0ATrKZ8pqEHdLeHMVc=; b=E14u/ZKVaMwVShzuwHZOoI+b9AJ58HGyN+1AOp835cRmanftE3h2Z9lfzj9hkTvHJc swj1GvLG7LP0np1IWRRZcpJBXensyt9M2WbapGIOwVauk3MWtcfqiUCM7Tu7d0WzcExH FlFK1iTiP2xfPDmI63sbPTsNzrZDwsaHiphNik2Dtz0I6m/XJgkXLAI2B5BzE6JMEI2U oKmIiBD3o+bfeZ+ukjH0SC0G3jeLyGMOkWm4nkaAk3dgMnd9u/pwbFmtbkCjuSB8/mqx wKJL46yv5PHGZTtjXT/Me2LCoZN2CWKhMFktnXcyWh5TA6jmkdarv3oLc2msOU3F/8Pl kfhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=q9jnEdYx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m12si1248116pls.199.2019.05.02.22.59.05; Thu, 02 May 2019 22:59:20 -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; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=q9jnEdYx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726742AbfECF5P (ORCPT + 99 others); Fri, 3 May 2019 01:57:15 -0400 Received: from terminus.zytor.com ([198.137.202.136]:55195 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725775AbfECF5O (ORCPT ); Fri, 3 May 2019 01:57:14 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x435v2Ik2618778 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 2 May 2019 22:57:03 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x435v2Ik2618778 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1556863023; bh=kz6MNukui0KiADnNHmzlQuaCU0ATrKZ8pqEHdLeHMVc=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=q9jnEdYxQCvaiqAQbg2AVzEmkrnJivFHzkUGrCHqbziC0+QrLomsVSM4JGKsZtR5p kpQmkzYogxOO9qw1oNuw5YDKHyyh/QKJRxIYE3JnqkkLqXD5zfHGFu6GJzJV2AjfWg p9AWJkhbKBnZCgGB+uRo6d5REBVcu1BOhvTvjrUEZf3anw9q4SiMjsgxVSg8HbNUS6 z9LWnuEHXUy4j4JF/jGknaz1ez/V5GP4VwOUVKg87x8qJSHTrUf/DDvEzBoHnXjG+I xkW2u7N1LsujDvf1Cer39ovK1A7N9zf59ze1L4Ccq+IZzWWLRCULRo4/TIavhI9jwE KhG1nb1Jjp7gA== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x435v2MJ2618680; Thu, 2 May 2019 22:57:02 -0700 Date: Thu, 2 May 2019 22:57:02 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Leo Yan Message-ID: Cc: acme@redhat.com, tglx@linutronix.de, jolsa@redhat.com, leo.yan@linaro.org, robert.walker@arm.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, hpa@zytor.com, mike.leach@linaro.org, namhyung@kernel.org, mingo@kernel.org, mathieu.poirier@linaro.org Reply-To: jolsa@redhat.com, tglx@linutronix.de, acme@redhat.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, suzuki.poulose@arm.com, leo.yan@linaro.org, robert.walker@arm.com, mike.leach@linaro.org, namhyung@kernel.org, hpa@zytor.com, mingo@kernel.org, mathieu.poirier@linaro.org In-Reply-To: <20190428083228.20246-1-leo.yan@linaro.org> References: <20190428083228.20246-1-leo.yan@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet Git-Commit-ID: 35bb59c10a6d0578806dd500477dae9cb4be344e X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 35bb59c10a6d0578806dd500477dae9cb4be344e Gitweb: https://git.kernel.org/tip/35bb59c10a6d0578806dd500477dae9cb4be344e Author: Leo Yan AuthorDate: Sun, 28 Apr 2019 16:32:27 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 2 May 2019 16:00:20 -0400 perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet 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);