Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3793091ybi; Mon, 29 Jul 2019 12:44:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7ss/Y22Q4ZfW3Z4WgSdl21+7dAIgWyYoWGymA8MWNF5WR5jwPPa6r+e/s6OTyOXms5j/R X-Received: by 2002:a17:902:740a:: with SMTP id g10mr112405241pll.82.1564429448755; Mon, 29 Jul 2019 12:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429448; cv=none; d=google.com; s=arc-20160816; b=PDhMD1T8847DoBzViF5At+w4foR3IF9vPqGvPTi4+SXNE0GvaUtQM9ODoY9ZiYtcnK 8F7sODHdES/2QrD7AKzW40iFa5n8fp2m3EiwVApgB1s3cufXjmnlEBKyfSP1ZxwZRU+W +2odD+tdCi4G6LVKRoFoqVElaXC04bEd1s03ZdYAvzDOYu0bfcpmqcvqko2uyAILxZRT uzFrxUoqzezuJxAqszAPpCALrP1rG9kDqdWuTtMucjVwd5GcpEvYzzzKzNPTesJjZvsN K00TzfakHnd5khfNNTrmh9emNK90LNHeTRNP75lANmvubmQkTB4cgfg129LTxsbTQ7ki s0Dg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ldTcfdw57XhOQSUSytlwU1AzHslsBRBYQwS5ZvwQoA0=; b=uUu9SEP0lV/4UGKj/C0jZL2sVCWYl2JhfGZH2LYM3VtiESBReSRYHhVHowMkSThN8f OpVdGU+96dBOmBCYZ1Q1ullQXQPPbbyO01s7l8BLn1+RfC4PwXsaTQQvbFf9DdTZCBAK v4n4lLk0Pds48fom88lb8/b1htXsLY5infkIBJca0YAchwWydChJSnJxgm1lc11LAJPs 8vf46z75++DC2fD/d5LwHeczZrcTrqWb/mGefLxUkvyrbxjlPX0aLX8DpVPdP04nk2Ux k9Xb4aWPk29ZoaDI7AMK/JefwXgX5O8pAbqw+eV2lJRDe4FJSSCXZDiVe5jlHqS+YiWK uNiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0AxitwQs; 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 u18si24536579plq.311.2019.07.29.12.43.53; Mon, 29 Jul 2019 12:44:08 -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=0AxitwQs; 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 S2389546AbfG2Tmn (ORCPT + 99 others); Mon, 29 Jul 2019 15:42:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:58596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389536AbfG2Tmm (ORCPT ); Mon, 29 Jul 2019 15:42:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 4D920217F5; Mon, 29 Jul 2019 19:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429360; bh=PC1jyJSYs8kQGazeAblx2dFnoYd09Pwf5CS25k/MkAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0AxitwQsiE4X/Hky0vsCd+z4OZKGnaknPMUvIQO6ybI0R9LjfIo+mn9Q/jsCEofuv oYsvoHFtMVRu6DqXP607AQR2MNG4UquaZtHh8IaYsI2HEUFhKkITa9gRBKD12JiwTI 7uK2GgMmrMiVchmDwFMKM3MWYVs9i8RnoRAYWORo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leo Yan , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Alexey Budankov , Alexios Zavras , Andi Kleen , Changbin Du , "David S. Miller" , Davidlohr Bueso , Eric Saint-Etienne , Jin Yao , Konstantin Khlebnikov , Mathieu Poirier , Namhyung Kim , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Gleixner , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.19 071/113] perf annotate: Fix dereferencing freed memory found by the smatch tool Date: Mon, 29 Jul 2019 21:22:38 +0200 Message-Id: <20190729190712.439276151@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 600c787dbf6521d8d07ee717ab7606d5070103ea ] 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 Signed-off-by: Sasha Levin --- 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 c357051dd2b6..daea1fdf7385 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1079,16 +1079,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 = ltrim(*rawp); return 0; -out_free_name: - free((void *)namep); - *namep = NULL; +out: return -1; } -- 2.20.1