linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] locktorture: Fix NULL pointer when torture_type is invalid
@ 2016-01-28  4:25 Kefeng Wang
  2016-01-30  2:46 ` Kefeng Wang
  0 siblings, 1 reply; 22+ messages in thread
From: Kefeng Wang @ 2016-01-28  4:25 UTC (permalink / raw)
  To: Paul E . McKenney, linux-kernel; +Cc: peterz, mingo, Kefeng Wang, Josh Triplett

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 : [<ffffffbffc017028>] lr : [<ffffffbffc017500>] pstate: 60000145
sp : ffffffc0fa93bb20
[snip...]
Call trace:
[<ffffffbffc017028>] __torture_print_stats+0x18/0x180 [locktorture]
[<ffffffbffc017500>] lock_torture_stats_print+0x68/0x110 [locktorture]
[<ffffffbffc0180fc>] lock_torture_cleanup+0xc4/0x278 [locktorture]
[<ffffffbffc01d144>] lock_torture_init+0x144/0x5b0 [locktorture]
[<ffffffc000082940>] do_one_initcall+0x94/0x1a0
[<ffffffc000141888>] do_init_module+0x60/0x1c8
[<ffffffc00011c628>] load_module+0x1880/0x1c9c
[<ffffffc00011cc00>] SyS_finit_module+0x7c/0x88
[<ffffffc000085cb0>] 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 <josh@joshtriplett.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 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 ",
-- 
2.6.0.GIT

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2016-03-08 19:52 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-28  4:25 [PATCH v2] locktorture: Fix NULL pointer when torture_type is invalid Kefeng Wang
2016-01-30  2:46 ` Kefeng Wang
2016-01-31  0:27   ` Paul E. McKenney
2016-01-31 22:17     ` Davidlohr Bueso
2016-02-01  2:25       ` Kefeng Wang
2016-02-01  3:02         ` Davidlohr Bueso
2016-02-01  3:28           ` Kefeng Wang
2016-02-02  6:46             ` Paul E. McKenney
2016-02-03  0:23               ` Davidlohr Bueso
2016-03-02 19:55                 ` Davidlohr Bueso
2016-03-02 21:12                   ` Paul E. McKenney
2016-03-03  1:37                     ` Kefeng Wang
2016-03-03  4:31                       ` Kefeng Wang
2016-03-03  8:36                         ` Davidlohr Bueso
2016-03-04 18:41                           ` Davidlohr Bueso
2016-03-07  2:00                           ` Kefeng Wang
2016-03-07  5:40                             ` Davidlohr Bueso
2016-03-07  7:02                               ` Kefeng Wang
2016-03-07 13:37                                 ` Paul E. McKenney
2016-03-08  2:10                                   ` Kefeng Wang
2016-03-08 19:51                                     ` Paul E. McKenney
2016-03-03 14:14                       ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).