From patchwork Fri May 3 00:25:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 163284 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp20618ill; Thu, 2 May 2019 17:26:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqypjau4oUvT1Yd4kW5281errGO0kecdOO50jpMcBzAOFfdd564YF68eza4O1s2bALGz355J X-Received: by 2002:a65:484a:: with SMTP id i10mr7015048pgs.408.1556843193438; Thu, 02 May 2019 17:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556843193; cv=none; d=google.com; s=arc-20160816; b=nyb0iojAEgr3dKgnYK31wsDBd0qxBKD3o3hyix6/OjCVKpXNAdP53Fn7aSrUU83MLw Rk8PO5LiGQh1A+htW2LGem2284QypIT9ynyDSQLkteDVB4GUYlLNImrRpE53/J3re4wE JoIz98r9XUz+ajcx8NRi2HoFfRV1NYUvHu9Eqs2BR6QFX+mi8Nq2mTNEvk7uYFNSmMuk 9XpwF9BQWC1UVJebfyPvNS/bncN9pGKQAgcafclHSWD7MnEwPVFWYdEOsc0rekiOvQJx r6ZcZC/tqWX6YQdfHmXHRafrgPkzUjzHFRfPSJw+t4Rs69xWakxq7VM7GBZyGpmlnNQC RQig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AnyZ66sO+ui2p2M6tDSOtXkn/JPM4cS/qOODdOkb0P8=; b=DmrLqagIy0ygb6fAgEs+BsMYxy23Cyij97Zn5hYcF8fcnEA59zh/R0h66dQezmpl7W OZknxJ0pYvQYoA5AjOYMS1HIlx+ft0GQaTRWnoCUIWy32XUgUZpJsPYF7bI2iE4or6bV vNWaAMZfgE32avY3b0mE9X1+NB6CBGsYLR1rQWLXSOkchg6ObzWZ1bUs8hN6Sj6CpIe4 S16kTe6O8eAcoca8tGRB/9O6WxmXLnFGRHZtZ5800hNCvlVaZh/rhEqD6OLybOs7H0TT VfrqQP1t4az5bPNNtvP6yespwlHi2UwdUVNB3TMqxqyJMNgv35p4WsD1CtxT4TUsIZt8 U0gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="VTo6q/l2"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p9si685984plo.49.2019.05.02.17.26.33; Thu, 02 May 2019 17:26:33 -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=@kernel.org header.s=default header.b="VTo6q/l2"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726571AbfECA0L (ORCPT + 30 others); 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 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(-) -- 2.20.1 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);