Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3100562ybi; Thu, 18 Jul 2019 21:02:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzj13B3hrc6kfpCERoCKvTIGDzffMHBZWjpKab2i+YHxx4i6bNlo5EAwjtPexkGqVdIOpi+ X-Received: by 2002:a17:90b:28f:: with SMTP id az15mr54412567pjb.18.1563508960398; Thu, 18 Jul 2019 21:02:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563508960; cv=none; d=google.com; s=arc-20160816; b=n//y7+tJvxKSbVSYnhc9j8CqQT3tfxL5zvY8TNMK274cyWSgSvVt6uhCEed8LAPM4g gscwFR7v+2WM/ngvt3oyLllIHbUPgClbkC/HpnMXAv+EP+f0YvbOaOJPfX2/UbfALZyY f+xtzlbpHD1qrO6gEN62ILgnrAHI+E7156WJmm9Ovewwm3GiOen6blSWa7hivWYMh/A2 zrbiXwXl4AqGUQ3XBO93kQtrNTZ8qp2/dw1ddlMsvuthIxRSgokTLK5ZkYm59Sj71OHF qFHIh//Ud8GmDHRet0LHrSMSE/jlFONcU0P0FB1eqxAGtkVr3PAvcztGleVsWE9jzntn /FFA== 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=dBl9Igq4sH8QM+H0PTdL0InqrpW3fZJasvuHWUIilT0=; b=pWX5HbFJt1ji3wMFyCuK6BmW4H37RPKkSg86pmxPXIILwDftRm9RuJxYA8Ru4n6pad YGFf5IDaofT31f956zz+8xbunXQ93ji8fD4oa0/8tjHCGbjotZx0fZ8Z6l7rI4/CAsst lFVDcm+uUDgjLE1s/Th5OylJAXWdoZeJPDkFp7cvn3Pgbvi/7RgGHBvn6Vg27nPhXIQr DzC4IFaRgf3kqSDuW+HA5jjJ/bfJH1vdaFj9S0RekdjU1wIuDnvIkwNqemrB9zefyrvq AizVU+0eTpsoodlvH5mYlGpd6Kh0LjLATwYC9aLsPTWtFjiKV8UGt9pORtBrBXASzlRG H+Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HiMAY+5y; 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 7si4272232pfh.38.2019.07.18.21.02.25; Thu, 18 Jul 2019 21:02:40 -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=HiMAY+5y; 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 S1729368AbfGSEBQ (ORCPT + 99 others); Fri, 19 Jul 2019 00:01:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:32876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729343AbfGSEBM (ORCPT ); Fri, 19 Jul 2019 00:01:12 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 934A821873; Fri, 19 Jul 2019 04:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508871; bh=5v9AwvmqW8ol/k2q/4YRiUqpBV497MFwNfAtTgp0llU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HiMAY+5ytDiIAoM6BOUkwuiwIPAV+XroEg8TvByumNWov1db6ZHSLFa2JAaNQjMt7 oHg+oEnq2sUcbreO46CLO/KEoDaflu96q4QF+sEqYKF2y1V2vB83ZTOfiedDdXMdCK dsHtDMqXwjwOdD4MKOawj1hWpPnd0TKbZD0onxbI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: 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 AUTOSEL 5.2 129/171] perf annotate: Fix dereferencing freed memory found by the smatch tool Date: Thu, 18 Jul 2019 23:56:00 -0400 Message-Id: <20190719035643.14300-129-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan [ 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 79db038b56f2..02d0df0de3bb 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1114,16 +1114,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