From patchwork Sun Apr 28 08:32:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 163001 Delivered-To: patch@linaro.org Received: by 2002:a92:7e86:0:0:0:0:0 with SMTP id q6csp585281ill; Sun, 28 Apr 2019 01:32:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8ZBpSsoGe8ChtUyQOwnvzPvWniIZqdfNdRlaP/1XfPPt6VHbtq/p+yZP3wW3trWiKJyOb X-Received: by 2002:a17:902:a5cb:: with SMTP id t11mr26606387plq.268.1556440375674; Sun, 28 Apr 2019 01:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556440375; cv=none; d=google.com; s=arc-20160816; b=IN6uHUoG6ZirA0vgGZeyCRO/sxE5eCnkcEBhkbv78gLFaw20Vz0laNT7qgvGr1IRUv poZrL6CA+eXzpKBbNpT1ayP83Zs7XoEUAqUFNNk6qOoflwfJlG49/xX+U0GIdxQ5mQqN 6YHhNyXnxAy23WUjUMDHjmyDSswRR0x35YZ8uX+HsxJBDeWbTZ1SWQi4brrZtbICBHbF +hseAzulnx3X0Lcpt/i1RR/e0kydeb/u3FCx9CPCdyYzI/H1uaCr4lvGqCZybXUxcvr7 nf7dEM9wD3mDRWyQUMXa1+pmCK63JOtWhxVmg93Ub7w2NZWprEk+UVSfZZKlf/uP127w sEUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=BZzKmMo+qjjyommvsHqCKRlBwkTvNOIM1AtqhVGSBu8=; b=V+H6m+sKV5xRF/TIlkKptzkKXwYpSsYTTI6D0ghbbPKOcKot0h12fGQZCkUiTo7Y2A PmY7Glb+c2CXKfaYLX6xKj6coTfit4lfc5MB0X4BBv8CTuUyd5mYU046t8p13dzw/uq9 NHWgSOZjcWmyBs5H2ftAGrr+9WINBlordKwxilnYXNq1HG/FdfzryiH+d7KmhCtXnUvn cYBDvex6+6QzpDShOLHoceYUTx7H/3AEaYAgaZ5kbu/Ag1mTSKRCsH9yeJuC1jUKNlwe VTYs8N1zYYOZo0iUmXzK+ojM7te/5kOeCVZ9CS8ECwgC8vTh8/3Es7e8pQijlSfNs9Lb 7nsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wu5QE43+; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5si5403968pgj.491.2019.04.28.01.32.55; Sun, 28 Apr 2019 01:32:55 -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=@linaro.org header.s=google header.b=wu5QE43+; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbfD1Icr (ORCPT + 30 others); Sun, 28 Apr 2019 04:32:47 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:45339 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726466AbfD1Icr (ORCPT ); Sun, 28 Apr 2019 04:32:47 -0400 Received: by mail-pg1-f195.google.com with SMTP id i21so229856pgi.12 for ; Sun, 28 Apr 2019 01:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=BZzKmMo+qjjyommvsHqCKRlBwkTvNOIM1AtqhVGSBu8=; b=wu5QE43+AeRJsCx5EsAFQ2WNN/6Pa5OHvDpSZUE3LqXCoegpmt5xwl2xMcIjZK1a8f JN1e575Y97uYNyL/D011tx6b8xfVBhZ1AE24pACltyswm1WgB1S6WztEKBL7XqoBiyER Fvhnt93SyMNVKo7wFuP8flLqfsi0O7HvOlyCBz5MxU7YoqWszzaVlNDYo1wWaSl9VECs mkj8mQZnB0Jy89/+wy8e6XXq2eeRmk2nIKe0Uu/xVMO4/q9o8tdGC5x+s9sSKCv7Bh2n ofJSPaSUV4jcfr2NyGPC/Gp8LGRwRljm3XrvOTPW5Y1+OTXNF1ptQkkubjadVG3vhCak Gk5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=BZzKmMo+qjjyommvsHqCKRlBwkTvNOIM1AtqhVGSBu8=; b=sKA9ZB158YLg/hYdLP67JJWTKolfdt4/x1wC+91hJeyxAf2+T3OSA4uWFwRjhBGIvA T7YMTsF7XYgSElicdN+EU2WjcwtVqnaoEYJbKEPSQoZnPEBjq2dTtermYQIsi0XVt6B7 xaRBkCfpfF3Jj9sXDdW0ucioHaNtV/KuYjx/sG4HvB0SljjXMWowQxesbgwpB/Zdahdd 0S3AZ0omVRoWDqn6Kk866Hfc1YyC668XAkmYT3tedUN/ZE/5vH4Qez8n9oWhz4GaP7G3 WEpdHqDgU8Wy0c/ipe6nK/kuhiE0sGvaN8Sjb2Fy7RmwHucy5Hs0Qb+B/ZXdWgy+9ezr p+Sw== X-Gm-Message-State: APjAAAXZs/uuhaVBO4vslDmKQQId0SQa8AKegeYNKj7mKyqF3904Lkoa Ft2Pg/eeyjw6y/Fq0+6EdTOWOg== X-Received: by 2002:a62:2fc1:: with SMTP id v184mr24439025pfv.258.1556440365813; Sun, 28 Apr 2019 01:32:45 -0700 (PDT) Received: from localhost.localdomain (li990-117.members.linode.com. [45.33.40.117]) by smtp.gmail.com with ESMTPSA id a12sm31960518pgq.21.2019.04.28.01.32.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Apr 2019 01:32:43 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Mathieu Poirier , Robert Walker , Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Leo Yan Subject: [PATCH v1 1/2] perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet Date: Sun, 28 Apr 2019 16:32:27 +0800 Message-Id: <20190428083228.20246-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Fixes: 7100b12cf474 ("perf cs-etm: Generate branch sample for exception packet") Fixes: 24fff5eb2b93 ("perf cs-etm: Avoid stale branch samples when flush packet") Signed-off-by: Leo Yan --- tools/perf/util/cs-etm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 2.17.1 Tested-by: Robert Walker diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 110804936fc3..054b480aab04 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);