From patchwork Thu Jan 28 04:25:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 60674 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp243306lbb; Wed, 27 Jan 2016 20:23:17 -0800 (PST) X-Received: by 10.66.229.104 with SMTP id sp8mr1402927pac.53.1453954997557; Wed, 27 Jan 2016 20:23:17 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si10595723pfi.64.2016.01.27.20.23.17; Wed, 27 Jan 2016 20:23:17 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968458AbcA1EXP (ORCPT + 30 others); Wed, 27 Jan 2016 23:23:15 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:60310 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935022AbcA1EXK (ORCPT ); Wed, 27 Jan 2016 23:23:10 -0500 Received: from 172.24.1.48 (EHLO szxeml426-hub.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DDU58188; Thu, 28 Jan 2016 12:22:52 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml426-hub.china.huawei.com (10.82.67.181) with Microsoft SMTP Server id 14.3.235.1; Thu, 28 Jan 2016 12:22:40 +0800 From: Kefeng Wang To: "Paul E . McKenney" , CC: , , Kefeng Wang , Josh Triplett Subject: [PATCH v2] locktorture: Fix NULL pointer when torture_type is invalid Date: Thu, 28 Jan 2016 12:25:59 +0800 Message-ID: <1453955159-23216-1-git-send-email-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.6.0.GIT MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.56A9979E.0015, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 8708367aa0c4f140c9513f1a9424926e Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Insmod locktorture with torture_type=mutex will lead to crash, Unable to handle kernel NULL pointer dereference at virtual address 00000008 pgd = ffffffc0f6c10000 [00000008] *pgd=000000013b221003, *pud=000000013b221003, *pmd=0000000000000000a Internal error: Oops: 94000006 [#1] PREEMPT SMP Modules linked in: locktorture(+) torture CPU: 2 PID: 1462 Comm: insmod Not tainted 4.4.0+ #19 Hardware name: linux,dummy-virt (DT) task: ffffffc0fb2b3700 ti: ffffffc0fa938000 task.ti: ffffffc0fa938000 PC is at __torture_print_stats+0x18/0x180 [locktorture] LR is at lock_torture_stats_print+0x68/0x110 [locktorture] pc : [] lr : [] pstate: 60000145 sp : ffffffc0fa93bb20 [snip...] Call trace: [] __torture_print_stats+0x18/0x180 [locktorture] [] lock_torture_stats_print+0x68/0x110 [locktorture] [] lock_torture_cleanup+0xc4/0x278 [locktorture] [] lock_torture_init+0x144/0x5b0 [locktorture] [] do_one_initcall+0x94/0x1a0 [] do_init_module+0x60/0x1c8 [] load_module+0x1880/0x1c9c [] SyS_finit_module+0x7c/0x88 [] el0_svc_naked+0x24/0x28 Fix it by check statp in __torture_print_stats(), if it is NULL, just create a lock-torture-statistics message with zero statistic argument. Cc: Josh Triplett Cc: Paul E. McKenney Signed-off-by: Kefeng Wang --- kernel/locking/locktorture.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) -- 2.6.0.GIT diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 8ef1919..7f0cf9c 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -647,19 +647,23 @@ static void __torture_print_stats(char *page, bool fail = 0; int i, n_stress; long max = 0; - long min = statp[0].n_lock_acquired; + long min = 0; long long sum = 0; - n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress; - for (i = 0; i < n_stress; i++) { - if (statp[i].n_lock_fail) - fail = true; - sum += statp[i].n_lock_acquired; - if (max < statp[i].n_lock_fail) - max = statp[i].n_lock_fail; - if (min > statp[i].n_lock_fail) - min = statp[i].n_lock_fail; + if (statp) { + min = statp[0].n_lock_acquired; + n_stress = write ? cxt.nrealwriters_stress : cxt.nrealreaders_stress; + for (i = 0; i < n_stress; i++) { + if (statp[i].n_lock_fail) + fail = true; + sum += statp[i].n_lock_acquired; + if (max < statp[i].n_lock_fail) + max = statp[i].n_lock_fail; + if (min > statp[i].n_lock_fail) + min = statp[i].n_lock_fail; + } } + page += sprintf(page, "%s: Total: %lld Max/Min: %ld/%ld %s Fail: %d %s\n", write ? "Writes" : "Reads ",