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) From patchwork Tue Jul 2 10:34:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168303 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072641ilk; Tue, 2 Jul 2019 03:35:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFlXWinWug9/UMyCrH7Iru/58nrPHmh89fiwWufeEx0KC7TjmJm2V2lHha+pOOKJZYTUAD X-Received: by 2002:a63:4c46:: with SMTP id m6mr30878117pgl.59.1562063743326; Tue, 02 Jul 2019 03:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063743; cv=none; d=google.com; s=arc-20160816; b=gleyg4leSV0OUZqOvOcqffrR3Wd+aR4LLIBFsIGvaVZpLqB99WGtiAwt308fiOtdwN BJwKinVvakz1Wf8Wp05wXo9in0W3LdaCdErSlWWzwfXkQj6Yj/Foxm0NSqgjUe8RUAz8 ulxdx0sxiY5GLJCsEJlUTz/u0t2xhfFwxhb+ZoE1gZ7vaOYojn7s7vS4zpfxJI98F1zj FppzkwdfYJfch4uM4x7qgXyxWeLfj7Ufq2Q0lpbSaHW67mL7gwFTAhUFgpDNbfa88NfX yxAjkuPkX/HJK2tGT66I8ifTWqKMj6fPoEaYX465jte+iHTJD6oL8aewclmlEwgyWYGG h8XQ== 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=KMNCKIxUd7C3QCEkBdcu4g6ofRmUIVRG/BHPe4FFBiI=; b=mpNyU2sKECmAwXl2DpqjGS1ootnz1YpozhZOEDZ4yyHHrIlAbA3EwDJR4nvuxzSFYG yWlx8WJ5mqHjOhI1ijP8R75DP9BeeCYuWcFc6Et9TiNXLWHrkx5RBUupFoWTPMeAd4it YZq2/8BJimdBQLmwGUaMGQV6e0eEP17jxRLRx1hbbtH327v1+bS9EkBj33VEX/I7HYaa LAmR2qqxWVLdNkv57yeFkB+TM+DJUBG0MbqV8fk6BOakeLTEqN+RTU0bgsDvq3wUISlr SvMe3OBy7zW5biIKs2DIwBKvWqZmuGDTKLjSw4i1YQ3mFdGQkWOEIxkaKsRfR1yjUvZ5 qR2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b3Ynb3mm; 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.43; Tue, 02 Jul 2019 03:35:43 -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=b3Ynb3mm; 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 S1727069AbfGBKfD (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:03 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:46048 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfC (ORCPT ); Tue, 2 Jul 2019 06:35:02 -0400 Received: by mail-ot1-f67.google.com with SMTP id x21so16635304otq.12 for ; Tue, 02 Jul 2019 03:35:02 -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=KMNCKIxUd7C3QCEkBdcu4g6ofRmUIVRG/BHPe4FFBiI=; b=b3Ynb3mmyQPqXrGhUFTeBcfcKHtyocPl8Z41p2F8I32GBNu0jF2BwO2+v3JgI33/vX jdTP5yPdtLr0AmtRijQulnFrapU3F7Wo1t9ouWCA8DB3JJmF+5U2+qFa/t67GXudzCMz ly/Us9RlBLH/YWRpgziYH+onbCeHqjhF+Jsx8f+BdbQnJpk0sZsc1lMdFG2vqOxBUmi3 zREazE8Zg6hRzYOeK/wcN6BSghqPHghcuZXM/aLU82P664LzADeiNUaoRo96TUXapNFl VMQxHdl/BOL+DLppX1ABrQiPd4KpJ6Qar4Ka5KVHxxtBxrd0PruJ1D9m2pAFFESgzNds V19Q== 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=KMNCKIxUd7C3QCEkBdcu4g6ofRmUIVRG/BHPe4FFBiI=; b=T3LRONcddq5FYPLtvwQLApURaiguPuBowGSFl2dgVmnxcCwvT44VxM+oHZb9pUYVKt wd+mvxW8A9e91ecPpFyBygXZxbVx8w9dfTAmGknctLxsQ9H5wT8yJNEyzZiZvSUJmJz4 prTFlOl/kSNFGczsEsNWgVfv9z2n/91It1OJrWVLmfIuvNH36gF78/wB5012sgAHdqOa MyD6S/84q9kb4dkM7lv2TSNWqAbYEnCSZt2/h1pot1Ur6rwSCUqlZB2xIt/FNhToVAv/ TZNikutlWu/sNAnLYpMxOrUGZ0JXmm/4Rt3qj8vsV153WyeRBIQS8l1Iql2GYE8EDTGt xElA== X-Gm-Message-State: APjAAAVBzDy6XLDPKFEU5Q544cFy2KKhu6n/J/tRzHwVV0Q++MzSEt6A LbH18aI/VtH0AFrYgUzZbM+aUA== X-Received: by 2002:a9d:6ac9:: with SMTP id m9mr19994522otq.242.1562063701875; Tue, 02 Jul 2019 03:35:01 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:01 -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 02/11] perf stat: Smatch: Fix use-after-freed pointer Date: Tue, 2 Jul 2019 18:34:11 +0800 Message-Id: <20190702103420.27540-3-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 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 --- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 8a35fc5a7281..de0f6d0e96a2 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 2 10:34:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168304 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072651ilk; Tue, 2 Jul 2019 03:35:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqydditTB/ikVgBTDX6ifxZfv4v0y4mn7o2EihEIrdXjqZk7oc0fDb94bAm47z5HPT/pLFbn X-Received: by 2002:a17:902:9897:: with SMTP id s23mr34301699plp.47.1562063743967; Tue, 02 Jul 2019 03:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063743; cv=none; d=google.com; s=arc-20160816; b=RlZNdy0YAh27x+IX2DN+/CRwJJmzZrfM7/BO3djMChiK3uwCFWH38PKS5PebT5Yn3o LsWBP58Heh55yW1+MyrM6O27ScaZhDishjsP7RwbAEmDjGDo3uIirhSUkMno3UvIzEBZ Q6UN7gS3WLBRWrorq8RJbcIHNEDYRNdSp8wB4DVsFlUZwS5vp+egMBbmTV1sQiIV/upk /895TdUWMJWN4rnQAbeA85c4gZ1g2u1GyFPrXXAx5dGx/8i06Px5OpidE/YGDb0ywhGU 3w2eOMKJ50x6xkL9wlseJS4gB2URF6PjTg4hgdJIXmRFkJTEAj16vBcQEIplGdqKuOvy Rxpg== 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=utMbP5r99vkrLRwFC9XJUF/q6Xmj0kpzfxPbj/zmwoc=; b=sZnCzOLsOlY1yZPHDZIYlGeccQVRIRhsDN6mzrxEG/AvlYl94uHWUfPclhGlroQPFf 7oFYxzk0ElTL+7TOMMmJ7v+L7cRH4EBcQoTowkZzWI6JqbLziCc77XM/UEwL+4126FiG 2nMjWxVcvAx4dL+h5bAyQ/UWEr4GeArRDHTZbvdNhcPWV8EE3kF72bpnHhqkmJTv+Tn3 jfikkYL2HI5bfYgj3d4fX7MN09N8okQMAu3fhAsxbjHDvZ9xwgLoi1TvxnUD9GIjrgZu rSSBOthBhv+65wh9tEboUO4xDTBgSyAfiq4NCzGf94S6xvwx25xiYU6TFt46FIkQ1JwC sLdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g07M7EfA; 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.43; Tue, 02 Jul 2019 03:35:43 -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=g07M7EfA; 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 S1727127AbfGBKfL (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:11 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:35778 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfK (ORCPT ); Tue, 2 Jul 2019 06:35:10 -0400 Received: by mail-oi1-f194.google.com with SMTP id a127so12617977oii.2 for ; Tue, 02 Jul 2019 03:35:10 -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=utMbP5r99vkrLRwFC9XJUF/q6Xmj0kpzfxPbj/zmwoc=; b=g07M7EfAimyBJUBTxRPreg/5uLOzsLgF+3r66hneNUCiDvvGk5WbVUCT/5bnUBY+wb FYofzKOxyhyHecehXrTFZp66JEf6ROxWUQ5wu2s+QCMytOkRacbVx59muNBI6eDLNZpa lnexdzYvCRMZQQHS0nzPHi9N/5iQCdz5m5FyE9VEXnXVl11RMplHf2yRET+rU7XTH5As Wy97HMCtEc0ir9AQEiywnG/ejR25uR4vQuPE+R2b2XrppBnvm3nq3qKb6Np/8Av7daH/ NJZ9kpbNTrdJVQsVpvesG5D+brZpx2D9s7NMI4g0A3BDoy+T5Rk0y41vDwNsooeaUCFW ZwWA== 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=utMbP5r99vkrLRwFC9XJUF/q6Xmj0kpzfxPbj/zmwoc=; b=IwNfer62tqDFk1Hvlr/OrFxXEKNnNniFp1KEijs7OEN0727JcPkgZIAZDfiDMpDlfT VyEZJbaJbBAqlcrFE0moxnhTtTna6am9QhUAnTRftzo8dj2U+70IcVTynW0/3FR5XROj 6juP21uoeXpFBBrtPYhbo45PQkYljO0yqUPCsUHwiJ1m6Va433EmStU1vwP+MPyupOyp zz5TA3Ybv24kAuVXw4DbL04jmbEAwBf2h1pA88PIzP2MaEdypf1Sm/oMiy+5iLdsN7QA Y3y1OpQDpVXf4CbJAi+/9PDW6pRUV56W+RZCVpA/eXi7M0ADkS7ggcY2n5F4p68fXGVx XdEA== X-Gm-Message-State: APjAAAVSzzZYf0rjXghSKzLNik1AtCkRtrR76atbPv3wOU3CP36wlb1o /i1RbBGBMkMqPFF869uTcK01JQ== X-Received: by 2002:aca:338b:: with SMTP id z133mr2465469oiz.97.1562063709968; Tue, 02 Jul 2019 03:35:09 -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.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:09 -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 03/11] perf top: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:12 +0800 Message-Id: <20190702103420.27540-4-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-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 --- tools/perf/builtin-top.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 12b6b15a9675..13234c322981 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -100,7 +100,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; @@ -109,6 +109,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; @@ -225,7 +227,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; @@ -233,6 +235,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 2 10:34:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168308 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072656ilk; Tue, 2 Jul 2019 03:35:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2FJ9f0jzftT9qDmrsPFXr3dgouJ/8pn4zmQUpXZf0dSWMqEfoUvc5Nr1UW4YwcK6wiK8R X-Received: by 2002:a17:90a:2486:: with SMTP id i6mr4736545pje.125.1562063744336; Tue, 02 Jul 2019 03:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063744; cv=none; d=google.com; s=arc-20160816; b=WbXTPf2nNH8ApJVyBDVEmGgG5oUCxHVuJYZrzZlwt2Hkr3CQ2c36hbacOoub1tu1ws pYShXCDFExQ6MgE266Vw+coIAijzj00aK25WbFTu+qkmsEchO4T4nSVAiJhq391In3CN 71+sNaR11zMPVxcWRezLHHpcy5W8PvK9hsQP0GEhF6V0bRFoaCj2YLcT2jzE6JEb8PLM V0AZ+Su7RHuIdvoZWrcIK0Q19Y29AA8g2eGc5gVWV+KO3C20NADCRjJpI0jZ9q9p1Xjh FAho4xLA1a41wY/aiD5nLxaKUVT9bjf2wNuAGBMjFEZnYLCpqsSeUotKnO133KiOfGGw K7TQ== 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=Ntf4e24cY15lCTdagT3iS0+VMjBOYWf7Iw92R3PEKUw=; b=vglpgDgmnXGpXUCVZWkQ+T53jqY02b2VR88XxW7RCBL0Y2NqriPwBpkN4hoVqiZ7B3 qjQFN9EGMOd9maQLGeNM6qx68O3JdluUbR91iIHSkwbdSBT8mqEckPeAk64Rg419KTaF SaIbiLkkDM65NqGpWYou0cQHk3Wlj+SFeZ/+hlvYJZP7TD6Z6zHBrPwHdOC9+gS0stgP ssF9L94NqofIQAWCkdcd9QYhsBkgnqe+njckVflExoSRMna5ALnOMP2ZzK+Z5/Yvysqg tX6ULq7wWnO8AAHqGWcYF6ovHW+IoJ4ej59lBRhojIKVa0Or5r/QCq/UL5Mbhd+X+mkh f7rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BFh3rrWH; 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.44; Tue, 02 Jul 2019 03:35:44 -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=BFh3rrWH; 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 S1727218AbfGBKfT (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:19 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:33543 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfS (ORCPT ); Tue, 2 Jul 2019 06:35:18 -0400 Received: by mail-ot1-f66.google.com with SMTP id q20so16655149otl.0 for ; Tue, 02 Jul 2019 03:35:18 -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=Ntf4e24cY15lCTdagT3iS0+VMjBOYWf7Iw92R3PEKUw=; b=BFh3rrWH1Q7vw8K9KiTKC5WaEVtLH0hxOlQ8lYb+DxjHbhrG8G/LElcvUvV9Z5bMjY PvFP3WCg4pEAT++5wHCFpR6vuJg14wqFr8xkqfLzZtDJAbaIKzIL7uG+cj1GqzhMO2oz lWopsH2r9uZgOt0L6Hl1QCAUtH7Cy7js2lqRCrJnKKpRi0tuHwlSYpEodH9GQE/iUnc2 FTPTtbK8H85AKdlBWYas0YUdufWuQAxbJ10khbih9MAd2Fmr+Mu5q6+8HCD70UpIv4LS kxPqAejefCAGovMeEGJzkcsjEhjSPfW3Vd90Z4GpmBWL3WYYkgjneF7Yov6E3seeRjaq gy1A== 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=Ntf4e24cY15lCTdagT3iS0+VMjBOYWf7Iw92R3PEKUw=; b=OKHJaSxIPBv3/GJBkw5vPJuydtvu6d/t7FjwStj8OU0XvM+WqCHQEhlddHz9LFAxs8 FamvqslAQJqmCHmKpwSGdN13o5NCfWrHzAQDBFyJkF9nVQuDPBRZv6hYgFgunDX0KnU0 sbRAoD6U3WJ4jPWU5w0ngNwm0wgEwITxGDuSCblvQZjyQBkwV8dI7yjyJbzPc/gf4VJg 8zZMOEV+Uya6Jhnj7WylfRNhHqf4PsG2SHFxwYWTRTX5fhyBsph6fnEXh9eQ0OfsTovJ 5aF1ClEbPpuJKXyPZdrldtokJYVgwV64MnlH+MEBQD93k5T+mE+0HRBozUXKJ3fu5DS4 kuAw== X-Gm-Message-State: APjAAAV9m8BxyBGbznD2w5YKp+DULzrcihmx6empNVpBdfYCXQ6L7UwB 4F1bPOGi5UB41dfW6Qdr3zGRXA== X-Received: by 2002:a9d:6853:: with SMTP id c19mr1570455oto.213.1562063718005; Tue, 02 Jul 2019 03:35:18 -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.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:17 -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 04/11] perf annotate: Smatch: Fix dereferencing freed memory Date: Tue, 2 Jul 2019 18:34:13 +0800 Message-Id: <20190702103420.27540-5-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 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. Signed-off-by: Leo Yan --- tools/perf/util/annotate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index c8ce13419d9b..b8dfcfe08bb1 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1113,16 +1113,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 = ltrim(*rawp); return 0; -out_free_name: - free((void *)namep); - *namep = NULL; +out: return -1; } From patchwork Tue Jul 2 10:34:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168305 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072669ilk; Tue, 2 Jul 2019 03:35:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwP/b9vSif7FCnPRxlhawTOtCp5zSH/ktFvC/FVIf7C1auqGGdp86mKEvrKZm9MCxjKStdp X-Received: by 2002:a17:90a:f498:: with SMTP id bx24mr4856613pjb.91.1562063744913; Tue, 02 Jul 2019 03:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063744; cv=none; d=google.com; s=arc-20160816; b=W0soyBWENXHad3MaO7z8KKRynmdJK0FRD+ZiP5+0dKnGXWiqxAXRPSWUxHCcKOT5gF sUOxs3HS2qSZC+nAo4FHxyxXxKsXrHjP470yEtu3uid0eLsGMd3+BPJYXACEOMC0miyU 4b9wGdO9MLDzI9WI/WgV4J09mpHzd9Qlx4NY5EAVXLIzHvzj0h6S8/x5O2GUzZ0n/wPa KRhDA34iPcsf/5xuAvs5eYyjAMcgA5rW3XnEthk1yIWSPVtJChofFbKLsDh5MHPQ94aG R5gc7mrZFvVxNqFxeLDI6waYeqZXLvfTVr/G9uhVmXFZCQLulqFZXJgQNPJVAmUmjbyq wttA== 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=j8r6zV3IEktEeBidDu6w6MpwFi6YkkHS02O0zUC0bQU=; b=YSndylDxzYonF2kLsuYH4mlKiK+ftpV0QJO1Ajv5nE4y2ve9wa45q+5zPDTo6474hQ qkoGFvu/uEMsMjX8i+poSwscgyOBJIPIUh550rpL++WKNaBi8Rnt1KW5c1ocWqKVJqGn 7CmlBRU5LlJEI0eLArOhK+FSnWi1wjsHqFAEMjbzaJOjXzN2Q4mqpyE93R3qU/tuKOjQ PN+0W7lS+Ry/nSzGrzLUCMUSw3+Tv0+/2uUhAPrT1El0SNglP1bprkUILGp8fVXphPQy Ve82/LffU0HmALAYJ9ZpL5Iro+oDd5t2M7QHfGpb//7oS6J6NQC9ojR/ooyAJpTKFuC4 eaig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qjjisz9+; 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.44; Tue, 02 Jul 2019 03:35:44 -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=Qjjisz9+; 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 S1727257AbfGBKf1 (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:27 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:39409 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKf0 (ORCPT ); Tue, 2 Jul 2019 06:35:26 -0400 Received: by mail-oi1-f196.google.com with SMTP id m202so12622160oig.6 for ; Tue, 02 Jul 2019 03:35:26 -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=j8r6zV3IEktEeBidDu6w6MpwFi6YkkHS02O0zUC0bQU=; b=Qjjisz9+e7yYwO6xLzJxQ9HbSJNib4eLc/3vLq48/xqqic/aAX4AvVAU/q5Zop1wmJ XkmTke4IVTLDngJtze/ZkDjaA1QU2R2D/kHisk1UxjpNfhZtzV+/+629pPbm+Ug4uQB3 4FUiB7Cc9UYcJjXd+1RdHn98NgTgP+CyF3zfcn8HHtP4zbskHeNvhiTO+SBYh8XED2gK tgRH9S+HRPx4neVupbgOI+Jf8yoEA/nT9Hu9YsNGYeST0SZxaf7/1ytrlD2AQQgeCoI8 QHpmQwLSW44gvSGD2fR7zcUfA5vt3FIfsqKNmFUkJO+2QCNdtXC1KzICntwRsWO7lm+s l/Xg== 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=j8r6zV3IEktEeBidDu6w6MpwFi6YkkHS02O0zUC0bQU=; b=ZhWtOEMWNsZTy66YnUSfM+vSeMkQXQjREusRvBKXrlKSlM7PydkH7stkzRWGpHjlu6 +7g15x+rVWqM9g2NTLSmhkb4CCf4loZuaoTgionVeck7M/udDy2d+kLYpl1DyxW5zitj UXu1kk3ZyfZYm0bqQS3WqXiuGsVJDYPY3rDbWo1AHn5dLa8cVrmvWrwAER7lVEg8IbW5 ZY5C2pwQ/12IgsXwczUmnPErCeckrehAWew+Q6ssMGA+EOFyOBABGsRozwf13er4CQ7v 3su9rsdqFLSZwngaZgU8unFEN0dJCjMJcZ1b26WOxXRT2OUM7ug81+RV0gAWm3rmMT/1 uQuw== X-Gm-Message-State: APjAAAW+W/IL6PLOMra5UOi3pBe66ryje61/6yJPjlMFjp5bxpz3xVrp m9YUWwaYwUOFkiuIkqh6zXoiKg== X-Received: by 2002:a54:4615:: with SMTP id p21mr2435033oip.22.1562063726111; Tue, 02 Jul 2019 03:35:26 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:25 -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 05/11] perf trace: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:14 +0800 Message-Id: <20190702103420.27540-6-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-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 } This patch directly returns NULL when fail to allocate memory for ttrace; this can avoid potential NULL pointer dereference. Signed-off-by: Leo Yan --- tools/perf/builtin-trace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index f3532b081b31..874d78890c60 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1038,9 +1038,10 @@ static struct thread_trace *thread_trace__new(void) { struct thread_trace *ttrace = zalloc(sizeof(struct thread_trace)); - if (ttrace) - ttrace->files.max = -1; + if (ttrace == NULL) + return NULL; + ttrace->files.max = -1; ttrace->syscall_stats = intlist__new(NULL); return ttrace; From patchwork Tue Jul 2 10:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168306 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072679ilk; Tue, 2 Jul 2019 03:35:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcuXgfeL23xPMwlRS18rfwwHEXBfW9D0mfR7oKjErTr7iujW5rJb44tskfoOydDHT4eQQ3 X-Received: by 2002:a17:902:7041:: with SMTP id h1mr34451453plt.133.1562063745290; Tue, 02 Jul 2019 03:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063745; cv=none; d=google.com; s=arc-20160816; b=0/QM3dEy2KTxMmCStpok8WZqkYTcnhN7F48jgt7mU1FVlEVqZNCJjEPyoRaFK4XpNS JToR74PHidme73K15ZznsuZwPstuWj1N4S4c2LLa2Z+kWfKNzPcHvkORYMiUDJlpjbNI kSLKeSvtrxjCOyXxL1PuE4XoTWMnZ+hPhnr/EMF7OuRNAi5Me0t9lHU1vm7VuXwMi00L FWAQc57HdsAloR51fmy70T1zCdiWT1hHHSWtUxhOMdsDET0kilw+K0RavZb9tKR5AIkI 0+QnrfKoHl4j2zwnZTtHijl7dKSH1AzcILsHcF/yFlKwHBtcb49hRMpyZ/PC0Szl4cM4 AE+g== 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=pR8OnU6ONKK8WXaF3q0PWRqZRj/gofETqCh57U/9pps=; b=lXLo6WGPInZwJPsfPsp90l/IB2GAd+bOp+6b6ipkYY3p7UFlzxcBXPYRBEOEDqXMSz ig5OIEOPmrWhrrulJqlurvkuZG/7JNppgZx4puu+GmbcvYkb4pU4P/5PE5688WO0uQGc zs4VNq0qS5u1RIVQUkIZg473Nw3vrOLJHm/OlAJFdqbEwTj69M7FnVf5EL9JWgGbeifa bBHxZOBKeoV+hdkFhIASpi/i9WmPO4lTB2mpkXsf/YmkBZ5zM26ZLlHScjnWI25Zv/dc IKpphcVk8CVJHK5DpjeVMroS5q72ijbbrcDFJ/eY78R3eXS8j7PLeODou0BOn79GpXRy LCyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gqUYj3Rg; 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.45; Tue, 02 Jul 2019 03:35:45 -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=gqUYj3Rg; 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 S1727294AbfGBKff (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:35 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:43245 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfe (ORCPT ); Tue, 2 Jul 2019 06:35:34 -0400 Received: by mail-ot1-f66.google.com with SMTP id q10so6705019otk.10 for ; Tue, 02 Jul 2019 03:35:34 -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=pR8OnU6ONKK8WXaF3q0PWRqZRj/gofETqCh57U/9pps=; b=gqUYj3RgcmbrGaA8NafweIqkT9dOdE8BbJZXI+ANioWM70cMuoNl7wgH8y7qyORqBP MrOo4umrodn+Q4qIgwxpFIBLrCit6U2wXsumMe5NX/NcBUN98yGQQgw5PDFKzGdWeAif T0HaRSKYOBlDUWYerXzXCwcJBErDmF66NK3NbzTASZBFJfCZTf681g3c3MMx3MB6Sj2z aiyeEui7Vl/tIxL9w8C53Q0o0E1fB5HdJ/7bmX1l7kvUuRXM4DO2+jhbXtB8R9UU3z2S 68owNLcHSQeyp9OTm7P/ivHJg0HXEtVBw1yBkFt+UMw4KPPPxrzs/dm6pvWXMIepPWjA dwgA== 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=pR8OnU6ONKK8WXaF3q0PWRqZRj/gofETqCh57U/9pps=; b=ROuWLk4Fou3bNl6rXd9PTI5WRz7RznvmkLgjkuCKz5zPXsMCAwaJgiml1u7xTqT+bV 1jPl9uqyh7Ta9ZB5MH1BBks81MBr2FIsZw75/P2BveWkhhy3+pSCMNbvYt4DKPhYo835 F6nKTPFrI6O+Uzq52YHLXygxWM4TTo6aoBMjVig0j/WKBtFDH2jekiQnYbpKHsxsFXfC BSeP3Wk8ETany5ko73OUDEK9/SoSfjfqC+//B3oEX/FieTa+3vJeN0xwbb5Aak9GENGn Gh2sVo9oDG5LlqkP6wDi0djJKJLGF0oj/HNNymuUcbmUu1df/dVAlWupvNs9fdgIaoyW 7sww== X-Gm-Message-State: APjAAAWD1Fnw7bbhdubHAcSmso7FMB+7U03vn1zTXWCMH+bITfIPqsWo KipJo2pfp+xzBuCWg/ccZl1/lg== X-Received: by 2002:a05:6830:14c:: with SMTP id j12mr22891677otp.181.1562063733986; Tue, 02 Jul 2019 03:35:33 -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.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:33 -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 06/11] perf hists: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:15 +0800 Message-Id: <20190702103420.27540-7-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/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 --- tools/perf/ui/browsers/hists.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 3421ecbdd3f0..2ba33040ddd8 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c @@ -638,7 +638,9 @@ int hist_browser__run(struct hist_browser *browser, const char *help, switch (key) { case K_TIMER: { u64 nr_entries; - hbt->timer(hbt->arg); + + if (hbt) + hbt->timer(hbt->arg); if (hist_browser__has_filter(browser) || symbol_conf.report_hierarchy) @@ -2819,7 +2821,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]; @@ -3085,7 +3087,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; @@ -3269,7 +3273,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 2 10:34:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168307 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072755ilk; Tue, 2 Jul 2019 03:35:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkaAW9B0RvahcV9HMUuCboAwhvCXaItFOZZkwEXwQKzVnarkCFWF886RcoZoGPwHTQicXo X-Received: by 2002:a63:d4c:: with SMTP id 12mr30739401pgn.30.1562063748450; Tue, 02 Jul 2019 03:35:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063748; cv=none; d=google.com; s=arc-20160816; b=GeosI96sXnSVO0kX3MJjngIVbYWoBWihsu7HkXOMHoCUnXJn6VSeeEZ6H06U3FEzRe n8mj1ibXdyrTgJEW3pyRvb664kDgi2HrvsnTEaUFvCZ2Y2yQ+ZEQtbOezAeB795SKSi8 qo/Dk4Eprs2AqwZbc4x5G/UY7QEmxm4NbiEmsDsYDS0bseZKQvxlWIwbYJB7IlmEJk2u ahkBgD4uF0paSj8OREXBPeXhv//ipLBezdkxCFmPbBj5uK4F23PBtEqYMdXzYHBdI1pq tJBiD2sPZ3Q931pdMLa/yk2go0EI//BwgNDCwAznngkLlJ1unjvAZfvsbUvZQeW3r7Mc I/Kw== 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=V5qTJJXMX1ZTj5uDhYEBO+OiJyquQwYXAx7tq46WL+E=; b=Cv8IFEhZyCC3pwNgGnZm5VcMhnwXkwBOwuBqFc1WqCfOofIg7W83ce1jGVYZnM1zfe XdgAmmy+LtZXD56h6Js79HuQQFPFHaReetLaTXkEK+JtpO4lU1hzz43KF9gKE2Rmsiag T3le2z/f1TGP9b0/bdKh31wt3k4oVijCmeV9FA+p6QedP6fLuv+yLN20rOnhod5c8+C4 I2jsYB16RS0ktYik4Ha30130Si1ddmozLy2RJICA95rnSHeol+vyNTEgM+Z++uJPlm7l vyJbbcNko9twn9q9uLeomrwBR05FEtU64jA9iNjaOTaONu5OKPAvPK2LUbBvzxGY1C/L KFyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kl6cvJ0z; 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 s18si12326007pgj.541.2019.07.02.03.35.48; Tue, 02 Jul 2019 03:35:48 -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=kl6cvJ0z; 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 S1727314AbfGBKfo (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:44 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:41393 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKfn (ORCPT ); Tue, 2 Jul 2019 06:35:43 -0400 Received: by mail-oi1-f196.google.com with SMTP id g7so12618800oia.8 for ; Tue, 02 Jul 2019 03:35:42 -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=V5qTJJXMX1ZTj5uDhYEBO+OiJyquQwYXAx7tq46WL+E=; b=kl6cvJ0zlfJ4KIzgl8/M2GfhjusvmgoE9v0c+xjgfAU4sjiJCtTNEv2yzhWtVB8AI+ gVbM8Qqsd7hSC9h0YewLPNreo18mQdKFVsH7a/QDGIyl2Bx1MoYHbh/qxkHoMHpiHQQZ vGOf5QD+aLwBNctZy/pFQEZGJbP+OIpBoWjVd7U6ksXP+Kq7VHvzUoFQcrbYXG+R4IXC T2VkFAs1O1gftEP2gLOO9Rw0MVuxO3GxyeHuurTVufDtKMAqN1fYRoKPEeS15cpCs1uV ZLkVdcbR1CFwm0XLj32S+RmS5gWwfsNv0VOqqgjvUahAMaBkQgFnEolKo5Cz/8uEdTmr yehA== 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=V5qTJJXMX1ZTj5uDhYEBO+OiJyquQwYXAx7tq46WL+E=; b=acWDy8EZ1JCm0F7Ic8GDu20suVPFVL2KVuU0akvDhGmmrCHD+cGVP1Qm+WHqk9wLh9 wyWzzx13n7d94PDcJAi3RrA4eBhLkKnqFPgUXqIgNkeSVC65tXnjofpq96WWajClOTqE G3/lQonenCugIJ5rPg+PYaMyOVnzhP4mo/ObB0eCTwqaw1JQXnms17K8AsekHZMF37yl /u0iJO01doXDJx0eDcSSvgXDLkMd9ZvYEhbJW8T8TvjyflUQRMOqqtxxVX5i5zpKmqVu Jcud13un8Ld8PwHGpuRY6RMdmO96Fs5LrNjLHsIU4VCdkoTceYiYSPoo0cMssK9GAb7Y DFiw== X-Gm-Message-State: APjAAAUSOmd78AD2lj4FQRIzyQCKtxZGO2ZBNEZIGvv7tRknUp+MW0MI BMZReAQDJ4MBycDdpNfMJ56Omw== X-Received: by 2002:aca:c5d0:: with SMTP id v199mr2313436oif.144.1562063742299; Tue, 02 Jul 2019 03:35:42 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:41 -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 07/11] perf map: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:16 +0800 Message-Id: <20190702103420.27540-8-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/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 --- tools/perf/util/map.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) -- 2.17.1 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 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) From patchwork Tue Jul 2 10:34:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168310 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4072966ilk; Tue, 2 Jul 2019 03:36:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwv/A/XTPUJVdb/J3jIwwMetc/KuVbVgPPo8/d+2QnIaCgFZoxluDxqCEUesY5+dvdSzeQ2 X-Received: by 2002:a17:902:848b:: with SMTP id c11mr34280162plo.217.1562063760195; Tue, 02 Jul 2019 03:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063760; cv=none; d=google.com; s=arc-20160816; b=OMcyrpaT0IycOLutZ8/UJ8jWcfkdyqoKUs7wjhMn0mP3XPtexqC7VvM8qHcpUK+Qcj GkJK1+zUBV6zk54/wsT/0pfUuo5xYr2rldOqyaVw5N55jyA34C41raeksczby/q7fP/x bHdgJNEgSarcyLW1YYqHI6KeGsfVOEEk00GH/Rrbmky9YuFY3R7L2E5fi9ZHkNxHVVFu TTpadCSWI+CXOyzGsiHvX4R0lL5q9N1QE+EtaobzpQwvSVMdC+rsd55om33QP5ybh5i7 sjgeS9WB0+TfyWDA0x2FeXZsY2SYRB27YUrILW4VB1pu1Hd3UW7HJqNfsddqhCCyVkPB unrg== 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=oEKxu+SRBR2p4slj10y4/Ir+izytEa7NCXuzbUYce7M=; b=EC6Y5cfkoS5dBcfGfiSl36iLMN2Fo0FsqbzXFZ+8HaXagQZKNx5G/TFqQWXPI3Y68q DVoKtwRhpVPAFlZi+ENecwMr4YYffE9HHGc9PgLu3KfpiG8kfrc3t22n9vzl6K1gWaiL VCr/1973yMoU6ibTVO8uOZBNaNXAxIRjw1zmD4ILoXeYvibEnrg2hhzlnTOCYiNRZHW2 2wZAdywoCrTu9nbaMNnRN5aHsaBJxO9ONl9ZHE8Dkhtf5hzofE0lkMMmvepz7qWsrfPf H3HXwJOKKfx2ArQyeFQkZ0G55HT1eA18oQ8OFwWWFJGInLe+vYHHOl3Uv+TfvALlJw8F 4sig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wEvS8Xbw; 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.59; Tue, 02 Jul 2019 03:36:00 -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=wEvS8Xbw; 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 S1727342AbfGBKf6 (ORCPT + 30 others); Tue, 2 Jul 2019 06:35:58 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:40818 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKf6 (ORCPT ); Tue, 2 Jul 2019 06:35:58 -0400 Received: by mail-ot1-f68.google.com with SMTP id e8so16625411otl.7 for ; Tue, 02 Jul 2019 03:35:57 -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=oEKxu+SRBR2p4slj10y4/Ir+izytEa7NCXuzbUYce7M=; b=wEvS8XbwFUFKdw+GxKZqyPYxrcjlJT6R7i4Djuo1pSo+8XRmo7dDVof0wJA6PCR3vd qFIwAcP7pDtAB8QbnK8W71bnfDTiUGrGvzNBaQ0BVXdhbpi92FhKXZpRzcCfxHl/1lrQ 0cnaFXJ4pGbGcg1Yj4KSf+weubc02b4z+z7aH8vZoygulTfyy1oCju1llcUE2/B5TAxO CBNT+MRWqFb+e57BQqcIPMsbBIg6p2JsXmSoO7EAI5kgLk7RIPuGCzZnvROcdx4biUl9 MWos28VX/AKKwLxXLoiRvshrmKgM0HO7EpW4LV9lPKGSBYUH2dyccIMucEgvK6w26lQT 61Og== 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=oEKxu+SRBR2p4slj10y4/Ir+izytEa7NCXuzbUYce7M=; b=GNqSNC1cwK/wKR72ZXJa37YlDHM02vLqOc2GqTno5QLw/LTCeMya2fg0OtkpO7kyA/ YarGl+G5JazzwEjeTmKBhDnWvWSc73fanQxrKNsUmM7MacSc8mkDbnuoiXiKhNDhkopZ 4DrrX3757WLYRdDlRAk0IJ0Dav9bt68C1vysk8fLImkSflS7N0Qyc4JKIzhCE59scFbi FOERrfenHSsZsVxZgSCNPfICC0wXeam9DUuHwFJzfXjFPY2jM3fNSOY/AB2aC2sivFlD sAtplDg6kgxjknvouajcS9zxOTQj4EB9mQmjB2maTh3aBPG2m6QrHvmMG+ZCxkhiImja EaXg== X-Gm-Message-State: APjAAAVvvBf26lcFuV+0K+bIXJDCiCK8umFmdJm+b/LT860dczjMeVf+ v7RM1cIBRg2ZSFqsfsvRNIVLjw== X-Received: by 2002:a9d:664c:: with SMTP id q12mr21775879otm.175.1562063757276; Tue, 02 Jul 2019 03:35:57 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:35:56 -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 09/11] perf intel-bts: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:18 +0800 Message-Id: <20190702103420.27540-10-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-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 } 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-bts.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index e32dbffebb2f..332e647fecaa 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c @@ -893,11 +893,10 @@ int intel_bts_process_auxtrace_info(union perf_event *event, if (session->itrace_synth_opts && session->itrace_synth_opts->set) { bts->synth_opts = *session->itrace_synth_opts; - } else { + } else if (session->itrace_synth_opts) { 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 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; } From patchwork Tue Jul 2 10:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 168312 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4073232ilk; Tue, 2 Jul 2019 03:36:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYPSAzPtRIkFe4+YgI58DPqSutW1N2I/EFzbmrArebAU6v5wFnjO9Qm/u4EOh2hZ/vXBFZ X-Received: by 2002:a17:902:204:: with SMTP id 4mr1192746plc.178.1562063775241; Tue, 02 Jul 2019 03:36:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562063775; cv=none; d=google.com; s=arc-20160816; b=MLcuuIlrb7/lZ4d8J7izGWJ/68NleZcfqe6WxWc56q7KbcUlq9PGibbVjvd7DzWJkh 9DUwfVrslo4g191qSivJxlWJNV8ld+P4rg5W4MwQfjzBWI0rBoGvPTbjnCv6EEEc7U9y tZPndeZQSoImDeF06SotvrpQjYkfFYfz/uOiiAh0UG/+CgxC4OyiKzEteLpg5uuhomZe B5Tki6SBwUd1RqlcFYZU6pbn0peIaDn/c/3VE76OGOPAD6nu4xSObeEBTC82+ja9CfI6 5qKJh0IdAVoOj+9JX6iM/YzGvbAnPD4XDHn23Rtuj/zWBP5ZjCwMBbfQVWXvIFxDXfC6 8Yfw== 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=dQcQ7p8oORqYUmw8MhMOFx6e3+qYvK2rxF9oxDoZM7o=; b=FlFQvHwT8Zorex6Y47Wi+cJkEa9d0tyjsij5Z6VW2GsZqym3NQ9IDGODSxV3JudiU7 xZcU/fRkDlSTohhFlLLjs2YS6usj65iaQ+DoEwBf020LWjdmt8KIKN5XFxypG/vvxefv Vpg1hfSdKvLNUy9GoMWGHzako/hrxiaoweYB+WTbJcytLElcgwm9hQlg1foDKjYh/qUY SVbQ9EdK+UFnZh8RfvOriN5CLff5N6WpiuikY2rNUKCEYMR8cH0vtkLZEf6YOVnG1c8S r5XoBB27YmI6cAsZfWXHrnweflQ1/0vRdub5QHqMZR2FcMKgfRmVmAY9F7rNEUS+bPL/ l+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JjPXkNjN; 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 v15si13459496pfm.238.2019.07.02.03.36.14; Tue, 02 Jul 2019 03:36:15 -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=JjPXkNjN; 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 S1727365AbfGBKgN (ORCPT + 30 others); Tue, 2 Jul 2019 06:36:13 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:43983 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725801AbfGBKgN (ORCPT ); Tue, 2 Jul 2019 06:36:13 -0400 Received: by mail-oi1-f195.google.com with SMTP id w79so12633872oif.10 for ; Tue, 02 Jul 2019 03:36:12 -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=dQcQ7p8oORqYUmw8MhMOFx6e3+qYvK2rxF9oxDoZM7o=; b=JjPXkNjNwzvim2+CUz73ozuGlX5deuQwPQXRLkI9Fyk/R2nArA59R51YaLMo8npnVO oDx52w/nnl82obHSJkgpF8mTIFXGgbsPgPRY0VhOjMmYjUfylrDBve/OsYv5SO5HwI/t fJtTAVO+HkS47kqFPjOMzwwEZDDJvwgP7lEbyF1Voea5leDzo8xMvT97Wip/cBsMj5HC qb+vN0sL1ae3v1Lp2+ZMoD6/7mRVeEM/HozhAt6Nchk7yTPvTc9H31mPH+gFGlRyx5hx n8EIseeSRFabSWYYZvbYMFwVKE8LJaUpguIJXOkH/Nu/sENoYoO49Zw4nIctWDhGf81L pkfg== 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=dQcQ7p8oORqYUmw8MhMOFx6e3+qYvK2rxF9oxDoZM7o=; b=kGb8lw7mS5IjbZqt8L9sSsQGrKwhK30M6RQJ/+ZncbSPj6LobBCCJ3jkDlbU/n0Z86 g3tsANgagV5eAmXnZxn6JXPzNz6DOtym2wyDAKGSXLo3ZTOlv2564LbmXdatDgK7IenN foSv93QVB3urJW3uDJH71kupAMLGrO79gV1uUCk+vgqEGIyqx0ipBoH0Q6nGHbvqZUM6 nM4v+3vVJls2uuO15Gf/m7BVmzVoQQXU9+tV+z6vHCszEcFYGVoSXUZJhHnKZH4JNqMq +QFwXzhwb140xCPh/7LAjkfZcDR+7KDNR2Tavy+mBG6klLJKGAdsuHZY4op5dAbWwIVQ CxKg== X-Gm-Message-State: APjAAAVVSC58k9p5VDUGpo0gyA/dB94Yw5FPFn8xXUHtkaqjJgaTCrWA Fb/kyO5CpzbBsrg/+okITD+8Aw== X-Received: by 2002:aca:be88:: with SMTP id o130mr2506821oif.122.1562063772431; Tue, 02 Jul 2019 03:36:12 -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.36.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 03:36:11 -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 11/11] perf cs-etm: Smatch: Fix potential NULL pointer dereference Date: Tue, 2 Jul 2019 18:34:20 +0800 Message-Id: <20190702103420.27540-12-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/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 } 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/cs-etm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/tools/perf/util/cs-etm.c b/tools/perf/util/cs-etm.c index 0c7776b51045..b79df56eb9df 100644 --- a/tools/perf/util/cs-etm.c +++ b/tools/perf/util/cs-etm.c @@ -2540,7 +2540,7 @@ int cs_etm__process_auxtrace_info(union perf_event *event, if (session->itrace_synth_opts && session->itrace_synth_opts->set) { etm->synth_opts = *session->itrace_synth_opts; - } else { + } else if (session->itrace_synth_opts) { itrace_synth_opts__set_default(&etm->synth_opts, session->itrace_synth_opts->default_no_sample); etm->synth_opts.callchain = false;