[Devel] [PATCH 4/4] kasan: introduce single-shot mode and enable it by default

Andrey Ryabinin aryabinin at odin.com
Fri Sep 4 07:06:16 PDT 2015


The first error is always the most significant. The following
errors usually are the consequences of the first or duplicates.

This introduces single-shot mode, which means that we will print
only the first error. It's enabled by default, but user
still can switch to the old behavior via 'kasan_print_till_death'
boot option.

https://jira.sw.ru/browse/PSBM-39339

Signed-off-by: Andrey Ryabinin <aryabinin at odin.com>
---
 mm/kasan/report.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 17af572..515ab38 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -216,14 +216,28 @@ static void kasan_report_error(struct kasan_access_info *info)
 	spin_unlock_irqrestore(&report_lock, flags);
 }
 
+static bool print_till_death;
+static int __init kasan_setup(char *arg)
+{
+	print_till_death = true;
+	return 0;
+}
+__setup("kasan_print_till_death", kasan_setup);
+
 void kasan_report(unsigned long addr, size_t size,
 		bool is_write, unsigned long ip)
 {
 	struct kasan_access_info info;
+	static bool reported = false;
 
 	if (likely(!kasan_enabled()))
 		return;
 
+	if (likely(!print_till_death)) {
+		if (reported)
+			return;
+		reported = true;
+	}
 	info.access_addr = (void *)addr;
 	info.access_size = size;
 	info.is_write = is_write;
-- 
2.4.6




More information about the Devel mailing list