Re: [PATCH] ubsan: Require GCC-8+ or Clang to use UBSAN

From: Josh Poimboeuf
Date: Tue Feb 09 2021 - 15:18:38 EST


On Mon, Jan 18, 2021 at 11:53:37AM -0600, Josh Poimboeuf wrote:
> On Thu, Jan 14, 2021 at 02:09:28PM +0300, Andrey Ryabinin wrote:
> >
> >
> > On 1/14/21 1:59 PM, Peter Zijlstra wrote:
> > > 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.
> > >
> >
> > Actually removing CONFIG_UBSAN_SIGNED_OVERFLOW would give us the same
> > effect without restricting GCC versions.
>
> Is that preferable? Always happy to remove code, just need some
> justification behind it.

Andrey,

Is Peter's patch acceptable or do you want to do something else?

--
Josh