From patchwork Tue Jul 2 10:34:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168302 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072634ilk; Tue, 2 Jul 2019 03:35:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1LUUJ+A8ca+6QvoN5jeBE2al3GdDseMujtgXgNpnmIGacaDsnnFUFwF6YToaC2tllldPY X-Received: by 2002:a63:dc02:: with SMTP id s2mr30310887pgg.286.1562063742895; Tue, 02 Jul 2019 03:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063742; cv=none; d=google.com; s=arc-20160816; b=y/YvsNgqWmQ8axRwvvGYUK9r8DbfxSzYun1SlxlwXX7t+UVuf91JkL0MstKaJOwMHC Kgjid/qsEjbaiHw1WJnNaVkJFJrgEhbl9U5TMC9EXi2znWtxUvgPrHYkBMdsJR1gHtde 9vdh6MTGcZCFHICAJ9dztXxTPPzUMK1Bmp7Ozhk0J6s5WiXtnb+nUDV3bjz9gHAowbVg JnShZo2Vh9FT9ItaCwwcUsmu0DsBVD+niTRRiBBRQnMiIm99kZ2VaBwo1rMrgbSUh4Vt 5nse4sY5bavKArWyHmN2oO7PMDftSsMcF/DzmX6d/Pc0ITWOPc4637UxOiGDgJ5ujoIK +kOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=F1cJQod20rlh4JhiBTdx2PH6KqMq30JuyoSJBz8Qo1U=; b=I3cHDnbecGTseiO+mWIosLKHsn8Torl4xc7FY/E40TRpaS4RB7qizLUK6rKgzoU3hQ br6Q3gs/xY/rD/JFnuUQlfXLEEVwdnBtD3ekYVujcEH+9yd6h6PrF9dzvaorAB0aK+Pz rhQbw+eBGeC0LUxMmdn2S1P30052l5pZzC0ld+VWg57cStJIJTd0Xl2wM8tnS3bF7MlK xY/IXaKI9XIRstGcncFCzmUEt2Zdr+UZ0bXbZXEMzX2qcWjLpM1ZuSOJOzaCDlBbBYCR d+Ep3pwc2CpQDSG6z0TjXT53HiWGLUrz+cL+gZybYBF+AyteKk3GKKVJ9/3+C+XN6q9B /VAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s70513xy; 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=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j23si12421035pll.214.2019.07.02.03.35.42; Tue, 02 Jul 2019 03:35:42 -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=@linaro.org header.s=google header.b=s70513xy; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbfGBKez (ORCPT + 30 others); Tue, 2 Jul 2019 06:34:55 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:46229 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKey (ORCPT ); Tue, 2 Jul 2019 06:34:54 -0400 Received: by mail-oi1-f193.google.com with SMTP id 65so12599750oid.13 for ; Tue, 02 Jul 2019 03:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F1cJQod20rlh4JhiBTdx2PH6KqMq30JuyoSJBz8Qo1U=; b=s70513xyDTidEr5Ppvu38moEO3tF4ILImM8v234mxyFjRqgVL7SFC8HyivT+ff4BNd wxGqLRz7aP+i61gRKfuH7f8z7WdX2tqXxbAgbQVVOGp+FcOfBbceh+Z0vBLp2jNZQqrs WAEP/LJXy6qfpj1dlbOlmWHvTcZp8tVA372DlFQZoDTSj6PhAMPwBV/3xMYn2Pc3hCp5 tZCXr+LfJZtmlV2gC4Dv7HoGfDrJ43YxMfEIHYkyuuPPMyn+01SC86WD3fU0uQvp7Wlq cpolfqTfxRJQh6j8ZyxIdCmR+7ly3pT5tC68g9KVPQ2P2nGKQINU3FBmCxa3UMKBeKqJ 8WnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F1cJQod20rlh4JhiBTdx2PH6KqMq30JuyoSJBz8Qo1U=; b=sULfVjyirXn3Hqtkxz5cVfx/rkzp8cadcGefZXhwFNUV4oBi5BklJXdTBv4vt74zwG 4n7hlykqAuf/iMT/O6oM54dmiq7REXGqr+TwvMivDDuxM6vubOmDJl3AbmwOv+CXt9CK MeMNXTskuUX0ii11rYPnURZqMfh/Nc/y08zN7s+d8D4P4phGNZzgbhIgzgz2QWvWVkj6 jgeh+xmrzETJETOYV9SxYYcfuLzaIYIh+ARxQVjGISxdwVmWuJNnpbV6zbjHML8MJqtL CUumYl3ymGCoSIVMaOw/WzrM46LY6Pvru9AP73dzeObnA1TAsqqMzwex7pffT1RFE/k1 3MFw== X-Gm-Message-State: APjAAAW8ac3oEokv4YegUVEPDVELlK1eFmU+22grkMHtg3ueLh8JIKog uvPGNV9KH7dFONdDouvdUfn6lQ== X-Received: by 2002:aca:3bc6:: with SMTP id i189mr2397047oia.153.1562063693989; Tue, 02 Jul 2019 03:34:53 -0700 (PDT) Received: from localhost.localdomain (li964-79.members.linode.com. [45.33.10.79]) by smtp.gmail.com with ESMTPSA id 61sm5139805otx.8.2019.07.02.03.34.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:34:53 -0700 (PDT) From: Leo Yan To: Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Mathieu Poirier , Suzuki K Poulose , Andi Kleen , "David S. Miller" , Davidlohr Bueso , Rasmus Villemoes , Jin Yao , Song Liu , Adrian Hunter , Alexios Zavras , Thomas Gleixner , Changbin Du , Eric Saint-Etienne , Konstantin Khlebnikov , Thomas Richter , Alexey Budankov , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Leo Yan Subject: [PATCH v1 01/11] perf report: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:10 +0800 Message-Id: <20190702103420.27540-2-leo.yan@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190702103420.27540-1-leo.yan@linaro.org> References: <20190702103420.27540-1-leo.yan@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Based on the following report from Smatch, fix the potential NULL pointer dereference check. tools/perf/builtin-report.c:304 process_read_event() error: we previously assumed 'evsel' could be null (see line 301) tools/perf/builtin-report.c 301 const char *name = evsel ? perf_evsel__name(evsel) : "unknown"; 302 int err = perf_read_values_add_value(&rep->show_threads_values, 303 event->read.pid, event->read.tid, 304 evsel->idx, ^^^^^^^ 305 name, 306 event->read.value); This patch checks if 'evsel' is NULL pointer then pass UINT64_MAX as idx parameter. Signed-off-by: Leo Yan --- tools/perf/builtin-report.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 91c40808380d..a894ce7cd04e 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -299,10 +299,10 @@ static int process_read_event(struct perf_tool *tool, if (rep->show_threads) { const char *name = evsel ? perf_evsel__name(evsel) : "unknown"; + int idx = evsel ? evsel->idx : INT_MAX; int err = perf_read_values_add_value(&rep->show_threads_values, event->read.pid, event->read.tid, - evsel->idx, - name, + idx, name, event->read.value); if (err)