linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	linux-kernel@vger.kernel.org,
	Randy Dunlap <rdunlap@infradead.org>,
	aryabinin@virtuozzo.com, dvyukov@google.com,
	keescook@chromium.org
Subject: [PATCH] ubsan: Require GCC-8+ or Clang to use UBSAN
Date: Thu, 14 Jan 2021 11:59:01 +0100	[thread overview]
Message-ID: <YAAj9aAcPsV9I6UL@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210104151317.GR3021@hirez.programming.kicks-ass.net>

On Mon, Jan 04, 2021 at 04:13:17PM +0100, Peter Zijlstra wrote:
> On Tue, Dec 22, 2020 at 11:04:54PM -0600, Josh Poimboeuf wrote:
> > GCC 7 has a known bug where UBSAN ignores '-fwrapv' and generates false
> > signed-overflow-UB warnings.  The type mismatch between 'i' and
> > 'nr_segs' in copy_compat_iovec_from_user() is causing such a warning,
> > which also happens to violate uaccess rules:
> > 
> >   lib/iov_iter.o: warning: objtool: iovec_from_user()+0x22d: call to __ubsan_handle_add_overflow() with UACCESS enabled
> > 
> > Fix it by making the variable types match.
> > 
> > This is similar to a previous commit:
> > 
> >   29da93fea3ea ("mm/uaccess: Use 'unsigned long' to placate UBSAN warnings on older GCC versions")
> 
> Maybe it's time we make UBSAN builds depend on GCC-8+ ?

---
Subject: ubsan: Require GCC-8+ or Clang to use UBSAN

Just like how we require GCC-8.2 for KASAN due to compiler bugs, require
a sane version of GCC for UBSAN.

Specifically, before GCC-8 UBSAN doesn't respect -fwrapv and thinks
signed arithmetic is buggered.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 lib/Kconfig.ubsan | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/Kconfig.ubsan b/lib/Kconfig.ubsan
index 8b635fd75fe4..acc3df62460e 100644
--- a/lib/Kconfig.ubsan
+++ b/lib/Kconfig.ubsan
@@ -2,8 +2,13 @@
 config ARCH_HAS_UBSAN_SANITIZE_ALL
 	bool
 
+# UBSAN prior to GCC-8 gets -fwrapv wrong, we rely on that
+config UBSAN_SANE
+	def_bool !CC_IS_GCC || GCC_VERSION >= 80000
+
 menuconfig UBSAN
 	bool "Undefined behaviour sanity checker"
+	depends on UBSAN_SANE
 	help
 	  This option enables the Undefined Behaviour sanity checker.
 	  Compile-time instrumentation is used to detect various undefined

  parent reply	other threads:[~2021-01-14 11:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23  5:04 [PATCH] mm/uaccess: Use 'unsigned long' to placate UBSAN warnings, again Josh Poimboeuf
2020-12-23  7:18 ` Randy Dunlap
2021-01-07 10:06   ` David Laight
2021-01-04 15:13 ` Peter Zijlstra
2021-01-06 23:37   ` Kees Cook
2021-01-07  0:06     ` Randy Dunlap
2021-01-07 21:07       ` Kees Cook
2021-01-13 23:27         ` Josh Poimboeuf
2021-01-07 10:51     ` Dmitry Vyukov
2021-01-14 10:59   ` Peter Zijlstra [this message]
2021-01-14 11:09     ` [PATCH] ubsan: Require GCC-8+ or Clang to use UBSAN Andrey Ryabinin
2021-01-18 17:53       ` Josh Poimboeuf
2021-02-09 18:24         ` Josh Poimboeuf
2021-02-09 23:17           ` Andrey Rybainin
2021-02-10  0:21             ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YAAj9aAcPsV9I6UL@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=dvyukov@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).