Skip to content

Commit e30a036

Browse files
rh-jkangasakpm00
authored andcommitted
kasan: make report_lock a raw spinlock
If PREEMPT_RT is enabled, report_lock is a sleeping spinlock and must not be locked when IRQs are disabled. However, KASAN reports may be triggered in such contexts. For example: char *s = kzalloc(1, GFP_KERNEL); kfree(s); local_irq_disable(); char c = *s; /* KASAN report here leads to spin_lock() */ local_irq_enable(); Make report_spinlock a raw spinlock to prevent rescheduling when PREEMPT_RT is enabled. Link: https://lkml.kernel.org/r/[email protected] Fixes: 342a932 ("locking/spinlock: Provide RT variant header: <linux/spinlock_rt.h>") Signed-off-by: Jared Kangas <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Andrey Ryabinin <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Vincenzo Frascino <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 091c1dd commit e30a036

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/kasan/report.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static inline void fail_non_kasan_kunit_test(void) { }
201201

202202
#endif /* CONFIG_KUNIT */
203203

204-
static DEFINE_SPINLOCK(report_lock);
204+
static DEFINE_RAW_SPINLOCK(report_lock);
205205

206206
static void start_report(unsigned long *flags, bool sync)
207207
{
@@ -212,7 +212,7 @@ static void start_report(unsigned long *flags, bool sync)
212212
lockdep_off();
213213
/* Make sure we don't end up in loop. */
214214
report_suppress_start();
215-
spin_lock_irqsave(&report_lock, *flags);
215+
raw_spin_lock_irqsave(&report_lock, *flags);
216216
pr_err("==================================================================\n");
217217
}
218218

@@ -222,7 +222,7 @@ static void end_report(unsigned long *flags, const void *addr, bool is_write)
222222
trace_error_report_end(ERROR_DETECTOR_KASAN,
223223
(unsigned long)addr);
224224
pr_err("==================================================================\n");
225-
spin_unlock_irqrestore(&report_lock, *flags);
225+
raw_spin_unlock_irqrestore(&report_lock, *flags);
226226
if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
227227
check_panic_on_warn("KASAN");
228228
switch (kasan_arg_fault) {

0 commit comments

Comments
 (0)