linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubsan: build ubsan.c more conservatively
@ 2019-07-22  9:10 Arnd Bergmann
  2019-07-22 12:25 ` Andrey Ryabinin
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2019-07-22  9:10 UTC (permalink / raw)
  To: Andrey Ryabinin, akpm
  Cc: Josh Poimboeuf, Peter Zijlstra, Arnd Bergmann, stable,
	Sodagudi Prasad, Linus Torvalds, Kees Cook, Andy Shevchenko,
	David S. Miller, linux-kernel, clang-built-linux

objtool points out several conditions that it does not like, depending
on the combination with other configuration options and compiler
variants:

stack protector:
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0xbf: call to __stack_chk_fail() with UACCESS enabled
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0xbe: call to __stack_chk_fail() with UACCESS enabled

stackleak plugin:
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x4a: call to stackleak_track_stack() with UACCESS enabled
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x4a: call to stackleak_track_stack() with UACCESS enabled

kasan:
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x25: call to memcpy() with UACCESS enabled
lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x25: call to memcpy() with UACCESS enabled

The stackleak and kasan options just need to be disabled for this file
as we do for other files already. For the stack protector, we already
attempt to disable it, but this fails on clang because the check is
mixed with the gcc specific -fno-conserve-stack option, so we need to
test them separately.

Fixes: 42440c1f9911 ("lib/ubsan: add type mismatch handler for new GCC/Clang")
Link: https://lore.kernel.org/lkml/20190617123109.667090-1-arnd@arndb.de/t/
Cc: stable@vger.kernel.org
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 lib/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/Makefile b/lib/Makefile
index 095601ce371d..320e3b632dd3 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -279,7 +279,8 @@ obj-$(CONFIG_UCS2_STRING) += ucs2_string.o
 obj-$(CONFIG_UBSAN) += ubsan.o
 
 UBSAN_SANITIZE_ubsan.o := n
-CFLAGS_ubsan.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
+KASAN_SANITIZE_ubsan.o := n
+CFLAGS_ubsan.o := $(call cc-option, -fno-conserve-stack) $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN)
 
 obj-$(CONFIG_SBITMAP) += sbitmap.o
 
-- 
2.20.0


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

* Re: [PATCH] ubsan: build ubsan.c more conservatively
  2019-07-22  9:10 [PATCH] ubsan: build ubsan.c more conservatively Arnd Bergmann
@ 2019-07-22 12:25 ` Andrey Ryabinin
  2019-07-22 12:52   ` Arnd Bergmann
  0 siblings, 1 reply; 3+ messages in thread
From: Andrey Ryabinin @ 2019-07-22 12:25 UTC (permalink / raw)
  To: Arnd Bergmann, akpm
  Cc: Josh Poimboeuf, Peter Zijlstra, stable, Sodagudi Prasad,
	Linus Torvalds, Kees Cook, Andy Shevchenko, David S. Miller,
	linux-kernel, clang-built-linux



On 7/22/19 12:10 PM, Arnd Bergmann wrote:
> objtool points out several conditions that it does not like, depending
> on the combination with other configuration options and compiler
> variants:
> 
> stack protector:
> lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0xbf: call to __stack_chk_fail() with UACCESS enabled
> lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0xbe: call to __stack_chk_fail() with UACCESS enabled
> 
> stackleak plugin:
> lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x4a: call to stackleak_track_stack() with UACCESS enabled
> lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x4a: call to stackleak_track_stack() with UACCESS enabled
> 
> kasan:
> lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch()+0x25: call to memcpy() with UACCESS enabled
> lib/ubsan.o: warning: objtool: __ubsan_handle_type_mismatch_v1()+0x25: call to memcpy() with UACCESS enabled
> 
> The stackleak and kasan options just need to be disabled for this file
> as we do for other files already. For the stack protector, we already
> attempt to disable it, but this fails on clang because the check is
> mixed with the gcc specific -fno-conserve-stack option, so we need to
> test them separately.
> 
> Fixes: 42440c1f9911 ("lib/ubsan: add type mismatch handler for new GCC/Clang")

There was no uaccess validataion at that time, so the right fixes line is probably this:

Fixes: d08965a27e84 ("x86/uaccess, ubsan: Fix UBSAN vs. SMAP")

> Link: https://lore.kernel.org/lkml/20190617123109.667090-1-arnd@arndb.de/t/
> Cc: stable@vger.kernel.org
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  lib/Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/Makefile b/lib/Makefile
> index 095601ce371d..320e3b632dd3 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -279,7 +279,8 @@ obj-$(CONFIG_UCS2_STRING) += ucs2_string.o
>  obj-$(CONFIG_UBSAN) += ubsan.o
>  
>  UBSAN_SANITIZE_ubsan.o := n
> -CFLAGS_ubsan.o := $(call cc-option, -fno-conserve-stack -fno-stack-protector)
> +KASAN_SANITIZE_ubsan.o := n
> +CFLAGS_ubsan.o := $(call cc-option, -fno-conserve-stack) $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN)

$(call cc-option, -fno-conserve-stack) can be removed entirely. It's just copy paste from kasan Makefile.
It was added in kasan purely for performance reasons.

Not sure that it's needed even in kasan Makefile, the code which was
the reason for adding fno-conserve-stack might not get into the final version of KASAN patches.

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

* Re: [PATCH] ubsan: build ubsan.c more conservatively
  2019-07-22 12:25 ` Andrey Ryabinin
@ 2019-07-22 12:52   ` Arnd Bergmann
  0 siblings, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2019-07-22 12:52 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Andrew Morton, Josh Poimboeuf, Peter Zijlstra, # 3.4.x,
	Sodagudi Prasad, Linus Torvalds, Kees Cook, Andy Shevchenko,
	David S. Miller, Linux Kernel Mailing List, clang-built-linux

On Mon, Jul 22, 2019 at 2:25 PM Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
> On 7/22/19 12:10 PM, Arnd Bergmann wrote:

> >
> > Fixes: 42440c1f9911 ("lib/ubsan: add type mismatch handler for new GCC/Clang")
>
> There was no uaccess validataion at that time, so the right fixes line is probably this:
>
> Fixes: d08965a27e84 ("x86/uaccess, ubsan: Fix UBSAN vs. SMAP")
>
> > Link: > +CFLAGS_ubsan.o := $(call cc-option, -fno-conserve-stack) $(call cc-option, -fno-stack-protector) $(DISABLE_STACKLEAK_PLUGIN)
>
> $(call cc-option, -fno-conserve-stack) can be removed entirely. It's just copy paste from kasan Makefile.
> It was added in kasan purely for performance reasons.

Ok, I addressed both of these and sent an updated patch, thanks for the review.

       Arnd

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

end of thread, other threads:[~2019-07-22 12:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22  9:10 [PATCH] ubsan: build ubsan.c more conservatively Arnd Bergmann
2019-07-22 12:25 ` Andrey Ryabinin
2019-07-22 12:52   ` Arnd Bergmann

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).