linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kasan: make report_lock a raw spinlock
@ 2024-11-19 21:02 Jared Kangas
  2024-11-22  6:28 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Jared Kangas @ 2024-11-19 21:02 UTC (permalink / raw)
  To: ryabinin.a.a
  Cc: glider, andreyknvl, dvyukov, vincenzo.frascino, akpm, kasan-dev,
	linux-mm, linux-kernel, Jared Kangas

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.

Signed-off-by: Jared Kangas <jkangas@redhat.com>
---
 mm/kasan/report.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index b48c768acc84..c7c0083203cb 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -200,7 +200,7 @@ static inline void fail_non_kasan_kunit_test(void) { }
 
 #endif /* CONFIG_KUNIT */
 
-static DEFINE_SPINLOCK(report_lock);
+static DEFINE_RAW_SPINLOCK(report_lock);
 
 static void start_report(unsigned long *flags, bool sync)
 {
@@ -211,7 +211,7 @@ static void start_report(unsigned long *flags, bool sync)
 	lockdep_off();
 	/* Make sure we don't end up in loop. */
 	report_suppress_start();
-	spin_lock_irqsave(&report_lock, *flags);
+	raw_spin_lock_irqsave(&report_lock, *flags);
 	pr_err("==================================================================\n");
 }
 
@@ -221,7 +221,7 @@ static void end_report(unsigned long *flags, const void *addr, bool is_write)
 		trace_error_report_end(ERROR_DETECTOR_KASAN,
 				       (unsigned long)addr);
 	pr_err("==================================================================\n");
-	spin_unlock_irqrestore(&report_lock, *flags);
+	raw_spin_unlock_irqrestore(&report_lock, *flags);
 	if (!test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags))
 		check_panic_on_warn("KASAN");
 	switch (kasan_arg_fault) {
-- 
2.47.0



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

* Re: [PATCH] kasan: make report_lock a raw spinlock
  2024-11-19 21:02 [PATCH] kasan: make report_lock a raw spinlock Jared Kangas
@ 2024-11-22  6:28 ` Andrew Morton
  2024-11-22 18:03   ` Jared Kangas
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2024-11-22  6:28 UTC (permalink / raw)
  To: Jared Kangas
  Cc: ryabinin.a.a, glider, andreyknvl, dvyukov, vincenzo.frascino,
	kasan-dev, linux-mm, linux-kernel

On Tue, 19 Nov 2024 13:02:34 -0800 Jared Kangas <jkangas@redhat.com> wrote:

> 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.

So I assume we want this backported into 6.12.x?

If so, please help us identify a suitable Fixes: commit.




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

* Re: [PATCH] kasan: make report_lock a raw spinlock
  2024-11-22  6:28 ` Andrew Morton
@ 2024-11-22 18:03   ` Jared Kangas
  0 siblings, 0 replies; 3+ messages in thread
From: Jared Kangas @ 2024-11-22 18:03 UTC (permalink / raw)
  To: Andrew Morton
  Cc: ryabinin.a.a, glider, andreyknvl, dvyukov, vincenzo.frascino,
	kasan-dev, linux-mm, linux-kernel

On Thu, Nov 21, 2024 at 10:28:09PM -0800, Andrew Morton wrote:
> On Tue, 19 Nov 2024 13:02:34 -0800 Jared Kangas <jkangas@redhat.com> wrote:
> 
> > 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.
> 
> So I assume we want this backported into 6.12.x?

Sorry for missing that; I think a backport of the patch would be
appropriate.

> If so, please help us identify a suitable Fixes: commit.

Fixes: 342a93247e08 ("locking/spinlock: Provide RT variant header: <linux/spinlock_rt.h>")



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

end of thread, other threads:[~2024-11-22 18:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-19 21:02 [PATCH] kasan: make report_lock a raw spinlock Jared Kangas
2024-11-22  6:28 ` Andrew Morton
2024-11-22 18:03   ` Jared Kangas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox