From patchwork Tue Jul 2 10:34:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168311 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4073090ilk; Tue, 2 Jul 2019 03:36:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYjdX7vK224DuaH3ihfT8NeCl3l+4TzXBEuFEwjwX9fx6KxM0+Qm5OPvXV6Yqc4Z36rWhx X-Received: by 2002:a17:902:f082:: with SMTP id go2mr36147014plb.25.1562063767521; Tue, 02 Jul 2019 03:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063767; cv=none; d=google.com; s=arc-20160816; b=h1lzAn98WQLeA7IC3FgbWBBA8hAHHW63X/fuWQSoF1RxpAWE+JlohuIaH/iiE21cvi OIyFXA8C9ZjtW6ej8/m8G0mBd+zivFGgwFHXgz6GyZ4Tq+ukJFI0PVXfRH7jMF+8pcFM P+3N1pTg31mFpVHQ0kl7HzGhCEHGqfqQ39RAM8BKnuvzW4rtLdQvtd7+vmXfrh6hKnXZ YbRMqj+f2EogBgR9Z6yPJgmG5yvp/+lFqh6wM8uBRiq8iIDqc3flQmBSQbPnBGvOD5i4 i35tTkjr9OnPRN9kDp+6yF9DURSUN8lSuDBDKHldEcH/cdexfdPSLgsJaKVCCkR27HQS 6hww== 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=3cNHVq2PaBuyPCbFNTx86WJww564kzf0LCV7McgViLQ=; b=I9sxw+ZWUQDns2tna7MGoYSasQnpZPbXamWSomtgjQMsJbuBD99MSbA0pef6Sqm8Ko GC+gnJ37felU58e6MoAqRg6CzsXX0yEQEoD9NZQjSA+UY/0K030XI2/Fm4nmJXk7cgYW rmHRVxUR4i5quyaCv9bVEuUwxqz9PeYdthweBf/PgWOjFTC7uIY8KBecR0tPFmculoJ1 5/qOEV4d08iwURocETFrCLvtB+3sPy+YY1dBXgrrkt//gu3PUcvh9RUBzZU9fiVvIr2b 0P+NuUgKqd454Lg8mrktkkbswM7GRQ2tV8ijQygr8sBy5YpMiXtKZHer+tliB/DEVLM6 GBTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GeU2YXEC; 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.36.07; Tue, 02 Jul 2019 03:36:07 -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=GeU2YXEC; 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 S1727355AbfGBKgG (ORCPT + 30 others); Tue, 2 Jul 2019 06:36:06 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:40527 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKgF (ORCPT ); Tue, 2 Jul 2019 06:36:05 -0400 Received: by mail-oi1-f193.google.com with SMTP id w196so12611747oie.7 for ; Tue, 02 Jul 2019 03:36:05 -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=3cNHVq2PaBuyPCbFNTx86WJww564kzf0LCV7McgViLQ=; b=GeU2YXECtSWfuOvAG0IXrfrSQ9GC6wKTPBTdhMDvUYYBgeNMHH44ObcVpAgJxIHjRu XicPO2ucq+5oUDudXs2mJPojY613jYIPnec60fr4ppTayNR73/TdwAy6ls50oh3kWzLz 7HggTaX71y4bEubqd8qL21lfZrHDsHmxgB/kbv2nqyzqpxo+YLTG5wwfi7mIlckvsUgs HfLJIS9EQrhuPFz8avWFKQpZmAWMl0i5FDmd225UflwLKM80U0o4VKBdwejuQMcstKgQ WU9+yflbRfrpdlPHRtZKIL7/IVZwM8i2kU9fiS76WHQBh44fB3J4FGPT+d9dVKxxJUkV P4+Q== 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=3cNHVq2PaBuyPCbFNTx86WJww564kzf0LCV7McgViLQ=; b=fDWuVrY4aU/xQqqK8697sjSAHvBlz3OATrFo8A5JaTgIzmAWsvVzIcOUnfrSBzoBvs qp3uObgEMnpQQhnRUD/mLwd6405yviLk5PppfZ+/dCNtoXRlUidHeExAdPa+kJ2IkmW/ dUNpJ05vDhbFdXCtiRFcmalKOMUzcnxXbvCbzRZ/9Ii8b+KrDrhVIXTnynmUpTNOwL22 XPK+56YuiH5ByC9qO97/SHTrPSzls/0gO7CiOtutBsuP9HdTr2cesDO/O4mmpVzlBFMG re3AQl9APfXZPZtvT810qEKyaGPuQTMazHMIo1Nkwk+OMVz4V9JWuZPNupZj1VG8jnBt JrXA== X-Gm-Message-State: APjAAAXuCNp0wxmqrb1rS9eX1npxiH9TJWPPpw9E8f0p3zgaWFOJKyn/ a3Ns9VQCOhzF0xY7OpWTDMShQQ== X-Received: by 2002:aca:3dd7:: with SMTP id k206mr2332669oia.47.1562063765056; Tue, 02 Jul 2019 03:36:05 -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.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:36:04 -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 10/11] perf intel-pt: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:19 +0800 Message-Id: <20190702103420.27540-11-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/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 } To dismiss the potential NULL pointer dereference, this patch validates the pointer 'session->itrace_synth_opts' before access its elements. Signed-off-by: Leo Yan --- tools/perf/util/intel-pt.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c index 550db6e77968..88b567bdf1f9 100644 --- a/tools/perf/util/intel-pt.c +++ b/tools/perf/util/intel-pt.c @@ -3195,7 +3195,7 @@ int intel_pt_process_auxtrace_info(union perf_event *event, if (session->itrace_synth_opts && session->itrace_synth_opts->set) { pt->synth_opts = *session->itrace_synth_opts; - } else { + } else if (session->itrace_synth_opts) { itrace_synth_opts__set_default(&pt->synth_opts, session->itrace_synth_opts->default_no_sample); if (!session->itrace_synth_opts->default_no_sample && @@ -3203,8 +3203,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; }