linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] kasan: consistently disable debugging features
@ 2020-05-12 15:33 Andrey Konovalov
  2020-05-12 15:33 ` [PATCH 2/3] kasan: move kasan_report() into report.c Andrey Konovalov
  2020-05-12 15:33 ` [PATCH 3/3] kasan: add missing functions declarations to kasan.h Andrey Konovalov
  0 siblings, 2 replies; 11+ messages in thread
From: Andrey Konovalov @ 2020-05-12 15:33 UTC (permalink / raw)
  To: Andrew Morton, Andrey Ryabinin
  Cc: Alexander Potapenko, Dmitry Vyukov, kasan-dev, linux-mm,
	linux-kernel, Leon Romanovsky, Andrey Konovalov

KASAN is incompatible with some kernel debugging/tracing features.
There's been multiple patches that disable those feature for some of
KASAN files one by one. Instead of prolonging that, disable these
features for all KASAN files at once.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 mm/kasan/Makefile | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile
index 08b43de2383b..434d503a6525 100644
--- a/mm/kasan/Makefile
+++ b/mm/kasan/Makefile
@@ -1,23 +1,28 @@
 # SPDX-License-Identifier: GPL-2.0
 KASAN_SANITIZE := n
-UBSAN_SANITIZE_common.o := n
-UBSAN_SANITIZE_generic.o := n
-UBSAN_SANITIZE_generic_report.o := n
-UBSAN_SANITIZE_tags.o := n
+UBSAN_SANITIZE := n
 KCOV_INSTRUMENT := n
 
+# Disable ftrace to avoid recursion.
 CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE)
+CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE)
 
 # Function splitter causes unnecessary splits in __asan_load1/__asan_store1
 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533
-
 CFLAGS_common.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
 CFLAGS_generic.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
 CFLAGS_generic_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
+CFLAGS_init.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
+CFLAGS_quarantine.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
+CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
 CFLAGS_tags.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
+CFLAGS_tags_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
 
 obj-$(CONFIG_KASAN) := common.o init.o report.o
 obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.o
-- 
2.26.2.645.ge9eca65c58-goog


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

* [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-12 15:33 [PATCH 1/3] kasan: consistently disable debugging features Andrey Konovalov
@ 2020-05-12 15:33 ` Andrey Konovalov
  2020-05-12 16:42   ` Leon Romanovsky
  2020-05-28 13:49   ` Qian Cai
  2020-05-12 15:33 ` [PATCH 3/3] kasan: add missing functions declarations to kasan.h Andrey Konovalov
  1 sibling, 2 replies; 11+ messages in thread
From: Andrey Konovalov @ 2020-05-12 15:33 UTC (permalink / raw)
  To: Andrew Morton, Andrey Ryabinin
  Cc: Alexander Potapenko, Dmitry Vyukov, kasan-dev, linux-mm,
	linux-kernel, Leon Romanovsky, Andrey Konovalov, Leon Romanovsky

The kasan_report() functions belongs to report.c, as it's a common
functions that does error reporting.

Reported-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 mm/kasan/common.c | 19 -------------------
 mm/kasan/report.c | 22 ++++++++++++++++++++--
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index 2906358e42f0..757d4074fe28 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -33,7 +33,6 @@
 #include <linux/types.h>
 #include <linux/vmalloc.h>
 #include <linux/bug.h>
-#include <linux/uaccess.h>
 
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
@@ -613,24 +612,6 @@ void kasan_free_shadow(const struct vm_struct *vm)
 }
 #endif
 
-extern void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip);
-extern bool report_enabled(void);
-
-bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip)
-{
-	unsigned long flags = user_access_save();
-	bool ret = false;
-
-	if (likely(report_enabled())) {
-		__kasan_report(addr, size, is_write, ip);
-		ret = true;
-	}
-
-	user_access_restore(flags);
-
-	return ret;
-}
-
 #ifdef CONFIG_MEMORY_HOTPLUG
 static bool shadow_mapped(unsigned long addr)
 {
diff --git a/mm/kasan/report.c b/mm/kasan/report.c
index 80f23c9da6b0..51ec45407a0b 100644
--- a/mm/kasan/report.c
+++ b/mm/kasan/report.c
@@ -29,6 +29,7 @@
 #include <linux/kasan.h>
 #include <linux/module.h>
 #include <linux/sched/task_stack.h>
+#include <linux/uaccess.h>
 
 #include <asm/sections.h>
 
@@ -454,7 +455,7 @@ static void print_shadow_for_address(const void *addr)
 	}
 }
 
-bool report_enabled(void)
+static bool report_enabled(void)
 {
 	if (current->kasan_depth)
 		return false;
@@ -479,7 +480,8 @@ void kasan_report_invalid_free(void *object, unsigned long ip)
 	end_report(&flags);
 }
 
-void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip)
+static void __kasan_report(unsigned long addr, size_t size, bool is_write,
+				unsigned long ip)
 {
 	struct kasan_access_info info;
 	void *tagged_addr;
@@ -518,6 +520,22 @@ void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned lon
 	end_report(&flags);
 }
 
+bool kasan_report(unsigned long addr, size_t size, bool is_write,
+			unsigned long ip)
+{
+	unsigned long flags = user_access_save();
+	bool ret = false;
+
+	if (likely(report_enabled())) {
+		__kasan_report(addr, size, is_write, ip);
+		ret = true;
+	}
+
+	user_access_restore(flags);
+
+	return ret;
+}
+
 #ifdef CONFIG_KASAN_INLINE
 /*
  * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
-- 
2.26.2.645.ge9eca65c58-goog


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

* [PATCH 3/3] kasan: add missing functions declarations to kasan.h
  2020-05-12 15:33 [PATCH 1/3] kasan: consistently disable debugging features Andrey Konovalov
  2020-05-12 15:33 ` [PATCH 2/3] kasan: move kasan_report() into report.c Andrey Konovalov
@ 2020-05-12 15:33 ` Andrey Konovalov
  2020-05-12 16:41   ` Leon Romanovsky
  1 sibling, 1 reply; 11+ messages in thread
From: Andrey Konovalov @ 2020-05-12 15:33 UTC (permalink / raw)
  To: Andrew Morton, Andrey Ryabinin
  Cc: Alexander Potapenko, Dmitry Vyukov, kasan-dev, linux-mm,
	linux-kernel, Leon Romanovsky, Andrey Konovalov, Leon Romanovsky

KASAN is currently missing declarations for __asan_report* and
__hwasan* functions. This can lead to compiler warnings.

Reported-by: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 mm/kasan/kasan.h | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index e8f37199d885..cfade6413528 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -212,8 +212,6 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
 asmlinkage void kasan_unpoison_task_stack_below(const void *watermark);
 void __asan_register_globals(struct kasan_global *globals, size_t size);
 void __asan_unregister_globals(struct kasan_global *globals, size_t size);
-void __asan_loadN(unsigned long addr, size_t size);
-void __asan_storeN(unsigned long addr, size_t size);
 void __asan_handle_no_return(void);
 void __asan_alloca_poison(unsigned long addr, size_t size);
 void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom);
@@ -228,6 +226,8 @@ void __asan_load8(unsigned long addr);
 void __asan_store8(unsigned long addr);
 void __asan_load16(unsigned long addr);
 void __asan_store16(unsigned long addr);
+void __asan_loadN(unsigned long addr, size_t size);
+void __asan_storeN(unsigned long addr, size_t size);
 
 void __asan_load1_noabort(unsigned long addr);
 void __asan_store1_noabort(unsigned long addr);
@@ -239,6 +239,21 @@ void __asan_load8_noabort(unsigned long addr);
 void __asan_store8_noabort(unsigned long addr);
 void __asan_load16_noabort(unsigned long addr);
 void __asan_store16_noabort(unsigned long addr);
+void __asan_loadN_noabort(unsigned long addr, size_t size);
+void __asan_storeN_noabort(unsigned long addr, size_t size);
+
+void __asan_report_load1_noabort(unsigned long addr);
+void __asan_report_store1_noabort(unsigned long addr);
+void __asan_report_load2_noabort(unsigned long addr);
+void __asan_report_store2_noabort(unsigned long addr);
+void __asan_report_load4_noabort(unsigned long addr);
+void __asan_report_store4_noabort(unsigned long addr);
+void __asan_report_load8_noabort(unsigned long addr);
+void __asan_report_store8_noabort(unsigned long addr);
+void __asan_report_load16_noabort(unsigned long addr);
+void __asan_report_store16_noabort(unsigned long addr);
+void __asan_report_load_n_noabort(unsigned long addr, size_t size);
+void __asan_report_store_n_noabort(unsigned long addr, size_t size);
 
 void __asan_set_shadow_00(const void *addr, size_t size);
 void __asan_set_shadow_f1(const void *addr, size_t size);
@@ -247,4 +262,19 @@ void __asan_set_shadow_f3(const void *addr, size_t size);
 void __asan_set_shadow_f5(const void *addr, size_t size);
 void __asan_set_shadow_f8(const void *addr, size_t size);
 
+void __hwasan_load1_noabort(unsigned long addr);
+void __hwasan_store1_noabort(unsigned long addr);
+void __hwasan_load2_noabort(unsigned long addr);
+void __hwasan_store2_noabort(unsigned long addr);
+void __hwasan_load4_noabort(unsigned long addr);
+void __hwasan_store4_noabort(unsigned long addr);
+void __hwasan_load8_noabort(unsigned long addr);
+void __hwasan_store8_noabort(unsigned long addr);
+void __hwasan_load16_noabort(unsigned long addr);
+void __hwasan_store16_noabort(unsigned long addr);
+void __hwasan_loadN_noabort(unsigned long addr, size_t size);
+void __hwasan_storeN_noabort(unsigned long addr, size_t size);
+
+void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size);
+
 #endif
-- 
2.26.2.645.ge9eca65c58-goog


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

* Re: [PATCH 3/3] kasan: add missing functions declarations to kasan.h
  2020-05-12 15:33 ` [PATCH 3/3] kasan: add missing functions declarations to kasan.h Andrey Konovalov
@ 2020-05-12 16:41   ` Leon Romanovsky
  0 siblings, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2020-05-12 16:41 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, linux-mm, linux-kernel

On Tue, May 12, 2020 at 05:33:21PM +0200, Andrey Konovalov wrote:
> KASAN is currently missing declarations for __asan_report* and
> __hwasan* functions. This can lead to compiler warnings.
>
> Reported-by: Leon Romanovsky <leon@kernel.org>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  mm/kasan/kasan.h | 34 ++++++++++++++++++++++++++++++++--
>  1 file changed, 32 insertions(+), 2 deletions(-)
>

Thanks,
Tested-by: Leon Romanovsky <leon@kernel.org>

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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-12 15:33 ` [PATCH 2/3] kasan: move kasan_report() into report.c Andrey Konovalov
@ 2020-05-12 16:42   ` Leon Romanovsky
  2020-05-28 13:49   ` Qian Cai
  1 sibling, 0 replies; 11+ messages in thread
From: Leon Romanovsky @ 2020-05-12 16:42 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, linux-mm, linux-kernel

On Tue, May 12, 2020 at 05:33:20PM +0200, Andrey Konovalov wrote:
> The kasan_report() functions belongs to report.c, as it's a common
> functions that does error reporting.
>
> Reported-by: Leon Romanovsky <leon@kernel.org>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  mm/kasan/common.c | 19 -------------------
>  mm/kasan/report.c | 22 ++++++++++++++++++++--
>  2 files changed, 20 insertions(+), 21 deletions(-)
>

Thanks,
Tested-by: Leon Romanovsky <leon@kernel.org>

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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-12 15:33 ` [PATCH 2/3] kasan: move kasan_report() into report.c Andrey Konovalov
  2020-05-12 16:42   ` Leon Romanovsky
@ 2020-05-28 13:49   ` Qian Cai
  2020-05-28 14:33     ` Josh Poimboeuf
  2020-05-28 15:00     ` Andrey Konovalov
  1 sibling, 2 replies; 11+ messages in thread
From: Qian Cai @ 2020-05-28 13:49 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, linux-mm, linux-kernel,
	Leon Romanovsky, Leon Romanovsky, Randy Dunlap, Josh Poimboeuf

On Tue, May 12, 2020 at 05:33:20PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> The kasan_report() functions belongs to report.c, as it's a common
> functions that does error reporting.
> 
> Reported-by: Leon Romanovsky <leon@kernel.org>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Today's linux-next produced this with Clang 11.

mm/kasan/report.o: warning: objtool: kasan_report()+0x8a: call to __stack_chk_fail() with UACCESS enabled

kasan_report at mm/kasan/report.c:536

> ---
>  mm/kasan/common.c | 19 -------------------
>  mm/kasan/report.c | 22 ++++++++++++++++++++--
>  2 files changed, 20 insertions(+), 21 deletions(-)
> 
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index 2906358e42f0..757d4074fe28 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -33,7 +33,6 @@
>  #include <linux/types.h>
>  #include <linux/vmalloc.h>
>  #include <linux/bug.h>
> -#include <linux/uaccess.h>
>  
>  #include <asm/cacheflush.h>
>  #include <asm/tlbflush.h>
> @@ -613,24 +612,6 @@ void kasan_free_shadow(const struct vm_struct *vm)
>  }
>  #endif
>  
> -extern void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip);
> -extern bool report_enabled(void);
> -
> -bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip)
> -{
> -	unsigned long flags = user_access_save();
> -	bool ret = false;
> -
> -	if (likely(report_enabled())) {
> -		__kasan_report(addr, size, is_write, ip);
> -		ret = true;
> -	}
> -
> -	user_access_restore(flags);
> -
> -	return ret;
> -}
> -
>  #ifdef CONFIG_MEMORY_HOTPLUG
>  static bool shadow_mapped(unsigned long addr)
>  {
> diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> index 80f23c9da6b0..51ec45407a0b 100644
> --- a/mm/kasan/report.c
> +++ b/mm/kasan/report.c
> @@ -29,6 +29,7 @@
>  #include <linux/kasan.h>
>  #include <linux/module.h>
>  #include <linux/sched/task_stack.h>
> +#include <linux/uaccess.h>
>  
>  #include <asm/sections.h>
>  
> @@ -454,7 +455,7 @@ static void print_shadow_for_address(const void *addr)
>  	}
>  }
>  
> -bool report_enabled(void)
> +static bool report_enabled(void)
>  {
>  	if (current->kasan_depth)
>  		return false;
> @@ -479,7 +480,8 @@ void kasan_report_invalid_free(void *object, unsigned long ip)
>  	end_report(&flags);
>  }
>  
> -void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip)
> +static void __kasan_report(unsigned long addr, size_t size, bool is_write,
> +				unsigned long ip)
>  {
>  	struct kasan_access_info info;
>  	void *tagged_addr;
> @@ -518,6 +520,22 @@ void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned lon
>  	end_report(&flags);
>  }
>  
> +bool kasan_report(unsigned long addr, size_t size, bool is_write,
> +			unsigned long ip)
> +{
> +	unsigned long flags = user_access_save();
> +	bool ret = false;
> +
> +	if (likely(report_enabled())) {
> +		__kasan_report(addr, size, is_write, ip);
> +		ret = true;
> +	}
> +
> +	user_access_restore(flags);
> +
> +	return ret;
> +}
> +
>  #ifdef CONFIG_KASAN_INLINE
>  /*
>   * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
> -- 
> 2.26.2.645.ge9eca65c58-goog
> 
> -- 
> 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 kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/78a81fde6eeda9db72a7fd55fbc33173a515e4b1.1589297433.git.andreyknvl%40google.com.

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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-28 13:49   ` Qian Cai
@ 2020-05-28 14:33     ` Josh Poimboeuf
  2020-05-28 14:55       ` Peter Zijlstra
  2020-05-28 15:00     ` Andrey Konovalov
  1 sibling, 1 reply; 11+ messages in thread
From: Josh Poimboeuf @ 2020-05-28 14:33 UTC (permalink / raw)
  To: Qian Cai
  Cc: Andrey Konovalov, Andrew Morton, Andrey Ryabinin,
	Alexander Potapenko, Dmitry Vyukov, kasan-dev, linux-mm,
	linux-kernel, Leon Romanovsky, Leon Romanovsky, Randy Dunlap,
	Peter Zijlstra

On Thu, May 28, 2020 at 09:49:13AM -0400, Qian Cai wrote:
> On Tue, May 12, 2020 at 05:33:20PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> > The kasan_report() functions belongs to report.c, as it's a common
> > functions that does error reporting.
> > 
> > Reported-by: Leon Romanovsky <leon@kernel.org>
> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> 
> Today's linux-next produced this with Clang 11.
> 
> mm/kasan/report.o: warning: objtool: kasan_report()+0x8a: call to __stack_chk_fail() with UACCESS enabled
> 
> kasan_report at mm/kasan/report.c:536

Peter, this was also reported with GCC about a month ago.  Should we add
__stack_chk_fail() to the uaccess safe list?

-- 
Josh


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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-28 14:33     ` Josh Poimboeuf
@ 2020-05-28 14:55       ` Peter Zijlstra
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Zijlstra @ 2020-05-28 14:55 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Qian Cai, Andrey Konovalov, Andrew Morton, Andrey Ryabinin,
	Alexander Potapenko, Dmitry Vyukov, kasan-dev, linux-mm,
	linux-kernel, Leon Romanovsky, Leon Romanovsky, Randy Dunlap

On Thu, May 28, 2020 at 09:33:41AM -0500, Josh Poimboeuf wrote:
> On Thu, May 28, 2020 at 09:49:13AM -0400, Qian Cai wrote:
> > On Tue, May 12, 2020 at 05:33:20PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> > > The kasan_report() functions belongs to report.c, as it's a common
> > > functions that does error reporting.
> > > 
> > > Reported-by: Leon Romanovsky <leon@kernel.org>
> > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> > 
> > Today's linux-next produced this with Clang 11.
> > 
> > mm/kasan/report.o: warning: objtool: kasan_report()+0x8a: call to __stack_chk_fail() with UACCESS enabled
> > 
> > kasan_report at mm/kasan/report.c:536
> 
> Peter, this was also reported with GCC about a month ago.  Should we add
> __stack_chk_fail() to the uaccess safe list?

It calls panic(), which I suppose is pretty safe, it kills the entire
machine dead :-)

Ok.

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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-28 13:49   ` Qian Cai
  2020-05-28 14:33     ` Josh Poimboeuf
@ 2020-05-28 15:00     ` Andrey Konovalov
  2020-05-28 15:15       ` Qian Cai
  1 sibling, 1 reply; 11+ messages in thread
From: Andrey Konovalov @ 2020-05-28 15:00 UTC (permalink / raw)
  To: Qian Cai
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, Linux Memory Management List, LKML,
	Leon Romanovsky, Leon Romanovsky, Randy Dunlap, Josh Poimboeuf

On Thu, May 28, 2020 at 3:49 PM Qian Cai <cai@lca.pw> wrote:
>
> On Tue, May 12, 2020 at 05:33:20PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> > The kasan_report() functions belongs to report.c, as it's a common
> > functions that does error reporting.
> >
> > Reported-by: Leon Romanovsky <leon@kernel.org>
> > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
>
> Today's linux-next produced this with Clang 11.
>
> mm/kasan/report.o: warning: objtool: kasan_report()+0x8a: call to __stack_chk_fail() with UACCESS enabled
>
> kasan_report at mm/kasan/report.c:536

Hm, the first patch in the series ("kasan: consistently disable
debugging features") disables stack protector for kasan files. Is that
patch in linux-next?

>
> > ---
> >  mm/kasan/common.c | 19 -------------------
> >  mm/kasan/report.c | 22 ++++++++++++++++++++--
> >  2 files changed, 20 insertions(+), 21 deletions(-)
> >
> > diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> > index 2906358e42f0..757d4074fe28 100644
> > --- a/mm/kasan/common.c
> > +++ b/mm/kasan/common.c
> > @@ -33,7 +33,6 @@
> >  #include <linux/types.h>
> >  #include <linux/vmalloc.h>
> >  #include <linux/bug.h>
> > -#include <linux/uaccess.h>
> >
> >  #include <asm/cacheflush.h>
> >  #include <asm/tlbflush.h>
> > @@ -613,24 +612,6 @@ void kasan_free_shadow(const struct vm_struct *vm)
> >  }
> >  #endif
> >
> > -extern void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip);
> > -extern bool report_enabled(void);
> > -
> > -bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip)
> > -{
> > -     unsigned long flags = user_access_save();
> > -     bool ret = false;
> > -
> > -     if (likely(report_enabled())) {
> > -             __kasan_report(addr, size, is_write, ip);
> > -             ret = true;
> > -     }
> > -
> > -     user_access_restore(flags);
> > -
> > -     return ret;
> > -}
> > -
> >  #ifdef CONFIG_MEMORY_HOTPLUG
> >  static bool shadow_mapped(unsigned long addr)
> >  {
> > diff --git a/mm/kasan/report.c b/mm/kasan/report.c
> > index 80f23c9da6b0..51ec45407a0b 100644
> > --- a/mm/kasan/report.c
> > +++ b/mm/kasan/report.c
> > @@ -29,6 +29,7 @@
> >  #include <linux/kasan.h>
> >  #include <linux/module.h>
> >  #include <linux/sched/task_stack.h>
> > +#include <linux/uaccess.h>
> >
> >  #include <asm/sections.h>
> >
> > @@ -454,7 +455,7 @@ static void print_shadow_for_address(const void *addr)
> >       }
> >  }
> >
> > -bool report_enabled(void)
> > +static bool report_enabled(void)
> >  {
> >       if (current->kasan_depth)
> >               return false;
> > @@ -479,7 +480,8 @@ void kasan_report_invalid_free(void *object, unsigned long ip)
> >       end_report(&flags);
> >  }
> >
> > -void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip)
> > +static void __kasan_report(unsigned long addr, size_t size, bool is_write,
> > +                             unsigned long ip)
> >  {
> >       struct kasan_access_info info;
> >       void *tagged_addr;
> > @@ -518,6 +520,22 @@ void __kasan_report(unsigned long addr, size_t size, bool is_write, unsigned lon
> >       end_report(&flags);
> >  }
> >
> > +bool kasan_report(unsigned long addr, size_t size, bool is_write,
> > +                     unsigned long ip)
> > +{
> > +     unsigned long flags = user_access_save();
> > +     bool ret = false;
> > +
> > +     if (likely(report_enabled())) {
> > +             __kasan_report(addr, size, is_write, ip);
> > +             ret = true;
> > +     }
> > +
> > +     user_access_restore(flags);
> > +
> > +     return ret;
> > +}
> > +
> >  #ifdef CONFIG_KASAN_INLINE
> >  /*
> >   * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high
> > --
> > 2.26.2.645.ge9eca65c58-goog
> >
> > --
> > 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 kasan-dev+unsubscribe@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/78a81fde6eeda9db72a7fd55fbc33173a515e4b1.1589297433.git.andreyknvl%40google.com.

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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-28 15:00     ` Andrey Konovalov
@ 2020-05-28 15:15       ` Qian Cai
  2020-05-28 15:24         ` Andrey Konovalov
  0 siblings, 1 reply; 11+ messages in thread
From: Qian Cai @ 2020-05-28 15:15 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, Linux Memory Management List, LKML,
	Leon Romanovsky, Leon Romanovsky, Randy Dunlap, Josh Poimboeuf

On Thu, May 28, 2020 at 05:00:54PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> On Thu, May 28, 2020 at 3:49 PM Qian Cai <cai@lca.pw> wrote:
> >
> > On Tue, May 12, 2020 at 05:33:20PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> > > The kasan_report() functions belongs to report.c, as it's a common
> > > functions that does error reporting.
> > >
> > > Reported-by: Leon Romanovsky <leon@kernel.org>
> > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> >
> > Today's linux-next produced this with Clang 11.
> >
> > mm/kasan/report.o: warning: objtool: kasan_report()+0x8a: call to __stack_chk_fail() with UACCESS enabled
> >
> > kasan_report at mm/kasan/report.c:536
> 
> Hm, the first patch in the series ("kasan: consistently disable
> debugging features") disables stack protector for kasan files. Is that
> patch in linux-next?

Yes, it is there,

+CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)

It seems that will not work for Clang?

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

* Re: [PATCH 2/3] kasan: move kasan_report() into report.c
  2020-05-28 15:15       ` Qian Cai
@ 2020-05-28 15:24         ` Andrey Konovalov
  0 siblings, 0 replies; 11+ messages in thread
From: Andrey Konovalov @ 2020-05-28 15:24 UTC (permalink / raw)
  To: Qian Cai
  Cc: Andrew Morton, Andrey Ryabinin, Alexander Potapenko,
	Dmitry Vyukov, kasan-dev, Linux Memory Management List, LKML,
	Leon Romanovsky, Leon Romanovsky, Randy Dunlap, Josh Poimboeuf

On Thu, May 28, 2020 at 5:15 PM Qian Cai <cai@lca.pw> wrote:
>
> On Thu, May 28, 2020 at 05:00:54PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> > On Thu, May 28, 2020 at 3:49 PM Qian Cai <cai@lca.pw> wrote:
> > >
> > > On Tue, May 12, 2020 at 05:33:20PM +0200, 'Andrey Konovalov' via kasan-dev wrote:
> > > > The kasan_report() functions belongs to report.c, as it's a common
> > > > functions that does error reporting.
> > > >
> > > > Reported-by: Leon Romanovsky <leon@kernel.org>
> > > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> > >
> > > Today's linux-next produced this with Clang 11.
> > >
> > > mm/kasan/report.o: warning: objtool: kasan_report()+0x8a: call to __stack_chk_fail() with UACCESS enabled
> > >
> > > kasan_report at mm/kasan/report.c:536
> >
> > Hm, the first patch in the series ("kasan: consistently disable
> > debugging features") disables stack protector for kasan files. Is that
> > patch in linux-next?
>
> Yes, it is there,
>
> +CFLAGS_report.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
>
> It seems that will not work for Clang?

Ah, Clang doesn't have -fno-conserve-stack and that makes the whole
cc-option expression fail? OK, I'll send a fix.

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

end of thread, other threads:[~2020-05-28 15:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 15:33 [PATCH 1/3] kasan: consistently disable debugging features Andrey Konovalov
2020-05-12 15:33 ` [PATCH 2/3] kasan: move kasan_report() into report.c Andrey Konovalov
2020-05-12 16:42   ` Leon Romanovsky
2020-05-28 13:49   ` Qian Cai
2020-05-28 14:33     ` Josh Poimboeuf
2020-05-28 14:55       ` Peter Zijlstra
2020-05-28 15:00     ` Andrey Konovalov
2020-05-28 15:15       ` Qian Cai
2020-05-28 15:24         ` Andrey Konovalov
2020-05-12 15:33 ` [PATCH 3/3] kasan: add missing functions declarations to kasan.h Andrey Konovalov
2020-05-12 16:41   ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).