Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1956003ybi; Sat, 13 Jul 2019 03:56:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8JSc6k8KEY7KEl9abMoTVmrbQEOcaNi73l6AQyV2UOlcyXKLteJOQAZpIiY1gYuFDPMSg X-Received: by 2002:a17:902:2ae8:: with SMTP id j95mr15764425plb.276.1563015408923; Sat, 13 Jul 2019 03:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563015408; cv=none; d=google.com; s=arc-20160816; b=ZNo3LddSDdIBlCkdUwhO4xrRfc3gn0EnR/eogK7t0eJN0zRgRVSM8cGrq4zSK6pfeK Wq3kf4VTNBbUudYJtMpLlbmRUHhQfK2V7tUGjQUPDD1oD7Wq3YkH06F/zZyEocmYLzUE Z454PO10yBB5jb79GMvt58Sj3LWGf2EJuqDfBjKbune2w0eIr8sDjldZmJp0YymsrSEq W+UAE/XXHKgzWyhGUZdYpJgV/j8kGBG83goPbyYdaLRXbz6kMItv+8fZnYI9+bY0JfFY Dm3wn0fEg/SKQIDL7DgCEDzZx4b21KuxLR5V5ykccfX4iJx8br9F9rte2S6CzcZ7DEIw jSxw== 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=F5U8Yp4oUEP66inJtwpbu9ERHqdQCKl1kYd7mg4mMLc=; b=xn0SRDuT2eOnG7ilcsr6Pp+bfNdjG9awD++n94wKbL9Y+XGkBID5K5v6dl8ZQyBr7X mpOQSOKE4/dy7wiWgJCEPUe4+UXRUr7iZkyRkvIff6gOQfuKk8/Ago6011fFb1y0AhDG 5o8hE9q1r5KNx2jsJn8tE3IEEI2Sf1ot2DWllL/57pZ1XC4kHHxgKNB9x5YFnKRe6X5l g1pwzwZgeM0FInp4fOC/cxjrP+WdYgA8YYTg/4ZZCG//T3q3Uc4730X0ES53f7E9HP6N RJg9fI4jDfrqg6/2vHjQCz1+EqoBICD9suxswPHeZgDpz0/+TyG9lJjPITFS8a3z4ryI CsAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019061801 header.b=OUo4XWUd; 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 u20si9923093plq.421.2019.07.13.03.56.33; Sat, 13 Jul 2019 03:56:48 -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=2019061801 header.b=OUo4XWUd; 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 S1727756AbfGMKzW (ORCPT + 99 others); Sat, 13 Jul 2019 06:55:22 -0400 Received: from terminus.zytor.com ([198.137.202.136]:43455 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbfGMKzV (ORCPT ); Sat, 13 Jul 2019 06:55:21 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x6DAsYMe3837823 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Sat, 13 Jul 2019 03:54:35 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x6DAsYMe3837823 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019061801; t=1563015276; bh=F5U8Yp4oUEP66inJtwpbu9ERHqdQCKl1kYd7mg4mMLc=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=OUo4XWUdtuOe+RYDlse1HYJ3j6gm3EhAgN46mv1tJsNFZuSD3PNekbxPfFSszMtGm c097KuW+pcaPnMxHehJ2J/DrLVWWVf7SzdhKkDp2zq7rBLZxlShcJMesN19Y1uCMNs IBIqvq65OowlXJFFncwrW4+JgJDI4jydL4vExYq+gvHXT96PqnmK0ELDN1KLmFnL9d iEbJFv16m8Q6ScZRYXbqXUZmqiVbC9h1PrJ1Oxuf5DvfEZVlPyIkWaQQovMasrwLb2 Dp1TNZ+n5Em4EGrOBym02Sgy/hc84dhCPPQ+DwFVAUIbDzLtaf/QaWQSmwU9KDNQXf mVbL81UbIPK6Q== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x6DAsYMG3837820; Sat, 13 Jul 2019 03:54:34 -0700 Date: Sat, 13 Jul 2019 03:54:34 -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: hpa@zytor.com, eric.saint.etienne@oracle.com, davem@davemloft.net, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com, mathieu.poirier@linaro.org, songliubraving@fb.com, dave@stgolabs.net, mingo@kernel.org, peterz@infradead.org, suzuki.poulose@arm.com, leo.yan@linaro.org, acme@redhat.com, adrian.hunter@intel.com, ak@linux.intel.com, tmricht@linux.ibm.com, khlebnikov@yandex-team.ru, changbin.du@intel.com, namhyung@kernel.org, jolsa@kernel.org, alexios.zavras@intel.com, tglx@linutronix.de, alexey.budankov@linux.intel.com, linux@rasmusvillemoes.dk, yao.jin@linux.intel.com Reply-To: alexey.budankov@linux.intel.com, linux@rasmusvillemoes.dk, yao.jin@linux.intel.com, ak@linux.intel.com, adrian.hunter@intel.com, tmricht@linux.ibm.com, khlebnikov@yandex-team.ru, changbin.du@intel.com, namhyung@kernel.org, jolsa@kernel.org, alexios.zavras@intel.com, tglx@linutronix.de, mathieu.poirier@linaro.org, songliubraving@fb.com, mingo@kernel.org, dave@stgolabs.net, peterz@infradead.org, suzuki.poulose@arm.com, acme@redhat.com, leo.yan@linaro.org, hpa@zytor.com, davem@davemloft.net, eric.saint.etienne@oracle.com, linux-kernel@vger.kernel.org, alexander.shishkin@linux.intel.com In-Reply-To: <20190702103420.27540-5-leo.yan@linaro.org> References: <20190702103420.27540-5-leo.yan@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf annotate: Fix dereferencing freed memory found by the smatch tool Git-Commit-ID: 600c787dbf6521d8d07ee717ab7606d5070103ea 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=-1.2 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_06_12,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: 600c787dbf6521d8d07ee717ab7606d5070103ea Gitweb: https://git.kernel.org/tip/600c787dbf6521d8d07ee717ab7606d5070103ea Author: Leo Yan AuthorDate: Tue, 2 Jul 2019 18:34:13 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 9 Jul 2019 09:33:55 -0300 perf annotate: Fix dereferencing freed memory found by the smatch tool Based on the following report from Smatch, fix the potential dereferencing freed memory check. tools/perf/util/annotate.c:1125 disasm_line__parse() error: dereferencing freed memory 'namep' tools/perf/util/annotate.c 1100 static int disasm_line__parse(char *line, const char **namep, char **rawp) 1101 { 1102 char tmp, *name = ltrim(line); [...] 1114 *namep = strdup(name); 1115 1116 if (*namep == NULL) 1117 goto out_free_name; [...] 1124 out_free_name: 1125 free((void *)namep); ^^^^^ 1126 *namep = NULL; ^^^^^^ 1127 return -1; 1128 } If strdup() fails to allocate memory space for *namep, we don't need to free memory with pointer 'namep', which is resident in data structure disasm_line::ins::name; and *namep is NULL pointer for this failure, so it's pointless to assign NULL to *namep again. Committer note: Freeing namep, which is the address of the first entry of the 'struct ins' that is the first member of struct disasm_line would in fact free that disasm_line instance, if it was allocated via malloc/calloc, which, later, would a dereference of freed memory. Signed-off-by: Leo Yan Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Alexios Zavras Cc: Andi Kleen Cc: Changbin Du Cc: David S. Miller Cc: Davidlohr Bueso Cc: Eric Saint-Etienne Cc: Jin Yao Cc: Konstantin Khlebnikov Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Rasmus Villemoes Cc: Song Liu Cc: Suzuki Poulouse Cc: Thomas Gleixner Cc: Thomas Richter Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190702103420.27540-5-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/annotate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index ec7aaf31c2b2..944a6507a5e3 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1119,16 +1119,14 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) *namep = strdup(name); if (*namep == NULL) - goto out_free_name; + goto out; (*rawp)[0] = tmp; *rawp = skip_spaces(*rawp); return 0; -out_free_name: - free((void *)namep); - *namep = NULL; +out: return -1; }