[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202101121555.C929315@keescook>
Date: Tue, 12 Jan 2021 15:56:26 -0800
From: Kees Cook <keescook@...omium.org>
To: Nathan Chancellor <natechancellor@...il.com>
Cc: Nick Desaulniers <ndesaulniers@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
LKML <linux-kernel@...r.kernel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>
Subject: Re: [PATCH] ubsan: Implement __ubsan_handle_alignment_assumption
On Tue, Jan 12, 2021 at 03:06:34PM -0700, Nathan Chancellor wrote:
> On Tue, Jan 12, 2021 at 01:53:30PM -0800, Nick Desaulniers wrote:
> > On Tue, Jan 12, 2021 at 1:37 PM Nathan Chancellor
> > <natechancellor@...il.com> wrote:
> > >
> > > > if real_ptr is an unsigned long, do we want to use `__ffs(real_ptr) +
> > > > 1` here rather than ffs which takes an int? It seems the kernel is
> > > > missing a definition of ffsl. :(
> > >
> > > Why the + 1? I think if we use __ffs (which it seems like we should), I
> > > think that needs to become
> >
> > This came up recently in an internal code review; ffs and __ffs differ
> > in output by one. See also the definition of ffs for alpha in
> > arch/alpha/include/asm/bitops.h.
>
> Interesting, thanks for bringing it up! Looks like ffs returns 1-32 and
> __ffs returns 0-31. I think that we want __ffs here because we are
> shifting (1UL << 32 overflows on 32-bit architectures) and the code in
> LLVM appears to agree. LeastSignificantSetBitIndex evaluates to
> __builtin_ctzl, which is the asm-generic implementation of __ffs.
Sounds good. With __ffs, consider your v2:
Acked-by: Kees Cook <keescook@...omium.org>
--
Kees Cook
Powered by blists - more mailing lists