Jeremy Cline c16b4f1
From 14d329da03ea1145efce866b127b10ea6390b5e1 Mon Sep 17 00:00:00 2001
Jeremy Cline c16b4f1
From: Murphy Zhou <jencce.kernel@gmail.com>
Jeremy Cline c16b4f1
Date: Sun, 29 Sep 2019 17:56:59 +0800
Jeremy Cline c16b4f1
Subject: [PATCH] mm/kmemleak: skip late_init if not skip disable
Jeremy Cline c16b4f1
Jeremy Cline c16b4f1
Now if DEFAULT_OFF set to y, kmemleak_init will start the cleanup_work
Jeremy Cline c16b4f1
workqueue. Then late_init call will set kmemleak_initialized to 1, the
Jeremy Cline c16b4f1
cleaup workqueue will try to do cleanup, triggering:
Jeremy Cline c16b4f1
Jeremy Cline c16b4f1
[24.738773] ==================================================================
Jeremy Cline c16b4f1
[24.742784] BUG: KASAN: global-out-of-bounds in __kmemleak_do_cleanup+0x166/0x180
Jeremy Cline c16b4f1
[24.744144] Key type ._fscrypt registered
Jeremy Cline c16b4f1
[24.745680] Read of size 8 at addr ffffffff88746c90 by task kworker/3:1/171
Jeremy Cline c16b4f1
[24.745687]
Jeremy Cline c16b4f1
[24.745697] CPU: 3 PID: 171 Comm: kworker/3:1 Not tainted 5.3.0-v5.3-12475-gcbafe18 #1
Jeremy Cline c16b4f1
[24.745701] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
Jeremy Cline c16b4f1
[24.745710] Workqueue: events kmemleak_do_cleanup
Jeremy Cline c16b4f1
[24.745717] Call Trace:
Jeremy Cline c16b4f1
[24.745736]  dump_stack+0x7c/0xc0
Jeremy Cline c16b4f1
[24.745755]  print_address_description.constprop.4+0x1f/0x300
Jeremy Cline c16b4f1
[24.751562] Key type .fscrypt registered
Jeremy Cline c16b4f1
[24.754370]  __kasan_report.cold.8+0x76/0xb2
Jeremy Cline c16b4f1
[24.754388]  ? __kmemleak_do_cleanup+0x166/0x180
Jeremy Cline c16b4f1
[24.754407]  kasan_report+0xe/0x20
Jeremy Cline c16b4f1
[24.778543]  __kmemleak_do_cleanup+0x166/0x180
Jeremy Cline c16b4f1
[24.780795]  process_one_work+0x919/0x17d0
Jeremy Cline c16b4f1
[24.782929]  ? pwq_dec_nr_in_flight+0x320/0x320
Jeremy Cline c16b4f1
[24.785092]  worker_thread+0x87/0xb40
Jeremy Cline c16b4f1
[24.786948]  ? __kthread_parkme+0xc3/0x190
Jeremy Cline c16b4f1
[24.789217]  ? process_one_work+0x17d0/0x17d0
Jeremy Cline c16b4f1
[24.791414]  kthread+0x333/0x3f0
Jeremy Cline c16b4f1
[24.793031]  ? kthread_create_worker_on_cpu+0xc0/0xc0
Jeremy Cline c16b4f1
[24.795473]  ret_from_fork+0x3a/0x50
Jeremy Cline c16b4f1
[24.797303]
Jeremy Cline c16b4f1
[24.798091] The buggy address belongs to the variable:
Jeremy Cline c16b4f1
[24.800634]  mem_pool_free_count+0x10/0x40
Jeremy Cline c16b4f1
[24.802656]
Jeremy Cline c16b4f1
[24.803434] Memory state around the buggy address:
Jeremy Cline c16b4f1
[24.805793]  ffffffff88746b80: 04 fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
Jeremy Cline c16b4f1
[24.809177]  ffffffff88746c00: 00 fa fa fa fa fa fa fa 00 00 fa fa fa fa fa fa
Jeremy Cline c16b4f1
[24.812407] >ffffffff88746c80: 04 fa fa fa fa fa fa fa 00 00 fa fa fa fa fa fa
Jeremy Cline c16b4f1
[24.815638]                          ^
Jeremy Cline c16b4f1
[24.817372]  ffffffff88746d00: 00 00 fa fa fa fa fa fa 00 00 00 00 00 00 00 00
Jeremy Cline c16b4f1
[24.820740]  ffffffff88746d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Jeremy Cline c16b4f1
[24.824021] ==================================================================
Jeremy Cline c16b4f1
Jeremy Cline c16b4f1
Fixes: c5665868183f ("mm: kmemleak: use the memory pool for early allocations")
Jeremy Cline c16b4f1
Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
Jeremy Cline c16b4f1
---
Jeremy Cline c16b4f1
 mm/kmemleak.c | 5 +++++
Jeremy Cline c16b4f1
 1 file changed, 5 insertions(+)
Jeremy Cline c16b4f1
Jeremy Cline c16b4f1
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
Jeremy Cline c16b4f1
index 03a8d84badad..b9baf617fe35 100644
Jeremy Cline c16b4f1
--- a/mm/kmemleak.c
Jeremy Cline c16b4f1
+++ b/mm/kmemleak.c
Jeremy Cline c16b4f1
@@ -1946,6 +1946,11 @@ void __init kmemleak_init(void)
Jeremy Cline c16b4f1
  */
Jeremy Cline c16b4f1
 static int __init kmemleak_late_init(void)
Jeremy Cline c16b4f1
 {
Jeremy Cline c16b4f1
+	if (!kmemleak_skip_disable) {
Jeremy Cline c16b4f1
+		kmemleak_disable();
Jeremy Cline c16b4f1
+		return 0;
Jeremy Cline c16b4f1
+	}
Jeremy Cline c16b4f1
+
Jeremy Cline c16b4f1
 	kmemleak_initialized = 1;
Jeremy Cline c16b4f1
 
Jeremy Cline c16b4f1
 	debugfs_create_file("kmemleak", 0644, NULL, NULL, &kmemleak_fops);
Jeremy Cline c16b4f1
-- 
Jeremy Cline c16b4f1
2.21.0
Jeremy Cline c16b4f1