lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKwvOdkA5kmXhKFDFTApLyT5LcUX2-Xr6vJJ0b8wePunMpLu0g@mail.gmail.com>
Date:   Tue, 12 Jan 2021 13:53:30 -0800
From:   Nick Desaulniers <ndesaulniers@...gle.com>
To:     Nathan Chancellor <natechancellor@...il.com>
Cc:     Kees Cook <keescook@...omium.org>,
        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 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.

Also, I just confirmed that:
```
#include <stdio.h>

// include/asm-generic/bitops/ffs.h
static inline int ffs(int x)
{
        int r = 1;

        if (!x)
                return 0;
        if (!(x & 0xffff)) {
                x >>= 16;
                r += 16;
        }
        if (!(x & 0xff)) {
                x >>= 8;
                r += 8;
        }
        if (!(x & 0xf)) {
                x >>= 4;
                r += 4;
        }
        if (!(x & 3)) {
                x >>= 2;
                r += 2;
        }
        if (!(x & 1)) {
                x >>= 1;
                r += 1;
        }
        return r;
}

// include/asm-generic/bitops/__ffs.h
static __always_inline unsigned long __ffs(unsigned long word)
{
        int num = 0;

        if ((word & 0xffffffff) == 0) {
                num += 32;
                word >>= 32;
        }
        if ((word & 0xffff) == 0) {
                num += 16;
                word >>= 16;
        }
        if ((word & 0xff) == 0) {
                num += 8;
                word >>= 8;
        }
        if ((word & 0xf) == 0) {
                num += 4;
                word >>= 4;
        }
        if ((word & 0x3) == 0) {
                num += 2;
                word >>= 2;
        }
        if ((word & 0x1) == 0)
                num += 1;
        return num;
}

int main() {
    int x = 3;
    unsigned long y = 3;
    printf("%d\n%lu\n", ffs(x), __ffs(y));
    return 0;
}
```
will print:
1
0
-- 
Thanks,
~Nick Desaulniers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ