Skip to contentSkip to conversation

kasan: support panic_on_warn

PATCH In review Dmitry Vyukov 2 participants 5 messages Oct 14, 2016 – Oct 17, 2016

Subsystems (2)
lore
Share & tools
lore

Dmitry Vyukov

author reviewer
#0 lore raw

PATCH 1/1 kasan: support panic_on_warn

If user sets panic_on_warn, he wants kernel to panic if there is anything barely wrong with the kernel. KASAN-detected errors are definitely not less benign than an arbitrary kernel WARNING.

Panic after KASAN errors if panic_on_warn is set.

We use this for continuous fuzzing where we want kernel to stop and reboot on any error.

---
 mm/kasan/report.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/kasan/report.c +4 -0
index 24c1211..ca0bd48 100644
@@ -133,6 +133,10 @@ static void kasan_end_report(unsigned long *flags)
 	pr_err("==================================================================\n");
 	add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
 	spin_unlock_irqrestore(&report_lock, *flags);
+	if (panic_on_warn) {
+		panic_on_warn = 0;
+		panic("panic_on_warn set ...\n");
+	}
 	kasan_enable_current();
 }
 
Signature · 7 lines
2.8.0.rc3.226.g39d4020

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 25 lines · Dmitry Vyukov

If user sets panic_on_warn, he wants kernel to panic if there is anything barely wrong with the kernel. KASAN-detected errors are definitely not less benign than an arbitrary kernel WARNING.

Panic after KASAN errors if panic_on_warn is set.

We use this for continuous fuzzing where we want kernel to stop and reboot on any error.

---
 mm/kasan/report.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/kasan/report.c +0 -0
index 24c1211..ca0bd48 100644

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 137

Quoted 5 lines
mm/kasan/report.c +2 -0
@@ -133,6 +133,10 @@ static void kasan_end_report(unsigned long *flags)
 	pr_err("==================================================================\n");
 	add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
 	spin_unlock_irqrestore(&report_lock, *flags);
+	if (panic_on_warn) {
+		panic_on_warn = 0;

Why we need to reset panic_on_warn?
I assume this was copied from __warn(). AFAIU in __warn() this protects from recursion:
__warn() -> painc() ->__warn() -> panic() -> ...
which is possible if WARN_ON() triggered in panic().
But KASAN is protected from such recursion via kasan_disable_current().

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 142

Quoted 6 lines
mm/kasan/report.c +2 -0
+		panic("panic_on_warn set ...\n");
+	}
 	kasan_enable_current();
 }
 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author reviewer
#2 lore raw
Quoted 23 lines · Andrey Ryabinin
Quoted 20 lines · Dmitry Vyukov

If user sets panic_on_warn, he wants kernel to panic if there is anything barely wrong with the kernel. KASAN-detected errors are definitely not less benign than an arbitrary kernel WARNING.

Panic after KASAN errors if panic_on_warn is set.

We use this for continuous fuzzing where we want kernel to stop and reboot on any error.

---
 mm/kasan/report.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 16 lines

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 137

Quoted 10 lines
mm/kasan/report.c +2 -0
index 24c1211..ca0bd48 100644
@@ -133,6 +133,10 @@ static void kasan_end_report(unsigned long *flags)
      pr_err("==================================================================\n");
      add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
      spin_unlock_irqrestore(&report_lock, *flags);
+     if (panic_on_warn) {
+             panic_on_warn = 0;

Why we need to reset panic_on_warn?
I assume this was copied from __warn(). AFAIU in __warn() this protects from recursion:
__warn() -> painc() ->__warn() -> panic() -> ...
which is possible if WARN_ON() triggered in panic().
But KASAN is protected from such recursion via kasan_disable_current().

But we have recursion into panic via kasan->panic->warning->panic. Am I missing something?

Quoted 4 lines

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 141

Quoted 4 lines
mm/kasan/report.c +2 -0
+             panic("panic_on_warn set ...\n");
+     }
      kasan_enable_current();
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 42 lines · Dmitry Vyukov
Quoted 23 lines · Andrey Ryabinin
Quoted 20 lines · Dmitry Vyukov

If user sets panic_on_warn, he wants kernel to panic if there is anything barely wrong with the kernel. KASAN-detected errors are definitely not less benign than an arbitrary kernel WARNING.

Panic after KASAN errors if panic_on_warn is set.

We use this for continuous fuzzing where we want kernel to stop and reboot on any error.

---
 mm/kasan/report.c | 4 ++++
 1 file changed, 4 insertions(+)
Quoted 16 lines

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 137

Quoted 10 lines
mm/kasan/report.c +2 -0
index 24c1211..ca0bd48 100644
@@ -133,6 +133,10 @@ static void kasan_end_report(unsigned long *flags)
      pr_err("==================================================================\n");
      add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
      spin_unlock_irqrestore(&report_lock, *flags);
+     if (panic_on_warn) {
+             panic_on_warn = 0;

Why we need to reset panic_on_warn?
I assume this was copied from __warn(). AFAIU in __warn() this protects from recursion:
__warn() -> painc() ->__warn() -> panic() -> ...
which is possible if WARN_ON() triggered in panic().
But KASAN is protected from such recursion via kasan_disable_current().

Quoted 1 line

But we have recursion into panic via kasan->panic->warning->panic.

We do, like almost every other panic() call in the kernel. But at least it's finite.
So, if finite recursion is a problem for panic() it should be fixed in panic(), rather then on every panic() call site.

Quoted 5 lines
Quoted 5 lines

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 141

Quoted 5 lines
mm/kasan/report.c +2 -0
+             panic("panic_on_warn set ...\n");
+     }
      kasan_enable_current();
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author reviewer
#4 lore raw
Quoted 45 lines · Andrey Ryabinin
Quoted 42 lines · Dmitry Vyukov
Quoted 39 lines · Andrey Ryabinin
Quoted 25 lines · Dmitry Vyukov

If user sets panic_on_warn, he wants kernel to panic if there is anything barely wrong with the kernel. KASAN-detected errors are definitely not less benign than an arbitrary kernel WARNING.

Panic after KASAN errors if panic_on_warn is set.

We use this for continuous fuzzing where we want kernel to stop and reboot on any error.

---
 mm/kasan/report.c | 4 ++++
 1 file changed, 4 insertions(+)
mm/kasan/report.c +0 -0
index 24c1211..ca0bd48 100644

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 137

Quoted 5 lines
mm/kasan/report.c +2 -0
@@ -133,6 +133,10 @@ static void kasan_end_report(unsigned long *flags)
      pr_err("==================================================================\n");
      add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
      spin_unlock_irqrestore(&report_lock, *flags);
+     if (panic_on_warn) {
+             panic_on_warn = 0;

Why we need to reset panic_on_warn?
I assume this was copied from __warn(). AFAIU in __warn() this protects from recursion:
__warn() -> painc() ->__warn() -> panic() -> ...
which is possible if WARN_ON() triggered in panic().
But KASAN is protected from such recursion via kasan_disable_current().

Quoted 4 lines
Quoted 1 line

But we have recursion into panic via kasan->panic->warning->panic.

We do, like almost every other panic() call in the kernel. But at least it's finite.
So, if finite recursion is a problem for panic() it should be fixed in panic(), rather then on every panic() call site.

I misunderstood the comment in warning code:

502 /*
503 * This thread may hit another WARN() in the panic path.
504 * Resetting this prevents additional WARN() from
panicking the

505                  * system on this thread.  Other threads are blocked by the
506                  * panic_mutex in panic().
507                  */

I interpreted it as recursion into panic will cause a deadlock due to recursive mutex acquisition.

But the mutex is a custom CAS that supports recursion on the same CPU.

136 this_cpu = raw_smp_processor_id();
137 old_cpu = atomic_cmpxchg(&panic_cpu, PANIC_CPU_INVALID, this_cpu);
138
139 if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
140 panic_smp_self_stop();

Mailed v2.

Thanks!

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

mm/kasan/report.c static void kasan_end_report(unsigned long *flags) · line 141

Quoted 5 lines
mm/kasan/report.c +2 -0
+             panic("panic_on_warn set ...\n");
+     }
      kasan_enable_current();
 }

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>