2021-03-31 06:35:40

by Zhang, Qiang

[permalink] [raw]
Subject: [PATCH] irq_work: record irq_work_queue() call stack

From: Zqiang <[email protected]>

Add the irq_work_queue() call stack into the KASAN auxiliary
stack in order to improve KASAN reports. this will let us know
where the irq work be queued.

Signed-off-by: Zqiang <[email protected]>
---
kernel/irq_work.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/irq_work.c b/kernel/irq_work.c
index e8da1e71583a..23a7a0ba1388 100644
--- a/kernel/irq_work.c
+++ b/kernel/irq_work.c
@@ -19,7 +19,7 @@
#include <linux/notifier.h>
#include <linux/smp.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);
@@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
if (!irq_work_claim(work))
return false;

+ /*record irq_work call stack in order to print it in KASAN reports*/
+ kasan_record_aux_stack(work);
+
/* Queue the entry and raise the IPI if needed. */
preempt_disable();
__irq_work_queue_local(work);
@@ -98,6 +101,8 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
if (!irq_work_claim(work))
return false;

+ kasan_record_aux_stack(work);
+
preempt_disable();
if (cpu != smp_processor_id()) {
/* Arch remote IPI send/receive backend aren't NMI safe */
--
2.17.1


2021-03-31 10:04:00

by Dmitry Vyukov

[permalink] [raw]
Subject: Re: [PATCH] irq_work: record irq_work_queue() call stack

On Wed, Mar 31, 2021 at 8:32 AM <[email protected]> wrote:
>
> From: Zqiang <[email protected]>
>
> Add the irq_work_queue() call stack into the KASAN auxiliary
> stack in order to improve KASAN reports. this will let us know
> where the irq work be queued.
>
> Signed-off-by: Zqiang <[email protected]>

Reviewed-by: Dmitry Vyukov <[email protected]>

> ---
> kernel/irq_work.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> index e8da1e71583a..23a7a0ba1388 100644
> --- a/kernel/irq_work.c
> +++ b/kernel/irq_work.c
> @@ -19,7 +19,7 @@
> #include <linux/notifier.h>
> #include <linux/smp.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);
> @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
> if (!irq_work_claim(work))
> return false;
>
> + /*record irq_work call stack in order to print it in KASAN reports*/
> + kasan_record_aux_stack(work);
> +
> /* Queue the entry and raise the IPI if needed. */
> preempt_disable();
> __irq_work_queue_local(work);
> @@ -98,6 +101,8 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
> if (!irq_work_claim(work))
> return false;
>
> + kasan_record_aux_stack(work);
> +
> preempt_disable();
> if (cpu != smp_processor_id()) {
> /* Arch remote IPI send/receive backend aren't NMI safe */
> --
> 2.17.1
>

2021-04-02 14:54:40

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH] irq_work: record irq_work_queue() call stack

On Wed, Mar 31, 2021 at 8:32 AM <[email protected]> wrote:
>
> From: Zqiang <[email protected]>
>
> Add the irq_work_queue() call stack into the KASAN auxiliary
> stack in order to improve KASAN reports. this will let us know
> where the irq work be queued.
>
> Signed-off-by: Zqiang <[email protected]>
> ---
> kernel/irq_work.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq_work.c b/kernel/irq_work.c
> index e8da1e71583a..23a7a0ba1388 100644
> --- a/kernel/irq_work.c
> +++ b/kernel/irq_work.c
> @@ -19,7 +19,7 @@
> #include <linux/notifier.h>
> #include <linux/smp.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);
> @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
> if (!irq_work_claim(work))
> return false;
>
> + /*record irq_work call stack in order to print it in KASAN reports*/
> + kasan_record_aux_stack(work);
> +
> /* Queue the entry and raise the IPI if needed. */
> preempt_disable();
> __irq_work_queue_local(work);
> @@ -98,6 +101,8 @@ bool irq_work_queue_on(struct irq_work *work, int cpu)
> if (!irq_work_claim(work))
> return false;
>
> + kasan_record_aux_stack(work);
> +
> preempt_disable();
> if (cpu != smp_processor_id()) {
> /* Arch remote IPI send/receive backend aren't NMI safe */
> --
> 2.17.1

Acked-by: Andrey Konovalov <[email protected]>

2021-06-09 06:43:39

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH] irq_work: record irq_work_queue() call stack

On Wed, Mar 31, 2021 at 02:32:02PM +0800, [email protected] wrote:

> @@ -70,6 +70,9 @@ bool irq_work_queue(struct irq_work *work)
> if (!irq_work_claim(work))
> return false;
>
> + /*record irq_work call stack in order to print it in KASAN reports*/
> + kasan_record_aux_stack(work);
> +
> /* Queue the entry and raise the IPI if needed. */
> preempt_disable();
> __irq_work_queue_local(work);

Thanks for the Cc :/ Also NAK.

I shall go revert this instantly. KASAN is not NMI safe, while
irq_work_queue() is very carefully crafted to be exactly that.