From patchwork Tue Jul 2 10:34:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168309 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072844ilk; Tue, 2 Jul 2019 03:35:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqydWTH5zGkYE1zGIYPZ9yLiQlEhAJmWTNVK9Z2/8mm+gzbDzjj8e9UDdt25vpt+Y93Y47FZ X-Received: by 2002:a63:ec13:: with SMTP id j19mr29076161pgh.174.1562063752952; Tue, 02 Jul 2019 03:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063752; cv=none; d=google.com; s=arc-20160816; b=NKzZIkIGDKesVPNDzQ8scRRsbPHGCN9Eb5OnnxgdUpP9RtIPXXSZN8FqZtSmCQ4vmM W2h/VbsssnXKGnXU4mEjp4+HGf8GayrNjRLKX5e2IxEFV7zq0GsbiP4W3s9G8Vo8sKrG TuTjg5JiBJFUCO8EyfdKUXXdN8hVNsOt6E07xNyXJHsRSqCy/pAOUE5fTnhFeMrR0Ucn 61a+oiNg+HJRs/ZXPl9JX962GnOnRq4vtpgEMVSaJLCRWxVKaHfcqnUORD/DdlOKwTik I4w1UqybHvH+kMUzWHUOFGmSjSc5IUBn9BAe1P/+CcSNp0F7RseUVMEblwB2umMP2XT+ xTHA== 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=zTwTfXNgxTmrGRUjBKcfiXIJvV7RcQHKF6DIe75zo+I=; b=Z594NcO7vQ+OVHue08kUsZ6dBgKS8AcXACSCjltvYOyc+m82gE0wDN5L85L8QWpzDn fzrEBx6kKGpFqCQRQjYnJpLIf6lRoGUnwDkMLGgwABVFbkjmrkeYc1PZLJxvQW0U5zCk XOYRgxTw+mdejbVWJVbchrlmN3A0UnrOvWMYsArY3kqvvxG0GABJ1WkdbtL6oXq+AZuo ZG1/NP/lXIBuCtC1hkzeTYKEft1nwQOILBUoZ3UmHgC7Di7+C+kfNeovizJBd71axmjM OanCm5RgHUr3QLMrGrQc2qjKlPu/g/VbKUdChLeig8Pw3u8eCFW7pfzAnlVVELBc8s6H BT1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qmeaKVWd; 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 d13si12177814pgl.545.2019.07.02.03.35.52; Tue, 02 Jul 2019 03:35:52 -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=qmeaKVWd; 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 S1727329AbfGBKfv (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:51 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:39449 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfu (ORCPT ); Tue, 2 Jul 2019 06:35:50 -0400 Received: by mail-oi1-f194.google.com with SMTP id m202so12622923oig.6 for ; Tue, 02 Jul 2019 03:35:50 -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=zTwTfXNgxTmrGRUjBKcfiXIJvV7RcQHKF6DIe75zo+I=; b=qmeaKVWdYJMzo5niBo8eJXFwzM8pytrY9m8n2B5/m28fbL9VJT6KWdOOE86JBx8ntL +vff4tW/HcSWI7kaAKHhD3u+0ivKHodubYbUbLUSilYabfc3gbGl+4nWUvaSCp+zj0ay QqIfGyD6iwhac5mxyv5FSMGGKbIK/XJMfsOKX7YTs0KXvUGx3Xqz2PBqs9avL+DCOH1T u2Rw3lY5ZSgrrfRnnMQ3rc/w8GuoaGJeh8U3W4jhpwrnZBbWCuFQ9EE2Jjd6sudTm7VX aH3e9GH6StNynB4j47dNPlpAEuRgXbbHp7/vr3dv9cCdgf8TtuiNQ3k71NfaNui1NR6/ 8FrA== 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=zTwTfXNgxTmrGRUjBKcfiXIJvV7RcQHKF6DIe75zo+I=; b=iRKow5t+3ToaxGjePoa0Davl2rlJmGPDnm4q7veSmBVbm9OxqpeL2sE/Fi7be7o7h+ QJeX2hVFV4TIb2S6lxZBEu24fuZIDsq+JJkClrvRfoVUHJ5MVf2qth7O5BO0gk5c7R+6 a3170zOLeexo5aXodVpgJHT0h4FxU7QfQlOkbhQbC6yhskSDr8fw9uvylKCQ9RqulcKs x4i7tBVmJPgXhk2r+5LJpfMLS+hsX9m8agIL3zaKoy6HY3J18c0ze7l03CmpX1gx86oY MefbB/jpBKbU7NwNISQCEbcIS7FF9/+j0W3jDBt2XXR+2l1ooEPcfiDKBKKeRaerNJEB glSA== X-Gm-Message-State: APjAAAWrpyTKOpDK7hGpfTM8pLpS+pGvBMXWjhG+ZtOATGvAKmIbShWm A7UVxdHru+9Y2TYihU3ben/fjA== X-Received: by 2002:aca:5241:: with SMTP id g62mr2474775oib.41.1562063749790; Tue, 02 Jul 2019 03:35:49 -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.35.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:49 -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 08/11] perf session: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:17 +0800 Message-Id: <20190702103420.27540-9-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/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 --- tools/perf/util/session.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 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)