linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kcov: don't instrument with UBSAN
@ 2020-12-09 10:01 Dmitry Vyukov
  2020-12-09 10:50 ` Marco Elver
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Dmitry Vyukov @ 2020-12-09 10:01 UTC (permalink / raw)
  To: akpm
  Cc: andreyknvl, kasan-dev, linux-kernel, linux-mm, Dmitry Vyukov,
	Stephen Rothwell, Marco Elver

Both KCOV and UBSAN use compiler instrumentation. If UBSAN detects a bug
in KCOV, it may cause infinite recursion via printk and other common
functions. We already don't instrument KCOV with KASAN/KCSAN for this
reason, don't instrument it with UBSAN as well.

As a side effect this also resolves the following gcc warning:

conflicting types for built-in function '__sanitizer_cov_trace_switch';
expected 'void(long unsigned int,  void *)' [-Wbuiltin-declaration-mismatch]

It's only reported when kcov.c is compiled with any of the sanitizers
enabled. Size of the arguments is correct, it's just that gcc uses 'long'
on 64-bit arches and 'long long' on 32-bit arches, while kernel type is
always 'long long'.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Suggested-by: Marco Elver <elver@google.com>
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
---
 kernel/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/Makefile b/kernel/Makefile
index aac15aeb9d69..efa42857532b 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -34,8 +34,11 @@ KCOV_INSTRUMENT_extable.o := n
 KCOV_INSTRUMENT_stacktrace.o := n
 # Don't self-instrument.
 KCOV_INSTRUMENT_kcov.o := n
+# If sanitizers detect any issues in kcov, it may lead to recursion
+# via printk, etc.
 KASAN_SANITIZE_kcov.o := n
 KCSAN_SANITIZE_kcov.o := n
+UBSAN_SANITIZE_kcov.o := n
 CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack) -fno-stack-protector
 
 obj-y += sched/
-- 
2.29.2.576.ga3fc446d84-goog



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

* Re: [PATCH] kcov: don't instrument with UBSAN
  2020-12-09 10:01 [PATCH] kcov: don't instrument with UBSAN Dmitry Vyukov
@ 2020-12-09 10:50 ` Marco Elver
  2020-12-09 13:51 ` Andrey Konovalov
  2020-12-09 18:54 ` Kees Cook
  2 siblings, 0 replies; 5+ messages in thread
From: Marco Elver @ 2020-12-09 10:50 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Andrew Morton, Andrey Konovalov, kasan-dev, LKML,
	Linux Memory Management List, Stephen Rothwell

On Wed, 9 Dec 2020 at 11:01, Dmitry Vyukov <dvyukov@google.com> wrote:
>
> Both KCOV and UBSAN use compiler instrumentation. If UBSAN detects a bug
> in KCOV, it may cause infinite recursion via printk and other common
> functions. We already don't instrument KCOV with KASAN/KCSAN for this
> reason, don't instrument it with UBSAN as well.
>
> As a side effect this also resolves the following gcc warning:
>
> conflicting types for built-in function '__sanitizer_cov_trace_switch';
> expected 'void(long unsigned int,  void *)' [-Wbuiltin-declaration-mismatch]
>
> It's only reported when kcov.c is compiled with any of the sanitizers
> enabled. Size of the arguments is correct, it's just that gcc uses 'long'
> on 64-bit arches and 'long long' on 32-bit arches, while kernel type is
> always 'long long'.
>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>

Acked-by: Marco Elver <elver@google.com>


> ---
>  kernel/Makefile | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/kernel/Makefile b/kernel/Makefile
> index aac15aeb9d69..efa42857532b 100644
> --- a/kernel/Makefile
> +++ b/kernel/Makefile
> @@ -34,8 +34,11 @@ KCOV_INSTRUMENT_extable.o := n
>  KCOV_INSTRUMENT_stacktrace.o := n
>  # Don't self-instrument.
>  KCOV_INSTRUMENT_kcov.o := n
> +# If sanitizers detect any issues in kcov, it may lead to recursion
> +# via printk, etc.
>  KASAN_SANITIZE_kcov.o := n
>  KCSAN_SANITIZE_kcov.o := n
> +UBSAN_SANITIZE_kcov.o := n
>  CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack) -fno-stack-protector
>
>  obj-y += sched/
> --
> 2.29.2.576.ga3fc446d84-goog
>


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

* Re: [PATCH] kcov: don't instrument with UBSAN
  2020-12-09 10:01 [PATCH] kcov: don't instrument with UBSAN Dmitry Vyukov
  2020-12-09 10:50 ` Marco Elver
@ 2020-12-09 13:51 ` Andrey Konovalov
  2020-12-09 18:54 ` Kees Cook
  2 siblings, 0 replies; 5+ messages in thread
From: Andrey Konovalov @ 2020-12-09 13:51 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: Andrew Morton, kasan-dev, LKML, Linux Memory Management List,
	Stephen Rothwell, Marco Elver

On Wed, Dec 9, 2020 at 11:01 AM Dmitry Vyukov <dvyukov@google.com> wrote:
>
> Both KCOV and UBSAN use compiler instrumentation. If UBSAN detects a bug
> in KCOV, it may cause infinite recursion via printk and other common
> functions. We already don't instrument KCOV with KASAN/KCSAN for this
> reason, don't instrument it with UBSAN as well.
>
> As a side effect this also resolves the following gcc warning:
>
> conflicting types for built-in function '__sanitizer_cov_trace_switch';
> expected 'void(long unsigned int,  void *)' [-Wbuiltin-declaration-mismatch]
>
> It's only reported when kcov.c is compiled with any of the sanitizers
> enabled. Size of the arguments is correct, it's just that gcc uses 'long'
> on 64-bit arches and 'long long' on 32-bit arches, while kernel type is
> always 'long long'.
>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
> ---
>  kernel/Makefile | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/kernel/Makefile b/kernel/Makefile
> index aac15aeb9d69..efa42857532b 100644
> --- a/kernel/Makefile
> +++ b/kernel/Makefile
> @@ -34,8 +34,11 @@ KCOV_INSTRUMENT_extable.o := n
>  KCOV_INSTRUMENT_stacktrace.o := n
>  # Don't self-instrument.
>  KCOV_INSTRUMENT_kcov.o := n
> +# If sanitizers detect any issues in kcov, it may lead to recursion
> +# via printk, etc.
>  KASAN_SANITIZE_kcov.o := n
>  KCSAN_SANITIZE_kcov.o := n
> +UBSAN_SANITIZE_kcov.o := n
>  CFLAGS_kcov.o := $(call cc-option, -fno-conserve-stack) -fno-stack-protector
>
>  obj-y += sched/
> --
> 2.29.2.576.ga3fc446d84-goog
>

Reviewed-by: Andrey Konovalov <andreyknvl@google.com>


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

* Re: [PATCH] kcov: don't instrument with UBSAN
  2020-12-09 10:01 [PATCH] kcov: don't instrument with UBSAN Dmitry Vyukov
  2020-12-09 10:50 ` Marco Elver
  2020-12-09 13:51 ` Andrey Konovalov
@ 2020-12-09 18:54 ` Kees Cook
  2020-12-09 21:49   ` Stephen Rothwell
  2 siblings, 1 reply; 5+ messages in thread
From: Kees Cook @ 2020-12-09 18:54 UTC (permalink / raw)
  To: Dmitry Vyukov
  Cc: akpm, andreyknvl, kasan-dev, linux-kernel, linux-mm,
	Stephen Rothwell, Marco Elver

On Wed, Dec 09, 2020 at 11:01:52AM +0100, Dmitry Vyukov wrote:
> Both KCOV and UBSAN use compiler instrumentation. If UBSAN detects a bug
> in KCOV, it may cause infinite recursion via printk and other common
> functions. We already don't instrument KCOV with KASAN/KCSAN for this
> reason, don't instrument it with UBSAN as well.
> 
> As a side effect this also resolves the following gcc warning:
> 
> conflicting types for built-in function '__sanitizer_cov_trace_switch';
> expected 'void(long unsigned int,  void *)' [-Wbuiltin-declaration-mismatch]
> 
> It's only reported when kcov.c is compiled with any of the sanitizers
> enabled. Size of the arguments is correct, it's just that gcc uses 'long'
> on 64-bit arches and 'long long' on 32-bit arches, while kernel type is
> always 'long long'.
> 
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Dmitry Vyukov <dvyukov@google.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

Thanks for chasing this down!

Andrew, can you add this to the stack of ubsan patches you're carrying,
please?

-- 
Kees Cook


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

* Re: [PATCH] kcov: don't instrument with UBSAN
  2020-12-09 18:54 ` Kees Cook
@ 2020-12-09 21:49   ` Stephen Rothwell
  0 siblings, 0 replies; 5+ messages in thread
From: Stephen Rothwell @ 2020-12-09 21:49 UTC (permalink / raw)
  To: Kees Cook
  Cc: Dmitry Vyukov, akpm, andreyknvl, kasan-dev, linux-kernel,
	linux-mm, Marco Elver

[-- Attachment #1: Type: text/plain, Size: 1353 bytes --]

Hi all,

On Wed, 9 Dec 2020 10:54:39 -0800 Kees Cook <keescook@chromium.org> wrote:
>
> On Wed, Dec 09, 2020 at 11:01:52AM +0100, Dmitry Vyukov wrote:
> > Both KCOV and UBSAN use compiler instrumentation. If UBSAN detects a bug
> > in KCOV, it may cause infinite recursion via printk and other common
> > functions. We already don't instrument KCOV with KASAN/KCSAN for this
> > reason, don't instrument it with UBSAN as well.
> > 
> > As a side effect this also resolves the following gcc warning:
> > 
> > conflicting types for built-in function '__sanitizer_cov_trace_switch';
> > expected 'void(long unsigned int,  void *)' [-Wbuiltin-declaration-mismatch]
> > 
> > It's only reported when kcov.c is compiled with any of the sanitizers
> > enabled. Size of the arguments is correct, it's just that gcc uses 'long'
> > on 64-bit arches and 'long long' on 32-bit arches, while kernel type is
> > always 'long long'.
> > 
> > Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> > Suggested-by: Marco Elver <elver@google.com>
> > Signed-off-by: Dmitry Vyukov <dvyukov@google.com>  
> 
> Reviewed-by: Kees Cook <keescook@chromium.org>
> 
> Thanks for chasing this down!
> 
> Andrew, can you add this to the stack of ubsan patches you're carrying,
> please?

Added to linux-next today.

-- 
Cheers,
Stephen Rothwell

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2020-12-09 21:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-09 10:01 [PATCH] kcov: don't instrument with UBSAN Dmitry Vyukov
2020-12-09 10:50 ` Marco Elver
2020-12-09 13:51 ` Andrey Konovalov
2020-12-09 18:54 ` Kees Cook
2020-12-09 21:49   ` Stephen Rothwell

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