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: <CAAXkRofTpf7R31V8vQOghkzWL+Ofqu0eCNV-WOmpm8pmpTvtLg@mail.gmail.com>
Date:   Thu, 20 May 2021 04:40:23 -0700
From:   Joseph Richey <joerichey94@...il.com>
To:     Mark Rutland <mark.rutland@....com>
Cc:     trivial@...nel.org, Joe Richey <joerichey@...gle.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
        x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Lorenzo Pieralisi <lorenzo.pieralisi@....com>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Zhangfei Gao <zhangfei.gao@...aro.org>,
        Zhou Wang <wangzhou1@...ilicon.com>,
        linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-media@...r.kernel.org,
        linux-accelerators@...ts.ozlabs.org
Subject: Re: [PATCH 0/6] Don't use BIT() macro in UAPI headers

On Thu, May 20, 2021 at 4:11 AM Mark Rutland <mark.rutland@....com> wrote:
>
> Hi,
>
> On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote:
> > From: Joe Richey <joerichey@...gle.com>
> >
> > The BIT(n) macro is used in the kernel as an alias for (1 << n).
> > However, it is not defined in the UAPI headers, which means that any
> > UAPI header files must be careful not to use it, or else the user
> > will get a linker error.
>
> Beware that the common definition of BIT() (in include/vdso/bits.h) is:
>
> | #define BIT(nr)                 (UL(1) << (nr))
>
> That UL() can be important if `nr` is ever greater than bits per int.
>
> > For example, compiling the following program:
> >
> >     #include <sys/auxv.h>
> >     #include <asm/hwcap2.h>
> >
> >     // Detect if FSGSBASE instructions are enabled
> >     int main() {
> >         unsigned long val = getauxval(AT_HWCAP2);
> >         return !(val & HWCAP2_FSGSBASE);
> >     }
> >
> > Results in the following likner error:
> >
> >     /usr/bin/ld: /tmp/cceFpAdR.o: in function `main':
> >     gs.c:(.text+0x21): undefined reference to `BIT'
> >
> > This patch series changes all UAPI uses of BIT() to just be open-coded.
>
> In include/uapi/linux/const.h we have an equivaleint _BITUL() macro,
> which I think should be used in preference of open-coding this (and is
> already used in a number of uapi headers).

That's a good idea. I mostly just did the open-coding for
consistency with the surrounding code, but aside from kvm.h
there aren't really many usages to change, so I can do it.

For kvm.h, I think it might be best to leave it open-coded
and move the entire file to _BITUL() at once.

>
> > However, there really should be a check for this in checkpatch.pl
> > Currently, the script actually _encourages_ users to use the BIT macro
> > even if adding things to UAPI.
>
> I think having something that suggests s/BIT()/_BITUL()/ under uapi
> would be good.

I'll just change the script to recommend _BITUL() (instead
of BIT()) if the code path contains "uapi".

>
> Thanks,
> Mark.
>
> >
> > Running `rg "BIT\(" **/uapi/**` shows no more usage of BIT() in any
> > UAPI headers. Tested by building a basic kernel. Changes are trivial.
> >
> > Joe Richey (6):
> >   x86/elf: Don't use BIT() macro in UAPI headers
> >   KVM: X86: Don't use BIT() macro in UAPI headers
> >   drivers: firmware: psci: Don't use BIT() macro in UAPI headers
> >   uacce: Don't use BIT() macro in UAPI headers
> >   media: vicodec: Don't use BIT() macro in UAPI headers
> >   tools headers UAPI: Sync pkt_sched.h with the kernel sources
> >
> >  arch/x86/include/uapi/asm/hwcap2.h   |   2 +-
> >  include/uapi/linux/kvm.h             |   4 +-
> >  include/uapi/linux/psci.h            |   2 +-
> >  include/uapi/linux/v4l2-controls.h   |  22 ++---
> >  include/uapi/misc/uacce/uacce.h      |   2 +-
> >  tools/include/uapi/linux/kvm.h       |   4 +-
> >  tools/include/uapi/linux/pkt_sched.h | 122 ++++++++++++++++++++++++---
> >  7 files changed, 130 insertions(+), 28 deletions(-)
> >
> > --
> > 2.31.1
> >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ