Skip to contentSkip to conversation

irq_work: Make irq_work_queue_on() NMI-safe again

PATCH In review Jun Miao 2 participants 4 messages Apr 26, 2022 – Apr 27, 2022

lore
Share & tools
lore

Jun Miao

author
#0 lore raw

PATCH 1/1 irq_work: Make irq_work_queue_on() NMI-safe again

We should not put NMI unsafe code in irq_work_queue_on().

The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which will call the spinlock. While the irq_work_queue_on() is also very carefully carafted to be exactly that.
When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to irq_work_queue(). So delete KASAN instantly.

Fixes e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")

Suggested by: "Huang, Ying" <[email protected]>

---
 kernel/irq_work.c | 3 ---
 1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -3
index 7afa40fe5cc4..e7f48aa8d8af 100644
@@ -20,7 +20,6 @@
 #include <linux/smp.h>
 #include <linux/smpboot.h>
 #include <asm/processor.h>
-#include <linux/kasan.h>
 
 static DEFINE_PER_CPU(struct llist_head, raised_list);
 static DEFINE_PER_CPU(struct llist_head, lazy_list);
@@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
 	if (!irq_work_claim(work))
 		return false;
 
-	kasan_record_aux_stack_noalloc(work);
-
 	preempt_disable();
 	if (cpu != smp_processor_id()) {
 		/* Arch remote IPI send/receive backend aren't NMI safe */
Signature · 1 line
2.32.0
author
#1 lore raw

Add  To/Cc : KASAN/MEM , since I only used the scripts/get_maintainer.pl to irq_work.c file.

Thanks
Jun Miao

Quoted 36 lines · Jun Miao

We should not put NMI unsafe code in irq_work_queue_on().

The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which will call the spinlock. While the irq_work_queue_on() is also very carefully carafted to be exactly that.
When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to irq_work_queue(). So delete KASAN instantly.

Fixes e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")

Suggested by: "Huang, Ying" <[email protected]>

---
  kernel/irq_work.c | 3 ---
  1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -3
index 7afa40fe5cc4..e7f48aa8d8af 100644
@@ -20,7 +20,6 @@
  #include <linux/smp.h>
  #include <linux/smpboot.h>
  #include <asm/processor.h>
-#include <linux/kasan.h>
 
  static DEFINE_PER_CPU(struct llist_head, raised_list);
  static DEFINE_PER_CPU(struct llist_head, lazy_list);
@@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
  	if (!irq_work_claim(work))
  		return false;
 
-	kasan_record_aux_stack_noalloc(work);
-
  	preempt_disable();
  	if (cpu != smp_processor_id()) {
  		/* Arch remote IPI send/receive backend aren't NMI safe */
Acked-by
#2 lore raw
Quoted 14 lines · Jun Miao

Add To/Cc : KASAN/MEM , since I only used the scripts/get_maintainer.pl to irq_work.c file.

Thanks
Jun Miao

Quoted 5 lines · Jun Miao

We should not put NMI unsafe code in irq_work_queue_on().

The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which will call the spinlock. While the irq_work_queue_on() is also very carefully carafted to be exactly that.

"crafted"

Quoted 1 line
Quoted 1 line

When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to

CONFIG_SM -> CONFIG_SMP

Quoted 5 lines
Quoted 5 lines

irq_work_queue(). So delete KASAN instantly.

Fixes e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")

Suggested by: "Huang, Ying" <[email protected]>

I thought this had already been removed, but apparently there were 2
places: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=156172a13ff0626d8e23276e741c7e2cb2f3b572

Quoted 30 lines
Quoted 17 lines
---
  kernel/irq_work.c | 3 ---
  1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -1
index 7afa40fe5cc4..e7f48aa8d8af 100644
@@ -20,7 +20,6 @@
  #include <linux/smp.h>
  #include <linux/smpboot.h>
  #include <asm/processor.h>
-#include <linux/kasan.h>
 
  static DEFINE_PER_CPU(struct llist_head, raised_list);
  static DEFINE_PER_CPU(struct llist_head, lazy_list);

kernel/irq_work.c bool irq_work_queue_on(struct irq_work *work, int cpu) · line 141

Quoted 8 lines
kernel/irq_work.c +0 -2
@@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
      if (!irq_work_claim(work))
              return false;
 
-     kasan_record_aux_stack_noalloc(work);
-
      preempt_disable();
      if (cpu != smp_processor_id()) {
              /* Arch remote IPI send/receive backend aren't NMI safe */

--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/9c951fe6-d354-5870-e91b-83d8346ac162%40intel.com.

author
#3 lore raw
Quoted 21 lines · Marco Elver
Quoted 13 lines · Jun Miao

Add To/Cc : KASAN/MEM , since I only used the scripts/get_maintainer.pl to irq_work.c file.

Thanks
Jun Miao

Quoted 5 lines · Jun Miao

We should not put NMI unsafe code in irq_work_queue_on().

The KASAN of kasan_record_aux_stack_noalloc() is not NMI safe. Because which will call the spinlock. While the irq_work_queue_on() is also very carefully carafted to be exactly that.

"crafted"

Quoted 1 line
Quoted 1 line

When unable CONFIG_SM or local CPU, the irq_work_queue_on() is even same to

CONFIG_SM -> CONFIG_SMP

Quoted 2 lines
Quoted 2 lines

irq_work_queue(). So delete KASAN instantly.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Fixes e2b5bcf9f5ba ("irq_work: record irq_work_queue() call stack")

Suggested by: "Huang, Ying" <[email protected]>

I thought this had already been removed, but apparently there were 2
places: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=156172a13ff0626d8e23276e741c7e2cb2f3b572

Sure, I also found this patch which is the same reason, maybe Peter Z forgot it. Let me make up a little.😉

Send V2 later.

Thanks
Jun Miao

Quoted 29 lines
Quoted 29 lines
Quoted 17 lines
---
   kernel/irq_work.c | 3 ---
   1 file changed, 3 deletions(-)
kernel/irq_work.c +0 -1
index 7afa40fe5cc4..e7f48aa8d8af 100644
@@ -20,7 +20,6 @@
   #include <linux/smp.h>
   #include <linux/smpboot.h>
   #include <asm/processor.h>
-#include <linux/kasan.h>
 
   static DEFINE_PER_CPU(struct llist_head, raised_list);
   static DEFINE_PER_CPU(struct llist_head, lazy_list);

kernel/irq_work.c bool irq_work_queue_on(struct irq_work *work, int cpu) · line 141

Quoted 8 lines
kernel/irq_work.c +0 -2
@@ -137,8 +136,6 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
       if (!irq_work_claim(work))
               return false;
 
-     kasan_record_aux_stack_noalloc(work);
-
       preempt_disable();
       if (cpu != smp_processor_id()) {
               /* Arch remote IPI send/receive backend aren't NMI safe */

--
You received this message because you are subscribed to the Google Groups "kasan-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/9c951fe6-d354-5870-e91b-83d8346ac162%40intel.com.