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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191011192737.c0e69db9ca49cd7622efdae5@linux-foundation.org>
Date:   Fri, 11 Oct 2019 19:27:37 -0700
From:   Andrew Morton <akpm@...ux-foundation.org>
To:     Rikard Falkeborn <rikard.falkeborn@...il.com>
Cc:     bp@...en8.de, joe@...ches.com, johannes@...solutions.net,
        keescook@...omium.org, linux-kernel@...r.kernel.org,
        mingo@...hat.com, tglx@...utronix.de,
        yamada.masahiro@...ionext.com,
        Geert Uytterhoeven <geert@...ux-m68k.org>,
        Haren Myneni <haren@...ibm.com>
Subject: Re: [Patch v4 2/2] linux/bits.h: Add compile time sanity check of
 GENMASK inputs

On Wed,  9 Oct 2019 23:45:02 +0200 Rikard Falkeborn <rikard.falkeborn@...il.com> wrote:

> GENMASK() and GENMASK_ULL() are supposed to be called with the high bit
> as the first argument and the low bit as the second argument. Mixing
> them will return a mask with zero bits set.
> 
> Recent commits show getting this wrong is not uncommon, see e.g.
> commit aa4c0c9091b0 ("net: stmmac: Fix misuses of GENMASK macro") and
> commit 9bdd7bb3a844 ("clocksource/drivers/npcm: Fix misuse of GENMASK
> macro").
> 
> To prevent such mistakes from appearing again, add compile time sanity
> checking to the arguments of GENMASK() and GENMASK_ULL(). If both
> arguments are known at compile time, and the low bit is higher than the
> high bit, break the build to detect the mistake immediately.
> 
> Since GENMASK() is used in declarations, BUILD_BUG_ON_ZERO() must be
> used instead of BUILD_BUG_ON().
> 
> __builtin_constant_p does not evaluate is argument, it only checks if it
> is a constant or not at compile time, and __builtin_choose_expr does not
> evaluate the expression that is not chosen. Therefore, GENMASK(x++, 0)
> does only evaluate x++ once.
> 
> Commit 95b980d62d52 ("linux/bits.h: make BIT(), GENMASK(), and friends
> available in assembly") made the macros in linux/bits.h available in
> assembly. Since BUILD_BUG_OR_ZERO() is not asm compatible, disable the
> checks if the file is included in an asm file.
> 
> Due to bugs in GCC versions before 4.9 [0], disable the check if
> building with a too old GCC compiler.
> 
> [0]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19449

I'm seeing some breakage in code which is newly added in linux-next:

sound/soc/codecs/tas2562.c: In function tas2562_set_dai_tdm_slot:
./include/linux/build_bug.h:16:51: error: negative width in bit-field <anonymous>
 #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
                                                   ^
./include/linux/bits.h:25:3: note: in expansion of macro BUILD_BUG_ON_ZERO
  (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
   ^~~~~~~~~~~~~~~~~
./include/linux/bits.h:39:3: note: in expansion of macro GENMASK_INPUT_CHECK
  (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
   ^~~~~~~~~~~~~~~~~~~
sound/soc/codecs/tas2562.h:65:37: note: in expansion of macro GENMASK
 #define TAS2562_TDM_CFG2_RXLEN_MASK GENMASK(0, 1)
                                     ^~~~~~~
sound/soc/codecs/tas2562.c:160:11: note: in expansion of macro TAS2562_TDM_CFG2_RXLEN_MASK
           TAS2562_TDM_CFG2_RXLEN_MASK,
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/build_bug.h:16:51: error: negative width in bit-field <anonymous>
 #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
                                                   ^
./include/linux/bits.h:25:3: note: in expansion of macro BUILD_BUG_ON_ZERO
  (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \


and

In file included from ./include/linux/bits.h:23:0,
                 from ./include/linux/ioport.h:15,
                 from ./include/linux/acpi.h:12,
                 from drivers/crypto/hisilicon/hpre/hpre_main.c:3:
./include/linux/build_bug.h:16:51: error: negative width in bit-field ‘<anonymous>’
 #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
                                                   ^
./include/linux/bits.h:25:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
  (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
   ^~~~~~~~~~~~~~~~~
./include/linux/bits.h:39:3: note: in expansion of macro ‘GENMASK_INPUT_CHECK’
  (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
   ^~~~~~~~~~~~~~~~~~~
drivers/crypto/hisilicon/hpre/hpre_main.c:119:15: note: in expansion of macro ‘GENMASK’
  { .int_msk = GENMASK(10, 15), .msg = "hpre_ooo_rdrsp_err" },
               ^~~~~~~
./include/linux/build_bug.h:16:51: error: negative width in bit-field ‘<anonymous>’
 #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
                                                   ^
./include/linux/bits.h:25:3: note: in expansion of macro ‘BUILD_BUG_ON_ZERO’
  (BUILD_BUG_ON_ZERO(__builtin_choose_expr( \
   ^~~~~~~~~~~~~~~~~
./include/linux/bits.h:39:3: note: in expansion of macro ‘GENMASK_INPUT_CHECK’
  (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
   ^~~~~~~~~~~~~~~~~~~
drivers/crypto/hisilicon/hpre/hpre_main.c:120:15: note: in expansion of macro ‘GENMASK’
  { .int_msk = GENMASK(16, 21), .msg = "hpre_ooo_wrrsp_err" },
               ^~~~~~~

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ