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]
Date:   Wed, 4 Nov 2020 03:34:47 +0200
From:   Jarkko Sakkinen <jarkko.sakkinen@....fi>
To:     Nick Desaulniers <ndesaulniers@...gle.com>
Cc:     Jarkko Sakkinen <jarkko@...nel.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Kees Cook <keescook@...omium.org>,
        Miguel Ojeda <miguel.ojeda.sandonis@...il.com>,
        Nathan Chancellor <natechancellor@...il.com>,
        Sedat Dilek <sedat.dilek@...il.com>,
        Marco Elver <elver@...gle.com>,
        Andrey Konovalov <andreyknvl@...gle.com>,
        Masahiro Yamada <masahiroy@...nel.org>,
        clang-built-linux <clang-built-linux@...glegroups.com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...nel.org>,
        Will Deacon <will@...nel.org>,
        Vincenzo Frascino <vincenzo.frascino@....com>,
        LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v3 1/7] compiler-clang: add build check for clang 10.0.1

On Tue, Nov 03, 2020 at 05:18:38PM -0800, Nick Desaulniers wrote:
> On Tue, Nov 3, 2020 at 4:38 PM Jarkko Sakkinen <jarkko@...nel.org> wrote:
> >
> > On Tue, Nov 03, 2020 at 10:48:27AM -0800, Nick Desaulniers wrote:
> > > On Mon, Nov 2, 2020 at 8:55 PM Jarkko Sakkinen <jarkko@...nel.org> wrote:
> > > >
> > > > On Wed, Sep 02, 2020 at 03:59:05PM -0700, Nick Desaulniers wrote:
> > > > > +#define CLANG_VERSION (__clang_major__ * 10000       \
> > > > > +                  + __clang_minor__ * 100    \
> > > > > +                  + __clang_patchlevel__)
> > > > > +
> > > > > +#if CLANG_VERSION < 100001
> > > > > +# error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
> > > > > +#endif
> > > >
> > > >
> > > > I'm trying to compile a BPF enabled test kernel for a live system and I
> > > > get this error even though I have much newer clang:
> > > >
> > > > ➜  ~ (master) ✔ clang --version
> > > > Ubuntu clang version 11.0.0-2
> > > > Target: x86_64-pc-linux-gnu
> > > > Thread model: posix
> > > > InstalledDir: /usr/bin
> > > >
> > > > Tried to Google for troubleshooter tips but this patch is basically the
> > > > only hit I get :-)
> > >
> > > To check the values of the above preprocessor defines, please run:
> > > $ clang -dM -E - < /dev/null | grep -e __clang_m -e __clang_p
> > >
> > > If you have multiple versions of clang installed, you might not be
> > > running the version you think you are.  Particularly, if you're using
> > > bcc, idk if it includes a copy of clang?  If that's the case, we may
> > > have to work out how we can support older versions of clang for the
> > > express purposes of bpf.
> >
> > ➜  ~ (master) ✔ clang -dM -E - < /dev/null | grep -e __clang_m -e __clang_p
> > #define __clang_major__ 11
> > #define __clang_minor__ 0
> > #define __clang_patchlevel__ 0
> >
> > I'm compiling the kernel itself with GCC.
> >
> > Here's an example BPF script that fails on me:
> >
> > struct sgx_enclave_add_pages {
> >         unsigned long src;
> >         unsigned long offset;
> >         unsigned long length;
> >         unsigned long secinfo;
> >         unsigned long flags;
> >         unsigned long count;
> > };
> >
> > kprobe:sgx_ioctl
> > {
> >         if (arg1 == 0xc030a401) {
> >                 printf("sgx_ioctl: %d, %lu\n", pid, ((struct sgx_enclave_add_pages *)(arg2))->offset);
> >         }
> >
> > }
> > Note that it relies on code not yet in the mainline.
> >
> > If I don't declare structs, things work just fine. E.g. the following
> > works:
> >
> > kprobe:sgx_encl_get_backing
> > {
> >         printf("%s\n", func)
> > }
> >
> > BTW, I don't really understand how scripts/clang-version.sh is even
> > supposed to work, if you compile the kernel itself with GCC. In that
> > case there would be no output, right? And thus version gets set to
> > zero...
> 
> That script is only used by KBUILD.  include/linux/compiler-clang.h is
> what's included into include/linux/compiler_types.h and causes the
> error.  The eBFP tools must be including kernel headers and defining
> `__clang__`.  Forgive my complete ignorance of eBPF, but how do you
> build that script?  I assume the tool is using Clang, since eBPF

Thanks a lot for helping with this :-)

I'm using bpftrace as the frontend.

> relies on the LLVM backend (not sure if the GCC eBPF backend is good
> to go quite yet), and that version of clang is older.
> 
> I wonder if we should guard the version check with __BPF_TRACING__
> similar to arch/x86/include/asm/cpufeature.h? Care to test:


Before I received this response, I did git revert for this commit
and things started working again.

> ```
> diff --git a/include/linux/compiler-clang.h
> b/include/linux/compiler-clang.h
> index dd7233c48bf3..98cff1b4b088 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -8,8 +8,10 @@
>                      + __clang_patchlevel__)
> 
>  #if CLANG_VERSION < 100001
> +#ifndef __BPF_TRACING__
>  # error Sorry, your version of Clang is too old - please use 10.0.1 or newer.
>  #endif
> +#endif
> 
>  /* Compiler specific definitions for Clang compiler */
> ```
> -- 

Shouldn't "#ifndef" be before the whole version check? Otherwise,
LGTM. Please CC me once there is a properly formed patch to try out.

> Thanks,
> ~Nick Desaulniers

/Jarkko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ