Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3748068yba; Mon, 29 Apr 2019 07:55:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKuHY+xyOwcfmKLbZVg+X2s9BStdGLY+sOCMFKgs98Bx6ZT2cPkZsyCQPTLhX813bDg8iM X-Received: by 2002:a63:ed4e:: with SMTP id m14mr60390656pgk.182.1556549726058; Mon, 29 Apr 2019 07:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556549726; cv=none; d=google.com; s=arc-20160816; b=rq5P9tYWsYzsVpcTJbSao6vugmyodSTHkfmn2+nOr8xZvOTmjb/XvUfEPEXJATK5Ui 4aNYTJcp0eDhudfCYewZ21ppFJ6ToDYg9DeooXa7uEDJL/zALUufmKTsDqlq+8d7y98w QYi+s6IWwaQeOIHNVlZC9xu/C5QWfY0rMogD0vXibhwkuUolAgL5K7gNntmgAcZW/cYu M1e3RQu8RAxauLzRN6tnvIoHqPdg2C5/QhrjBQV7yCkdQgvX9znDjed7you3dW4f6V+f 7Uue7xKcUPwuKuX5Cah18wR/wbQ4yN/ZqpzDneltyRJJh6iDxAXUyhmvic5trmNOgytx AcUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=PiUaB6pcDx6TqfcQVf727+J+qC+Bf8hKgAYHZ0BQ3mc=; b=pPRii9HYulAHs7reDAlWEL/WUSZa7FJD8rOxLdWCXKBFB7wA3RrB8aUti8OvFhfZ14 vzBWrri/fnRHMaO8hjTNiWYz3frdYVT3gt6p8U7V0mXRnbrbCbq7yopTvMH8r4/FIxKU G1pYTkGhNMApF02cQgQ2YEPKdCr6gBouXTiXBozwGoCgiH8vrCMPd1gcI6nUhstQrkDg KBP8dfcX5woTIczZYFg4/Ip7CrhBGqgHpDCSQEEkFlb7XbX8Ydnl7V4tB1vrNekruVli IufJ9aWQPqH8W++kkHeAk+xSiFqqyU8A82DeGPc+Nbfbr6Hqoyi4txY1eLYxXZ+8MigK X5Ew== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o86si33645289pfa.270.2019.04.29.07.55.10; Mon, 29 Apr 2019 07:55:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728606AbfD2Oxk (ORCPT + 99 others); Mon, 29 Apr 2019 10:53:40 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:59450 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728396AbfD2Oxk (ORCPT ); Mon, 29 Apr 2019 10:53:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D7A6E80D; Mon, 29 Apr 2019 07:53:39 -0700 (PDT) Received: from [10.32.98.83] (e111474-lin.manchester.arm.com [10.32.98.83]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 187983F5C1; Mon, 29 Apr 2019 07:53:37 -0700 (PDT) Subject: Re: [PATCH v1 1/2] perf cs-etm: Always allocate memory for cs_etm_queue::prev_packet To: Leo Yan , Arnaldo Carvalho de Melo , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20190428083228.20246-1-leo.yan@linaro.org> From: Robert Walker Message-ID: Date: Mon, 29 Apr 2019 15:53:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190428083228.20246-1-leo.yan@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 28/04/2019 09:32, Leo Yan wrote: > 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(-) I've tested these with the trace from the HiKey960 and the segfault no longer occurs Tested-by: Robert Walker Regards Rob > > 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);