stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Kaehlcke <mka@chromium.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Sasha Levin <sashal@kernel.org>,
	stable@vger.kernel.org, clang-built-linux@googlegroups.com,
	Nick Desaulniers <ndesaulniers@google.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Ido Schimmel <idosch@mellanox.com>,
	Will Deacon <will.deacon@arm.com>,
	Vadim Pasternak <vadimp@mellanox.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	Pavel Machek <pavel@ucw.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] include/linux/bitops.h: sanitize rotate primitives
Date: Tue, 4 Jun 2019 08:26:32 -0700	[thread overview]
Message-ID: <20190604152632.GO40515@google.com> (raw)
In-Reply-To: <20190604074849.GC6840@kroah.com>

On Tue, Jun 04, 2019 at 09:48:49AM +0200, Greg Kroah-Hartman wrote:
> On Mon, Jun 03, 2019 at 11:39:46AM -0700, Matthias Kaehlcke wrote:
> > From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > 
> > commit ef4d6f6b275c498f8e5626c99dbeefdc5027f843 upstream.
> > 
> > The ror32 implementation (word >> shift) | (word << (32 - shift) has
> > undefined behaviour if shift is outside the [1, 31] range.  Similarly
> > for the 64 bit variants.  Most callers pass a compile-time constant
> > (naturally in that range), but there's an UBSAN report that these may
> > actually be called with a shift count of 0.
> > 
> > Instead of special-casing that, we can make them DTRT for all values of
> > shift while also avoiding UB.  For some reason, this was already partly
> > done for rol32 (which was well-defined for [0, 31]).  gcc 8 recognizes
> > these patterns as rotates, so for example
> > 
> >   __u32 rol32(__u32 word, unsigned int shift)
> >   {
> > 	return (word << (shift & 31)) | (word >> ((-shift) & 31));
> >   }
> > 
> > compiles to
> > 
> > 0000000000000020 <rol32>:
> >   20:   89 f8                   mov    %edi,%eax
> >   22:   89 f1                   mov    %esi,%ecx
> >   24:   d3 c0                   rol    %cl,%eax
> >   26:   c3                      retq
> > 
> > Older compilers unfortunately do not do as well, but this only affects
> > the small minority of users that don't pass constants.
> > 
> > Due to integer promotions, ro[lr]8 were already well-defined for shifts
> > in [0, 8], and ro[lr]16 were mostly well-defined for shifts in [0, 16]
> > (only mostly - u16 gets promoted to _signed_ int, so if bit 15 is set,
> > word << 16 is undefined).  For consistency, update those as well.
> > 
> > Link: http://lkml.kernel.org/r/20190410211906.2190-1-linux@rasmusvillemoes.dk
> > Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> > Reported-by: Ido Schimmel <idosch@mellanox.com>
> > Tested-by: Ido Schimmel <idosch@mellanox.com>
> > Reviewed-by: Will Deacon <will.deacon@arm.com>
> > Cc: Vadim Pasternak <vadimp@mellanox.com>
> > Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> > Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> > Cc: Pavel Machek <pavel@ucw.cz>
> > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> > Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> > ---
> > Hi Greg and Sasha,
> > 
> > Please pick this patch for 4.19. It fixes (at least) crashes due
> > to undefined instructions in BPF code on arm32 when building with
> > clang:
> 
> What about for the 5.1 kernel?  You don't want anyone updating from 4.19
> to the latest stable and having a regression, right?

ack

posted it also for 5.1

      reply	other threads:[~2019-06-04 15:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-03 18:39 [PATCH] include/linux/bitops.h: sanitize rotate primitives Matthias Kaehlcke
2019-06-04  7:48 ` Greg Kroah-Hartman
2019-06-04 15:26   ` Matthias Kaehlcke [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190604152632.GO40515@google.com \
    --to=mka@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=idosch@mellanox.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux@rasmusvillemoes.dk \
    --cc=ndesaulniers@google.com \
    --cc=pavel@ucw.cz \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=vadimp@mellanox.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).