From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932570AbcAaA1c (ORCPT ); Sat, 30 Jan 2016 19:27:32 -0500 Received: from e32.co.us.ibm.com ([32.97.110.150]:57516 "EHLO e32.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932134AbcAaA1a (ORCPT ); Sat, 30 Jan 2016 19:27:30 -0500 X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: paulmck@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Date: Sat, 30 Jan 2016 16:27:21 -0800 From: "Paul E. McKenney" To: Kefeng Wang Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, Josh Triplett , "Guohanjun (Hanjun Guo)" , dave@stgolabs.net Subject: Re: [PATCH v2] locktorture: Fix NULL pointer when torture_type is invalid Message-ID: <20160131002721.GI6719@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <1453955159-23216-1-git-send-email-wangkefeng.wang@huawei.com> <56AC2421.7020006@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <56AC2421.7020006@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16013100-0005-0000-0000-00001BEB792A Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jan 30, 2016 at 10:46:57AM +0800, Kefeng Wang wrote: > Hi Paul, > > On 2016/1/28 12:25, Kefeng Wang wrote: > > 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. > > It is keep to get the statistics printout at the end if with bad argument, > what's your opinion about this version? Hello, Kefeng, Well, it does look like it would prevent the NULL pointer dereference, but I was hoping for something that would print the full statistics at the end regardless of the periodic statistics. But I am adding Davidlohr on CC, as he seems to be the major user of locktorture. Thanx, Paul > Thanks, > Kefeng > > > > > Cc: Josh Triplett > > Cc: Paul E. McKenney > > Signed-off-by: Kefeng Wang > > --- > > kernel/locking/locktorture.c | 24 ++++++++++++++---------- > > 1 file changed, 14 insertions(+), 10 deletions(-) > > > > 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 ", > > >