Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3141537ybi; Thu, 18 Jul 2019 21:50:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCLM8T55UId5Hy0Ik8btRQ/hF0FaNVX0tctwcME7WAQgY2fgbFGjEzuEebUUwkRugGCvBo X-Received: by 2002:a65:4786:: with SMTP id e6mr50587677pgs.448.1563511854042; Thu, 18 Jul 2019 21:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563511854; cv=none; d=google.com; s=arc-20160816; b=yQ564XTNnohuIx/e51BrQsIKqTPvRY3a2azfomTWCANpGmKZnCjVGDJdbWrsE6Jfu8 sL6XeBhd5imbJZPSArKQ7+9j9fth6ljq9hVARLt62UhCx+vUkEmcEoqR6y4SV8Xec1iK aUelQxjcCcQR/Y5DfzuLUgQTa9yN8E3LrheiSHoWhzaJVxQ47IzIVNgRq4qxx9vPoNSc nqfwiuvdviyzT0xPt1oyTXT5UrU1LrdxelyxV+rG1fOh+jvb1RGNEfMAssb2RWfswEsP 3f/Mu1GCUjzlVm7LMhXIuo9utt5IffT4JwZaBe7FvI0kG4ka8W6VJyNiNppEYDnlIEVJ EmTg== 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=EQuU2dxoMZnKXt988MipTDLYU+1at46CXMltGhojHo4=; b=cUjlSpjJ25buABgtU4GMYus6MewqZf+HjjZV8niAl0BCOhc2/xieomyYfURTZzubSQ 8QVxMwldfd3lFqDVyQM7S+45dm9mk4fppz+v403FFKaMT/PjefQQxUs42nMZ0Q4JP971 UbHsKh+s8erM2nAaCUQyntBdZOXO8AUvMEI87DkOjAUYliVOOX0Q5P9zIDDRanvcbt2Z UC+mZJ2h0Zt3wXRkQ+x9q31Y3nUEM58EkmA+fvp46w7w9EQR0/xE5IslM6vrfyWFLl6E Fe8c2p8WpHp7y9RGcEHPMtm0XOancQ7/UNk++HE0+yU58nqegCpmdM1XgfkV99k1cDQG ri+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I2zV5Ib4; 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 v18si2036941pfm.145.2019.07.18.21.50.38; Thu, 18 Jul 2019 21:50:54 -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=I2zV5Ib4; 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 S1729242AbfGSEAy (ORCPT + 99 others); Fri, 19 Jul 2019 00:00:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:60636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729193AbfGSEAt (ORCPT ); Fri, 19 Jul 2019 00:00:49 -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 0F02521851; Fri, 19 Jul 2019 04:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508848; bh=j+HXwgeRUH9qfHCXxD77Ld2n1CmoxppTDIULSUBLVNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I2zV5Ib428C4sLAd9DWK1Ogii3UU8m9RCD6zby8tyGm2o4VQLzZZrnNAzCzcCIWSk bT0uXNMIjZJ/DqoW0kJYkIKA2PAVKIAWc763VN84aOZASUmWjOGm+Z27UWIgLeg2Rk XnC4SzkkW0cFq71zo/rmO2RUYibX/I5E6Wpf373c= 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 , Davidlohr Bueso , "David S . Miller" , Eric Saint-Etienne , Jin Yao , Konstantin Khlebnikov , linux-arm-kernel@lists.infradead.org, Mathieu Poirier , Namhyung Kim , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Gleixner , Thomas Richter , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 5.2 123/171] perf stat: Fix use-after-freed pointer detected by the smatch tool Date: Thu, 18 Jul 2019 23:55:54 -0400 Message-Id: <20190719035643.14300-123-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 c74b05030edb3b52f4208d8415b8c933bc509a29 ] Based on the following report from Smatch, fix the use-after-freed pointer. tools/perf/builtin-stat.c:1353 add_default_attributes() warn: passing freed memory 'str'. The pointer 'str' has been freed but later it is still passed into the function parse_events_print_error(). This patch fixes this use-after-freed issue. 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: Davidlohr Bueso Cc: David S. Miller Cc: Eric Saint-Etienne Cc: Jin Yao Cc: Konstantin Khlebnikov Cc: linux-arm-kernel@lists.infradead.org Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Rasmus Villemoes Cc: Song Liu Cc: Suzuki Poulouse Cc: Thomas Gleixner Cc: Thomas Richter Link: http://lkml.kernel.org/r/20190702103420.27540-3-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1ae66f09dc7d..e28002d90573 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1276,8 +1276,8 @@ static int add_default_attributes(void) fprintf(stderr, "Cannot set up top down events %s: %d\n", str, err); - free(str); parse_events_print_error(&errinfo, str); + free(str); return -1; } } else { -- 2.20.1