Skip to content

Commit c32caa2

Browse files
xairytorvalds
authored andcommitted
kasan: disable LOCKDEP when printing reports
If LOCKDEP detects a bug while KASAN is printing a report and if panic_on_warn is set, KASAN will not be able to finish. Disable LOCKDEP while KASAN is printing a report. See https://bugzilla.kernel.org/show_bug.cgi?id=202115 for an example of the issue. Link: https://lkml.kernel.org/r/c48a2a3288200b07e1788b77365c2f02784cfeb4.1646237226.git.andreyknvl@google.com Signed-off-by: Andrey Konovalov <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Marco Elver <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 8020791 commit c32caa2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mm/kasan/report.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/ftrace.h>
1414
#include <linux/init.h>
1515
#include <linux/kernel.h>
16+
#include <linux/lockdep.h>
1617
#include <linux/mm.h>
1718
#include <linux/printk.h>
1819
#include <linux/sched.h>
@@ -148,6 +149,8 @@ static void start_report(unsigned long *flags, bool sync)
148149
disable_trace_on_warning();
149150
/* Update status of the currently running KASAN test. */
150151
update_kunit_status(sync);
152+
/* Do not allow LOCKDEP mangling KASAN reports. */
153+
lockdep_off();
151154
/* Make sure we don't end up in loop. */
152155
kasan_disable_current();
153156
spin_lock_irqsave(&report_lock, *flags);
@@ -160,12 +163,13 @@ static void end_report(unsigned long *flags, void *addr)
160163
trace_error_report_end(ERROR_DETECTOR_KASAN,
161164
(unsigned long)addr);
162165
pr_err("==================================================================\n");
163-
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
164166
spin_unlock_irqrestore(&report_lock, *flags);
165167
if (panic_on_warn && !test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
166168
panic("panic_on_warn set ...\n");
167169
if (kasan_arg_fault == KASAN_ARG_FAULT_PANIC)
168170
panic("kasan.fault=panic set ...\n");
171+
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
172+
lockdep_on();
169173
kasan_enable_current();
170174
}
171175

0 commit comments

Comments
 (0)