From patchwork Tue Jul 9 18:31:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168755 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896015ilk; Tue, 9 Jul 2019 11:31:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNfFNkZW0nPFKbKfYsmIanmUJQiNLaIFiU0r166OIzhG4ApkCbWw4qRIOeiqbkvmcqqB1t X-Received: by 2002:a17:90a:898e:: with SMTP id v14mr1586524pjn.119.1562697110393; Tue, 09 Jul 2019 11:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697110; cv=none; d=google.com; s=arc-20160816; b=Cty/JKoykZGPjRJWw+H8ccz8HSwa1Gi1MKNpB1zVmkBjVisCt2LJr6+w/7qTyTyPSm xWwxLhwGS5wDR4gArx9+Fbr7ICSIk3Uw85D/gmh00Is7OyHO8XdRVBufm8/JScRVzJ/J pEzYBYb2+EasXd7fYxaeQqVNa4qrALP6S/j9M+J0kPxXnXo6iw03mmuyUO2O6DGQ1p4z 2jS/VA3hhMGBs4/VoqagNe/+Yx1F2y28aEsXe4uUjJuLkK8NYqArZFAvcgKdEiqPtm0Q C88w/UwxzEVx4XTGxSMn3Oy2bGnugw8Td2lpCd1ebPwQWAbYcQ+cDNnoAWp+i0SV2FY+ iz+w== 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=BhCV8DtjOWI/nh3PnXd5gSJVWobdN5eToBycnnF+4UU=; b=rSNwB5KVweWTzM6gtuODv+xCe00s54ZLxS8Xp5W4qIwX1sNwispGBIjZxQq1piWQqE rGRjiAZxhYEw2T0CUH9D+8iMyDyIAGEDE38r06gBMSEinLLfeGvrOMqJn4x1jd1Od087 A5Z2c5HFIs+QhXGvF6dUIv/Aqs99g0Yhyr2GkKSJs6jklYaTYhUS/yQBE10GYB3ojZcR +f8acI5jHILIavC3JNugNSji3WBW3cGWJ6cTlVFRjmpMdbccNMgLpW3Kb1QEV7WSE7UM 1lM9SxQ5DxL0AVPIESrB8MTAFwOFlmPiF6XFw9UVsmF9DoS3JntN2YT5pjlA89wmunlG xufg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F2bTdox0; 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 w1si18161152pfn.129.2019.07.09.11.31.50; Tue, 09 Jul 2019 11:31:50 -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=F2bTdox0; 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 S1729042AbfGISbt (ORCPT + 30 others); Tue, 9 Jul 2019 14:31:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:52976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfGISbs (ORCPT ); Tue, 9 Jul 2019 14:31:48 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 A82CA214AF; Tue, 9 Jul 2019 18:31:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697107; bh=aVZ0iIxfrqicomtqFbAEDq8CdAhVe14Oy+wL/zknopw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2bTdox0H8xFhe/mRht+zvTN+TcE0KZL6eOYL7Iz06XZSNfhoYDeICfpNcc8HlFmh qffXnJhZjtN1ZwyWplr3H34bUl2VVKmNx01Fi5UBTmfdAgHzKSBsOg0I94n/LbQfqd jSkDNMv8Doc+kAOxjTV9cmEcolzf/VhAHmMpoSGY= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , Arnaldo Carvalho de Melo Subject: [PATCH 02/25] perf stat: Fix use-after-freed pointer detected by the smatch tool Date: Tue, 9 Jul 2019 15:31:03 -0300 Message-Id: <20190709183126.30257-3-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan 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 --- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.21.0 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index e5e19b461061..b81f7b197d24 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1349,8 +1349,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 { From patchwork Tue Jul 9 18:31:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168756 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896125ilk; Tue, 9 Jul 2019 11:31:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwKfvvxXuJteLDAR//nIdoS9d8h47fl89v6OJ5WkeHoh0gaH9bNS1NnyZGurx4V19W5+bxJ X-Received: by 2002:a17:902:7c90:: with SMTP id y16mr34343764pll.238.1562697117685; Tue, 09 Jul 2019 11:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697117; cv=none; d=google.com; s=arc-20160816; b=rWKYyYp656xTLdYLU5pia+Zjrx2c2qthBLLvh6TrFRtvBoqdWtAb9vlSK6QMSxhhFn o5Y4xx8khLyztY1/z76yb58NSUJ9Awf5d6MwyEQvtCsDsnVy+Dk/VSCtVGOlYzrty366 0T3xtyAjXDljbm7fRfA5LSIxojKvTbs08HCT6UdYmCSHJdVBxyEhaDUky0Ra6kfqdlWA 6xjIeA9+3dcm2aQoERKNALto95yPrfFRvsCEXjJsWvYpGxDVfRWxqz+M6Sxm4RqNtLjK Luvh901j7A5O+rJBI/gSVybn1Z2D+NpjQZs2KC9pSP8+oWhDf6T8M083GbzsGgSWPa4N dGKA== 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=I8XknWA6iYpcZTURSxx8UuYj2uePVMSg9pXuAkUxRas=; b=YS0J/DkzvzBfpeYp+6vPCDIoqvk1TKzAa3aIpGupJuSxnp9ThzJkDjBlKgGtXnh0rI HIqAopZ91wN4Mrznq+WYJ7IRLLqL/w/AGa9G1AOCeZRw8zkKy6sDNUQFTNVBF+3392x0 bga6XnRSX9imJblhhB1r+77p1RXLqxzw1MW1Dy72EmCrq/g1d1r0ejBES+i0M+QCDr50 fc+48pkGlKsJbK3N1+NatC4pm7P1y1K7KkTo8xqKv8HRxaA8Fy15CWex5zocIasR/HNU F2kz8QEnbSrmBowKnUBVD3yGSzNrxszQ8fSmLXhEVarh/kmKZ44f/MWi8357BBzk4P3h 0mlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WttUJ7bQ; 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 t7si16515593plr.27.2019.07.09.11.31.57; Tue, 09 Jul 2019 11:31:57 -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=WttUJ7bQ; 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 S1729052AbfGISb4 (ORCPT + 30 others); Tue, 9 Jul 2019 14:31:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:53156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfGISb4 (ORCPT ); Tue, 9 Jul 2019 14:31:56 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 34BE4216FD; Tue, 9 Jul 2019 18:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697114; bh=/r3kNfehywaYBWJZ3L/w2X8MX2iuc/x3OcDG99w2lbc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WttUJ7bQp7Fy1xQD0OuMxektnM/uEuj/z08KGlKdD1Q4WBH3eV2aMY66Ed3df4/Qn oZT+CRuUjbD9KpDjbUM7Oo36DSzK6WqhnBw3MvFN3e77ioNz9+Mhrq/Vq26rIxZrAw /ntkinYg+LWlj8Uosc/3N7EXKLg/A+IxlxNMKjyE= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 03/25] perf top: Fix potential NULL pointer dereference detected by the smatch tool Date: Tue, 9 Jul 2019 15:31:04 -0300 Message-Id: <20190709183126.30257-4-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/builtin-top.c:109 perf_top__parse_source() warn: variable dereferenced before check 'he' (see line 103) tools/perf/builtin-top.c:233 perf_top__show_details() warn: variable dereferenced before check 'he' (see line 228) tools/perf/builtin-top.c 101 static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) 102 { 103 struct perf_evsel *evsel = hists_to_evsel(he->hists); ^^^^ 104 struct symbol *sym; 105 struct annotation *notes; 106 struct map *map; 107 int err = -1; 108 109 if (!he || !he->ms.sym) 110 return -1; This patch moves the values assignment after validating pointer 'he'. 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-4-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-top.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 6d40a4ef58c5..b46b3c9f57a0 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -101,7 +101,7 @@ static void perf_top__resize(struct perf_top *top) static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) { - struct perf_evsel *evsel = hists_to_evsel(he->hists); + struct perf_evsel *evsel; struct symbol *sym; struct annotation *notes; struct map *map; @@ -110,6 +110,8 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he) if (!he || !he->ms.sym) return -1; + evsel = hists_to_evsel(he->hists); + sym = he->ms.sym; map = he->ms.map; @@ -226,7 +228,7 @@ static void perf_top__record_precise_ip(struct perf_top *top, static void perf_top__show_details(struct perf_top *top) { struct hist_entry *he = top->sym_filter_entry; - struct perf_evsel *evsel = hists_to_evsel(he->hists); + struct perf_evsel *evsel; struct annotation *notes; struct symbol *symbol; int more; @@ -234,6 +236,8 @@ static void perf_top__show_details(struct perf_top *top) if (!he) return; + evsel = hists_to_evsel(he->hists); + symbol = he->ms.sym; notes = symbol__annotation(symbol); From patchwork Tue Jul 9 18:31:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168757 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896236ilk; Tue, 9 Jul 2019 11:32:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnfBwTtw8Qlyj92JSW0fMq5n5pfSrlUH3ElX0Lg6g8GD9T/eEY5XzqHsjjVyPhU1eCxQtD X-Received: by 2002:a63:6c4:: with SMTP id 187mr164729pgg.401.1562697124693; Tue, 09 Jul 2019 11:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697124; cv=none; d=google.com; s=arc-20160816; b=vaGEwkVbVSNiqNFEjnp6cOLxHfe9fDSGubEhFwy3AyM/5NILQEubdP6jgAlu7rgfks TGMvrO9SAdvdwRwFn7DRtux7M/M/0DpaEdQlhyFa1h7eRPu3SBJiQ6HxwIC2aPvnDBJx Ja1BhX7AWVq6jxhEiFbBpgwDn89iWVG3zYZq12K1NAXhjomQCxB8glkwcDXaOB6qo9PT 3MWVnfpJNoxPaahf2BqeLyDo1yMKN7AdWdum4O3uITLvdQ4RsOYvYC0GJOKemsasxwbU iy2zaiNSJNNoi6XzSgkc3gDT7G4uGU8RwSXQUZamFYk1FUcXrIE5LEBPRyndioLytmAy wNbQ== 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=XPGr3Em7TZSESLaW6HtkSjsM1hHmjB9grF4BfAvS/44=; b=vK42AlVVpWnB5eAa5E1mGLKnjnQ0VH7+eJW8xVLf0qWK6yieDkY9tQOo8Lr/dbgup5 V4I52MkakHmUDd15z+tJ8fwbndsOZdXx/dHlwFS0+0b0aQEcCuomw0P8BlR3Yx6BVloc 78oFrqQ60RV9Gw+6+8Ab9e5TQhEmHMoK0Lzbg/z54x6ZUoXmJSRxw+5STW0pSlj2n+tO FxIdId8rjwCi0LUgER8itOrJ0gQXZSbFB7XmNYBU8pY9vdzABdwo5b43xFe2GSY5Kp8f +tZkLgdz4Gj9oWhXmCC833owuB+v4KNhqwJm6jgxtgUjk5Cg+F/QHBZyVgMZD3RUd4Bt NVCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ae/0ykf8"; 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 t7si16515593plr.27.2019.07.09.11.32.04; Tue, 09 Jul 2019 11:32:04 -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="ae/0ykf8"; 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 S1729061AbfGIScD (ORCPT + 30 others); Tue, 9 Jul 2019 14:32:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:53288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbfGIScC (ORCPT ); Tue, 9 Jul 2019 14:32:02 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 583DB21537; Tue, 9 Jul 2019 18:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697121; bh=4014MKo13hkHV0d3pRWB5c8cnBeoEWRYJEclpGth5F0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ae/0ykf8ibATNOt5C+iqxcsMiu28JpUNOk20sand/gyMk/rjMDvn/8y3f2oy54irq dxUYtYetkX/2kYmlxHWifDw6s6Y81rnyC47U7Wne7cOIr0/jJDCq+gbxuy20wRMmov BlqbsYa2sSCBa5Mdkin7mmFfBNwCYfliYZDNhWic= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 04/25] perf annotate: Fix dereferencing freed memory found by the smatch tool Date: Tue, 9 Jul 2019 15:31:05 -0300 Message-Id: <20190709183126.30257-5-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan 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(-) -- 2.21.0 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; } From patchwork Tue Jul 9 18:31:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168758 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896352ilk; Tue, 9 Jul 2019 11:32:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPHLHKml/yViyV4k2RqzH8V+aOi97PJc5apBYY+ZMu/wx3+SUSIMz5LbbsTBlhmhQ7AHgk X-Received: by 2002:a63:5212:: with SMTP id g18mr31018034pgb.387.1562697131813; Tue, 09 Jul 2019 11:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697131; cv=none; d=google.com; s=arc-20160816; b=01TTC51iERbr6w0wUhGtr3ubnxcLISF4n8Kr8W1x+67wEq4/M/SPPWFuDYP9Z9ZvaB SreAGMCIKxPOrtLCuV1YVf6z8oUOi94itVPp7qprfsWcvExjqT2lq79bV9Gbd7Fhv3HX skeO7i7TLn6aq8h3xQtIT1h6ffYWdJGEUUKglynROWqar3EUrIDreQLmo7S6DYAxmzt6 u+ewYOkBuXuw6UTdx3VPkgsz7soQXP9CTcUGvnziSpQhAtdhiy0Uo7cmrfkVi0xBjwQM Ng6NHqJUSdQOZBOHZSca/1NCRQp90DPFR0CoIGLvMjMCuSVqd9I4QUvI8aN4TQvTK6Ru n1tQ== 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=yThV/wsDbOO7z0W8p5jy900zA1BoiaC/u+pr+N5bygA=; b=LwMKaKWcmbmrUop2KdWA17Qq3CUXVrIufvfeOTiPHlKZ2sc6AfzTO+zh1+haLSf/DL uIKtXgfzDzIChcmd8+bNgxVISCHVDd7xmmQc+kHbrYTpI3fGOhNpyjCn9keaACiYRQLb UlbN9LJZT8cFQHmpaOZW13dBgnv90Yi5fzL0TwcP9cu7xGSpBqstbPYJ+Rtazf/VvjX0 zqx8n7feSheYPf/HwTqgTcV9Ib8vMsEDqcGQbqYY3etHpBNxtbMnkH68mRGqi2h7NSex wz1SWW6EgG/woIKFcttFjyNukssf2enirlHojdXOlODEVzzXw32qWEP1xX8amytpmjwH xB2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R5NqjC4s; 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 u185si20804361pgd.561.2019.07.09.11.32.11; Tue, 09 Jul 2019 11:32:11 -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=R5NqjC4s; 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 S1729079AbfGIScK (ORCPT + 30 others); Tue, 9 Jul 2019 14:32:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:53464 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726592AbfGIScJ (ORCPT ); Tue, 9 Jul 2019 14:32:09 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 CFCAC2087F; Tue, 9 Jul 2019 18:32:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697128; bh=uKY1upGstB9eyiC2tvMjOQrnpwH5zhKS9cvZBMmwlRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R5NqjC4skuB80xSqY6Wwp1WwLiCweXwZ4voKnG+hZZIIGLatgkiHk+63fQN4xEqr8 SvuRJwGK0s2OPCDFsud6JvVO/9KhewPXZZLlxe6R8inbDBGyOn/YUFfL1UrrWJ82oC /KSRamxD4VurvzRcHPHPaEYLPpkeV2JjNtjxj8Q4= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 05/25] perf trace: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:06 -0300 Message-Id: <20190709183126.30257-6-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/builtin-trace.c:1044 thread_trace__new() error: we previously assumed 'ttrace' could be null (see line 1041). tools/perf/builtin-trace.c 1037 static struct thread_trace *thread_trace__new(void) 1038 { 1039 struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); 1040 1041 if (ttrace) 1042 ttrace->files.max = -1; 1043 1044 ttrace->syscall_stats = intlist__new(NULL); ^^^^^^^^ 1045 1046 return ttrace; 1047 } 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-6-leo.yan@linaro.org [ Just made it look like other tools/perf constructors, same end result ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) -- 2.21.0 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index d0eb7224dd36..e3fc9062f136 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1038,10 +1038,10 @@ static struct thread_trace *thread_trace__new(void) { struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); - if (ttrace) + if (ttrace) { ttrace->files.max = -1; - - ttrace->syscall_stats = intlist__new(NULL); + ttrace->syscall_stats = intlist__new(NULL); + } return ttrace; } From patchwork Tue Jul 9 18:31:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168759 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896563ilk; Tue, 9 Jul 2019 11:32:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPs8HdRqRe/AbIQYfwadVGglAS7duhZSH6vjFS32SrCzojlJ5TrTWT8JYfY3PYc+2scmze X-Received: by 2002:a17:902:8d91:: with SMTP id v17mr33652668plo.91.1562697144997; Tue, 09 Jul 2019 11:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697144; cv=none; d=google.com; s=arc-20160816; b=SB84A8GLSgW+0wVQTW/vXzjjS5r5eidqwNFSn6j3zKS9skMLpMZvAp8rpuh9VfQxzI Ruq8tzXpwTyAEmXnZ9bfDRsg1K9r+LOpsisvOO0+vMvVUlIzQdyuLjXdZUO2j/H+QbGc LuaGjNqMw3beJ7sV62nn10GFwwhGGwEL5871qAgeYWCHGxpF3mSyvdl5GwKqjz9Q7eeJ d8/BXDy5sT+USTbbwFOp5avSbuxxYv3ZI+ppUGHDG3jvyX6bT+moNhggKl6y2yrymOxS 2CMGmDvEjTctoaa+P/hGRWCo+sqSrZVJuvhlZ3SS0buwc4fTDHFv+c0SpY8Z6unVmjFA cVVQ== 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=tT7T/TRs6aplUF1AgzCcp0Ff/DKIOnN8nESTF2du4WM=; b=ew0UjvFrJynj8d7qlDMFci1Zd17mqj53Ba7Ik6eb8LwNeJ0tMZVxejLosXRbQ3j01p kdXW6W84GG0rn8zLH4Ip1+RPMhivnCuExRGjb3ZfOn6kbJeywc4dYtLeGhQBQK+NsR7J s2y8XxWzzTEHWg2z66CHLGrxETXqFqY5P6oKt80vNG2V9DXp7LxTzMTKflA+DOFv7NAg bGQLGBjzGjKR4lqPS694OGN9KQOmXC47iGQe+GWfmMZFSsDIir/zKrznx+HZ0wnFUG0y Jyj2aKsUEvyaipKNaPEgydXxTNA7GrKvl5xRNiXzPGKj7egkcXHUjPooBVsvYnnLkV6y FVKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ESqkemMN; 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 u185si20804361pgd.561.2019.07.09.11.32.24; Tue, 09 Jul 2019 11:32:24 -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=ESqkemMN; 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 S1729125AbfGIScX (ORCPT + 30 others); Tue, 9 Jul 2019 14:32:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:53568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729094AbfGIScV (ORCPT ); Tue, 9 Jul 2019 14:32:21 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 2FE342171F; Tue, 9 Jul 2019 18:32:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697136; bh=JjyDoauJ+WYz56YyYDKCZ3keOnFJy6NiR6Q0BlDn5EY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ESqkemMNPwhyxKwOQR1gPTIAR2g071vi5m0lY8XDTWTk9gxiQcipmE/K7Zan3h6h4 Hf3SBt9jwNbo5P0pUS1hf4uidv2b5RDrvxbykDHuwGO8ZT1TTc4GojtJ/VnVOuxZet b7Jb7VD996e5+fP2saq8AJCYYDH9elce/osSNPYE= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 06/25] perf map: Fix potential NULL pointer dereference found by smatch tool Date: Tue, 9 Jul 2019 15:31:07 -0300 Message-Id: <20190709183126.30257-7-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/map.c:479 map__fprintf_srccode() error: we previously assumed 'state' could be null (see line 466) tools/perf/util/map.c 465 /* Avoid redundant printing */ 466 if (state && 467 state->srcfile && 468 !strcmp(state->srcfile, srcfile) && 469 state->line == line) { 470 free(srcfile); 471 return 0; 472 } 473 474 srccode = find_sourceline(srcfile, line, &len); 475 if (!srccode) 476 goto out_free_line; 477 478 ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); 479 state->srcfile = srcfile; ^^^^^^^ 480 state->line = line; ^^^^^^^ This patch validates 'state' pointer before access its elements. 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 Fixes: dd2e18e9ac20 ("perf tools: Support 'srccode' output") Link: http://lkml.kernel.org/r/20190702103420.27540-8-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/map.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 6fce983c6115..5f87975d2562 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -476,8 +476,11 @@ int map__fprintf_srccode(struct map *map, u64 addr, goto out_free_line; ret = fprintf(fp, "|%-8d %.*s", line, len, srccode); - state->srcfile = srcfile; - state->line = line; + + if (state) { + state->srcfile = srcfile; + state->line = line; + } return ret; out_free_line: From patchwork Tue Jul 9 18:31:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168760 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8896651ilk; Tue, 9 Jul 2019 11:32:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjY/9BvER9bep6jlBAd2wEppnOB8mXHcsTxgCAu0T9TiPWWD3OnBwcxZt+5FfdO9MoFXKB X-Received: by 2002:a65:6081:: with SMTP id t1mr18894787pgu.9.1562697149645; Tue, 09 Jul 2019 11:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697149; cv=none; d=google.com; s=arc-20160816; b=qANsNr8R3klYhwKsGUGI+SVVvm26alogGgD7Z5CNThahd30JtD79g5SkPDY9oVK7XY AW2NO2EndMxXBq5OHmHo/X9DxqInQxG8cTMsifTwj+pQQM6vd5/OrLTF/WHSSZbjhSFn asYLu6iB+y3mM9jNgSNvVZcUjiD+irceXQ79Jm5EqucI3u3aMkhae26WKeGuTq+tK/z5 oJZOwdrYbBiZnbMGKoB+vK+A3V+eygz0iXL84m9aqa/poGjehTDIBsrWly+IJ9XBClVb MJsznfp3hFyv0fw/CS4tLOeOMiQc2cV8FXtjyWJGJ1nveW6LMQfQfzA6yOkx5luer1IL Hvew== 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=4OXxn3DW2sslp44VkLFd6P05tzxSwup5/MayWZIMCbo=; b=N/4C7SAEjzI6nmqvd+gmJLyojYVLggGkNCRUkKsJOlQFz6YDiKGbdCWA4X3hM/ET/Q FHn7TTOcxM5LyuK4slfKhwCqw0sCc1a8zyWUaipE9o81qBTftVvvj/hU6JqAFkGAeHxb /oUzqJmkIWJMNHJnO0B1c2xDX7XIKEIsIMmMr9ezDW3xmnnpue+YaHvB8iNegzS/HJCL xhq/I/uXwKDMb+CMHZQXZA+RwI3QGD4AvbjMfS7Vv1w1ycla4teEnBhSh74jbOF/2vrC ueTGHpQuiQrgdC4ZL2dpdDM2a0drdFJbAlxtZmcjZnvrt01lj4FhugJlOryKI10IOttw umsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="am5/w0YM"; 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 o19si24636534pgl.389.2019.07.09.11.32.29; Tue, 09 Jul 2019 11:32:29 -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="am5/w0YM"; 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 S1729140AbfGISc2 (ORCPT + 30 others); Tue, 9 Jul 2019 14:32:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:53836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729094AbfGISc0 (ORCPT ); Tue, 9 Jul 2019 14:32:26 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 7FD7221743; Tue, 9 Jul 2019 18:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697145; bh=LzlQIF4A49g3wOWfYMbmSZepSv/fUbacMvy8iT48q8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=am5/w0YM83bIKrJUqGCW+batDUhjaHXgi7HVsURprAOsei5iju27lqv0YAlsH85VU gd182DK8TEn/+xmW4r92QB0t6z3ZrhmYxFogvmwnbbPbPg2OAa5pP6UQ1vBBKrZeue YwL8273Rnsy8SQJQpTxUxUFXfQEjK59/9glm9X5Y= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , 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 , Peter Zijlstra , Rasmus Villemoes , Song Liu , Suzuki Poulouse , Thomas Richter , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 08/25] perf session: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:09 -0300 Message-Id: <20190709183126.30257-9-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/session.c:1252 dump_read() error: we previously assumed 'evsel' could be null (see line 1249) tools/perf/util/session.c 1240 static void dump_read(struct perf_evsel *evsel, union perf_event *event) 1241 { 1242 struct read_event *read_event = &event->read; 1243 u64 read_format; 1244 1245 if (!dump_trace) 1246 return; 1247 1248 printf(": %d %d %s %" PRIu64 "\n", event->read.pid, event->read.tid, 1249 evsel ? perf_evsel__name(evsel) : "FAIL", 1250 event->read.value); 1251 1252 read_format = evsel->attr.read_format; ^^^^^^^ 'evsel' could be NULL pointer, for this case this patch directly bails out without dumping read_event. 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-9-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/session.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.21.0 diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 54cf163347f7..2e61dd6a3574 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1249,6 +1249,9 @@ static void dump_read(struct perf_evsel *evsel, union perf_event *event) evsel ? perf_evsel__name(evsel) : "FAIL", event->read.value); + if (!evsel) + return; + read_format = evsel->attr.read_format; if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) From patchwork Tue Jul 9 18:31:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168761 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8897330ilk; Tue, 9 Jul 2019 11:33:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzi/Bj1pgyccUijUlZU/KLr7TV7QgNdN3NJVVHilqb8mlkm8/vuvaoydCQYfMr+14fzpf+y X-Received: by 2002:a17:902:6a87:: with SMTP id n7mr33383893plk.336.1562697190630; Tue, 09 Jul 2019 11:33:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697190; cv=none; d=google.com; s=arc-20160816; b=jzQ/Qz0brvOfSGR8NEFcCAED4KCfsFmgb0KEs32KlQCXzL0JFSSBjiTKpRh6fhYZIS VjaxEwDhqZDG+M9QirgPjO0HlF32dhxVATBF2CDMAiGRors9QJYgr8lz/CwFiv7+X36d CM65UD+jCCIuNIsBLv8mDH8A1yMZxgz6YZAtOBlw/rSzYyk5F5mvPP1QneQ5k+M5EpIm G9vBUusDFmklKGNz/q6OyK3oZ3AT/ah4Pam1FBtsbQCYY7MwqKM7zo2c1AYg3Am08cvN uyOeFLIKLccw4UECXrhv7wARIwa6WUKXZxS9ghtwBNIOsXXYWQobVBFg0VIi+2X7TePg UM3w== 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=1Tgxq9vSNl+U3rCnP871jYqkQXZuRsJvvXFtdLKzUjI=; b=g/gWiVf5wFnNUQ/4cnYs+Dt7ZG3FTo3qdr9j8lsYIoS/kYl74bEnbJ3SJeN+zVFv9y kaKHDczPhTKhxk7pdX8UXlsbHT09zwxG3nqqmhzfjOsynxTjgThwd2nw8TqN2j+g2qbC C22oT/2lcaz+0su39FP5IBrmTJL3Mv78LlGo1Hk14OJ4t1qIK0tq4Bg1XnZJ7cCyMgt3 qA+N85CjvAUcgqBi19IECJVw7TaxzyZDTvwnrcrM76RtHjGwT4THQoKKFGqygBFDCdsj OyeKyoBseAUnO0NW1AtNIZ2LD/H3UlgL6pUF68Yfsy66JRwdpub5TQT+nNMswNgJlWPl 9AzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qNlo2WDs; 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 x185si24921602pfx.243.2019.07.09.11.33.10; Tue, 09 Jul 2019 11:33:10 -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=qNlo2WDs; 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 S1729281AbfGISdI (ORCPT + 30 others); Tue, 9 Jul 2019 14:33:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:54756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbfGISdF (ORCPT ); Tue, 9 Jul 2019 14:33:05 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 E8EF720665; Tue, 9 Jul 2019 18:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697184; bh=+AHHhdCKUtduEQJ0K9mVtwS+3cT8oze/CNUH/7f6WcY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNlo2WDshInz0LxZHziyFOQ7IticF2B5seQoqdwNEkGwXb7NjkejRO2Kx6c49thQo rBHeqnABe6q9slbHT66Dfoz0U9uQScNpFgsMSgWevK8Mhyzpo18byI7gnQSeLeYlFt ontlmBoLOc1jbLxNSxMPktzZFaxgzFZLp4R7aj94= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Mathieu Poirier , Adrian Hunter , Alexander Shishkin , Andi Kleen , Jiri Olsa , Suzuki Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 19/25] perf cs-etm: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:20 -0300 Message-Id: <20190709183126.30257-20-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/cs-etm.c:2545 cs_etm__process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 2541) tools/perf/util/cs-etm.c 2541 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 2542 etm->synth_opts = *session->itrace_synth_opts; 2543 } else { 2544 itrace_synth_opts__set_default(&etm->synth_opts, 2545 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 2546 etm->synth_opts.callchain = false; 2547 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in cs_etm__process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan Reviewed-by: Mathieu Poirier Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Jiri Olsa Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-5-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.21.0 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 508e4a3ddc8c..67b88b599a53 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2538,7 +2538,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, return 0; } - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { etm->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&etm->synth_opts, From patchwork Tue Jul 9 18:31:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168762 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8897398ilk; Tue, 9 Jul 2019 11:33:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYyBgyr9SgFuMq7wih/qSiSU8XtpN0IthM9U/XCe7Rw22KaSFxxVkXa8R1+AHg8pw1xHOn X-Received: by 2002:a65:610a:: with SMTP id z10mr32402334pgu.178.1562697194610; Tue, 09 Jul 2019 11:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697194; cv=none; d=google.com; s=arc-20160816; b=o31KBcgmxkxKJ+GuttabsUZ/ZdXgdZc/yC7Dn8/KfzJbqkZRqHOWEd6fiBmNrLM3xp KxjUkm79ppq1b4vmskdO2sOQzBJQy5J51urHXl+kPYiA2YhR+xYEmIly0wrETax9nVAy a6jhTVPfj8v8IscWB+UNA5W0TTsGQ6x3zu6iHNxsC3Sev3Rkgfzs+ZyOt3EDQWuw1SYi FCU0Q37DdgSJqad/O8ODW26M+yZ4xIVkw3T96hj80RS+CHm1IrbNqLhloPjeQxAvjvvq xRV0X8gpLkSAcebL8lchzKINM9iBwFkQFVSo/qWiepTYuAw2dRiY7rji+uI2pcaYxGpf yjuQ== 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=VSMlYjQN+VOfSG02injKM/DMDTwfBDQ0N/ogG02SSxI=; b=xLQ19a/8Pdblnl3n/iTW0VnzwLkALO0NWXtdqQku2rnTDbfFDHWPPOTl1bOvFIf2+x ymzY2ToFsCcpt/5M69H9EiLRaFU8nB2h6y3STvlpqe0sjqlIUhw87QDhc+sWrEqHEJRh mUAZ0rBb9earl+Hwk+TfB5w3jWzQVhohT9wOFaJphwSfwiUEmOV80hRBD7kVI/9rl6NU 8AMVPuoxsR01tMT94dwkp0rWM/dOAao6Z5J3gkk7QueJRjQqgr7WGtusJy9Ps2gWya4n YFy1CMvRdaO9WRIjpoApOKjsOoEFuGe/qJcvWasa4LcJPSF4itdLn830ix9yb0J+hvSd Okvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f8iQL7E1; 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 x185si24921602pfx.243.2019.07.09.11.33.14; Tue, 09 Jul 2019 11:33:14 -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=f8iQL7E1; 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 S1729294AbfGISdN (ORCPT + 30 others); Tue, 9 Jul 2019 14:33:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:54836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726218AbfGISdK (ORCPT ); Tue, 9 Jul 2019 14:33:10 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 3C54520656; Tue, 9 Jul 2019 18:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697189; bh=KszjUYtgLQLtSW1cBi/FB/Vr+ozCmXKbJls+v8/d2Fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f8iQL7E15IMCw60dkBnTlvmxBoAUZtTsRcEuiS+ZwBJw3vfoOPCqXBzOWoMj3nxEN CkuFqdIoeSN9PJqvxi/3u5L+Zsj5RWauMq2A/P5L6Ayfh4F/jjnQMPH71ylZC/Zkju VU12QzNPW5IqWzjl/TjUVVrabDIAKCaL5FoxfEZs= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Adrian Hunter , Alexander Shishkin , Andi Kleen , Mathieu Poirier , Suzuki Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 20/25] perf hists browser: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:21 -0300 Message-Id: <20190709183126.30257-21-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/ui/browsers/hists.c:641 hist_browser__run() error: we previously assumed 'hbt' could be null (see line 625) tools/perf/ui/browsers/hists.c:3088 perf_evsel__hists_browse() error: we previously assumed 'browser->he_selection' could be null (see line 2902) tools/perf/ui/browsers/hists.c:3272 perf_evsel_menu__run() error: we previously assumed 'hbt' could be null (see line 3260) This patch firstly validating the pointers before access them, so can fix potential NULL pointer dereference. Signed-off-by: Leo Yan Acked-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-2-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/ui/browsers/hists.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) -- 2.21.0 diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 85581cfb9112..a94eb0755e8b 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -639,7 +639,11 @@ int hist_browser__run(struct hist_browser *browser, const char *help, switch (key) { case K_TIMER: { u64 nr_entries; - hbt->timer(hbt->arg); + + WARN_ON_ONCE(!hbt); + + if (hbt) + hbt->timer(hbt->arg); if (hist_browser__has_filter(browser) || symbol_conf.report_hierarchy) @@ -2821,7 +2825,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, { struct hists *hists = evsel__hists(evsel); struct hist_browser *browser = perf_evsel_browser__new(evsel, hbt, env, annotation_opts); - struct branch_info *bi; + struct branch_info *bi = NULL; #define MAX_OPTIONS 16 char *options[MAX_OPTIONS]; struct popup_action actions[MAX_OPTIONS]; @@ -3087,7 +3091,9 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events, goto skip_annotation; if (sort__mode == SORT_MODE__BRANCH) { - bi = browser->he_selection->branch_info; + + if (browser->he_selection) + bi = browser->he_selection->branch_info; if (bi == NULL) goto skip_annotation; @@ -3271,7 +3277,8 @@ static int perf_evsel_menu__run(struct perf_evsel_menu *menu, switch (key) { case K_TIMER: - hbt->timer(hbt->arg); + if (hbt) + hbt->timer(hbt->arg); if (!menu->lost_events_warned && menu->lost_events && From patchwork Tue Jul 9 18:31:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168763 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8897612ilk; Tue, 9 Jul 2019 11:33:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMq16oqaa/uBvPmm7OppWwTak66YGkUhiceGJA/vfrIMzNdckRrjYIAJhUYzf6/ElkrZhg X-Received: by 2002:a17:90a:d343:: with SMTP id i3mr1727777pjx.15.1562697207167; Tue, 09 Jul 2019 11:33:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697207; cv=none; d=google.com; s=arc-20160816; b=fddUY/kbq1w8xX0PPNEhMlfFmpgDgSA2HvG6OU9k5LXNhL7QuDdiub5KSWeRLOUvPZ +EpW8EPWEHe8Jdis2GZ5vmMY25vgWTi1AC1HkiUZijBiw6tbLpC572wRMsNlMd8IB95E zi8avzZsJ/eD3SrrK/51XkgnfKk23SUm5PnaL7zIXogrB4A92C+nFf0JL+8g1VKgUtD4 Az5hGp8G3U/JkxxQ9Ss+Q+8FI5mPQchhP+1HBypFXJKLoBedWsDoYo5kwgqp5zVpb7et zzakmz14+lNkMFimlhNfImjWk/SchB1feLd93EC+Tqrk36x0V7IuT5mcqiE5yOHiLxjL +9Og== 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=RNG9FIOsMrNbeAWAGzeZN8uasBHU+JNuQ2nFq46gZMI=; b=rHRMwu3+7m0fTwEt514sJp7k84SN2kQ9I1jL8dslA11FmAk4+w+dO8jLMurKGIEtew 8TmoIcApSEWfVupwaLsGtcKnu7CYIWsKb1VCLlKsHjHXl4HxybBXeu9szbE8ILZOvwwy 2nJ246fDkQlBLIkHjlVc0CHBM2z1YwuyAzjkc6RknyCv5zuiVducE26vyJf8La/CsFKb 5XrPelMOxVpOccsH8aiOrdtYT1jxS2MI/0I3ga52wQrLxterEsAZVLgc8U8G7hEkxoQm 4OunjoCKT24bsu9sx000nnvu4WbMsKI8qknMft+FVKplxE3/npK5m3e6tdySRSzsnfmR yhmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OhgwGTrS; 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 67si12300818pfv.74.2019.07.09.11.33.26; Tue, 09 Jul 2019 11:33:27 -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=OhgwGTrS; 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 S1729337AbfGISd0 (ORCPT + 30 others); Tue, 9 Jul 2019 14:33:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:55124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729096AbfGISdY (ORCPT ); Tue, 9 Jul 2019 14:33:24 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 338B320665; Tue, 9 Jul 2019 18:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697202; bh=yHkKoGD86pkN+7stgd+uP0ofZTcNoxDdiAluQJh5XWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OhgwGTrSCVsyY6l35y3Jwar5V8OjWGbU3pdvsAamp+EyeBAqawP4TvOEmNTcy94ro Itr+QH/iIyv+Xr00I/LOdAogXZTUU/JFqTXbdT8OV/JzNPm57UHIpjHz4bj6w5ThC0 P1HfLZyCRM++zp4UoAf94V3S2jHMYnEs5qFysq1w= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Adrian Hunter , Alexander Shishkin , Andi Kleen , Jiri Olsa , Mathieu Poirier , Suzuki Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 24/25] perf intel-bts: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:25 -0300 Message-Id: <20190709183126.30257-25-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/intel-bts.c:898 intel_bts_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 894) tools/perf/util/intel-bts.c:899 intel_bts_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 898) tools/perf/util/intel-bts.c 894 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 895 bts->synth_opts = *session->itrace_synth_opts; 896 } else { 897 itrace_synth_opts__set_default(&bts->synth_opts, 898 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 899 if (session->itrace_synth_opts) ^^^^^^^^^^^^^^^^^^^^^^^^^^ 900 bts->synth_opts.thread_stack = 901 session->itrace_synth_opts->thread_stack; 902 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_bts_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan Acked-by: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Jiri Olsa Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-3-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/intel-bts.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.21.0 diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 5a21bcdb8ef7..5560e95afdda 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -891,13 +891,12 @@ int intel_bts_process_auxtrace_info(union perf_event *event, if (dump_trace) return 0; - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { bts->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&bts->synth_opts, session->itrace_synth_opts->default_no_sample); - if (session->itrace_synth_opts) - bts->synth_opts.thread_stack = + bts->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; } From patchwork Tue Jul 9 18:31:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 168764 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8897680ilk; Tue, 9 Jul 2019 11:33:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJOrZ6FxDqmmlP4E1BdYHFdUFgh9DChEQ+IGVRXCwBpbThlzyH33s61dpLlSWiCq1Fy2Ga X-Received: by 2002:a63:e62:: with SMTP id 34mr29816792pgo.331.1562697211375; Tue, 09 Jul 2019 11:33:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562697211; cv=none; d=google.com; s=arc-20160816; b=u86abRgXeamUPkGn1QuQIqLLKorFgTQ5okaqaYVvDfqQeFA7NW7E7xgIp4+hvOshDL GAxLubsbmbSCqCI5T8hq7Jt7uPGrLscApMRhJHNypgGo2vr75kcF1wggGs/Slc8HdWf3 cGoKbAooxPvKgntZtEXBi0ZNJUl2S/wRS1P1K1BNVbaMDsNd3uqo3MpYHknzMm2xDEXf 8GvXB4k0l/qVbuhUvQ37zAEg6YoYVZJLTJs0Isqgld8PDDCKdHPyFOxg3LLaXF8hEetT DpEu9WZiy6S41MajZ1antJnEJDuNO3nvRiKEsIi06IFh5ul0Tefv4Vcbpl5dOFJSWhUl hYIQ== 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=bzhnTvp8j/QqUEvjbbPtxZb1Tui70yPg4LPGUwU65hM=; b=qVIVlfJ00ufjM0KlU5m6V3apI6yKphcBvS7CMxPxbmfbsVq+WAZLIuwftxOwna79pZ 80IvtOe+X6zMXyKDe+DvI4VaLcP/6SudbI6z2GzFeZfinkuwTiMam5CKi+TsO0vLW/2c mKbK1OiJ5TLYz49TmJ3hJ08ZZljGqBgBXM1WH1/MQmuCzrEZatl48iFUPJNEmaZi1hKQ QD0jDCCYkFbEqkUZxfNKUaXnmUwKQqnnhctFRUVrNXb/ILkhDeCI2mg/Lkn41USzxQbk cels/dGromQ5exnvc1wKBawrH9j9itjhomgzuvl7tdsnslAHFWfsA0Q5pj1pHBPhvQDX aj5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wKFilR8Z; 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 i32si3349989pje.44.2019.07.09.11.33.31; Tue, 09 Jul 2019 11:33:31 -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=wKFilR8Z; 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 S1729348AbfGISd3 (ORCPT + 30 others); Tue, 9 Jul 2019 14:33:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55246 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbfGISd1 (ORCPT ); Tue, 9 Jul 2019 14:33:27 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.35.11]) (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 65E3D20656; Tue, 9 Jul 2019 18:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562697207; bh=yAP7lLk8scvs8z72JtKyaa3K2i32Wc49Nr1SyOz2l3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wKFilR8ZSDMQ1SkWeWA3Li198T/E6FamZeMgPqVQ6ToJ38qlAhi99VtfYYPROyasb pjvJQfxgjUiT2IbDYEICDj3cffL3tGgoY13Cm6D2Nypc9DXTkwOlFTwt3t6x5WgO56 9L37svk73hrJY1BnddgDill4IWSC8nS4stvKIm8U= From: Arnaldo Carvalho de Melo To: Ingo Molnar , Thomas Gleixner Cc: Jiri Olsa , Namhyung Kim , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Leo Yan , Adrian Hunter , Alexander Shishkin , Andi Kleen , Jiri Olsa , Mathieu Poirier , Suzuki Poulouse , linux-arm-kernel@lists.infradead.org, Arnaldo Carvalho de Melo Subject: [PATCH 25/25] perf intel-pt: Fix potential NULL pointer dereference found by the smatch tool Date: Tue, 9 Jul 2019 15:31:26 -0300 Message-Id: <20190709183126.30257-26-acme@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190709183126.30257-1-acme@kernel.org> References: <20190709183126.30257-1-acme@kernel.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leo Yan Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/util/intel-pt.c:3200 intel_pt_process_auxtrace_info() error: we previously assumed 'session->itrace_synth_opts' could be null (see line 3196) tools/perf/util/intel-pt.c:3206 intel_pt_process_auxtrace_info() warn: variable dereferenced before check 'session->itrace_synth_opts' (see line 3200) tools/perf/util/intel-pt.c 3196 if (session->itrace_synth_opts && session->itrace_synth_opts->set) { 3197 pt->synth_opts = *session->itrace_synth_opts; 3198 } else { 3199 itrace_synth_opts__set_default(&pt->synth_opts, 3200 session->itrace_synth_opts->default_no_sample); ^^^^^^^^^^^^^^^^^^^^^^^^^^ 3201 if (!session->itrace_synth_opts->default_no_sample && 3202 !session->itrace_synth_opts->inject) { 3203 pt->synth_opts.branches = false; 3204 pt->synth_opts.callchain = true; 3205 } 3206 if (session->itrace_synth_opts) ^^^^^^^^^^^^^^^^^^^^^^^^^^ 3207 pt->synth_opts.thread_stack = 3208 session->itrace_synth_opts->thread_stack; 3209 } 'session->itrace_synth_opts' is impossible to be a NULL pointer in intel_pt_process_auxtrace_info(), thus this patch removes the NULL test for 'session->itrace_synth_opts'. Signed-off-by: Leo Yan Acked-by: Adrian Hunter Cc: Alexander Shishkin Cc: Andi Kleen Cc: Jiri Olsa Cc: Mathieu Poirier Cc: Namhyung Kim Cc: Suzuki Poulouse Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/20190708143937.7722-4-leo.yan@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/intel-pt.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) -- 2.21.0 diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index c76a96f777fb..df061599fef4 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3210,7 +3210,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, goto err_delete_thread; } - if (session->itrace_synth_opts && session->itrace_synth_opts->set) { + if (session->itrace_synth_opts->set) { pt->synth_opts = *session->itrace_synth_opts; } else { itrace_synth_opts__set_default(&pt->synth_opts, @@ -3220,8 +3220,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->synth_opts.branches = false; pt->synth_opts.callchain = true; } - if (session->itrace_synth_opts) - pt->synth_opts.thread_stack = + pt->synth_opts.thread_stack = session->itrace_synth_opts->thread_stack; } @@ -3241,11 +3240,9 @@ int intel_pt_process_auxtrace_info(union perf_event *event, pt->cbr2khz = tsc_freq / pt->max_non_turbo_ratio / 1000; } - if (session->itrace_synth_opts) { - err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); - if (err) - goto err_delete_thread; - } + err = intel_pt_setup_time_ranges(pt, session->itrace_synth_opts); + if (err) + goto err_delete_thread; if (pt->synth_opts.calls) pt->branches_filter |= PERF_IP_FLAG_CALL | PERF_IP_FLAG_ASYNC |