From: Pavel Machek <pavel@ucw.cz>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Vadim Pasternak <vadimp@mellanox.com>,
jacek.anaszewski@gmail.com, linux-kernel@vger.kernel.org,
linux-leds@vger.kernel.org, idosch@mellanox.com,
Andrey Ryabinin <aryabinin@virtuozzo.com>
Subject: Re: [PATCH v1 bitops] bitops: Fix UBSAN undefined behavior warning for rotation right
Date: Tue, 9 Apr 2019 11:50:41 +0200 [thread overview]
Message-ID: <20190409095041.GA32344@atrey.karlin.mff.cuni.cz> (raw)
In-Reply-To: <20190408155217.3f723554ae7fbcb34eeacb30@linux-foundation.org>
Hi!
> (resend, cc Andrey)
>
> On Sun, 7 Apr 2019 12:53:25 +0000 Vadim Pasternak <vadimp@mellanox.com> wrote:
>
> > The warning is caused by call to rorXX(), if the second parameters of
> > this function "shift" is zero. In such case UBSAN reports the warning
> > for the next expression: (word << (XX - shift), where XX is
> > 64, 32, 16, 8 for respectively ror64, ror32, ror16, ror8.
> > Fix adds validation of this parameter - in case it's equal zero, no
> > need to rotate, just original "word" is to be returned to caller.
> >
> > The UBSAN undefined behavior warning has been reported for call to
> > ror32():
> > [ 11.426543] UBSAN: Undefined behaviour in ./include/linux/bitops.h:93:33
> > [ 11.434045] shift exponent 32 is too large for 32-bit type 'unsigned int'
>
> hm, do we care?
>
> > ...
> >
>
> > --- a/include/linux/bitops.h
> > +++ b/include/linux/bitops.h
> > @@ -70,6 +70,9 @@ static inline __u64 rol64(__u64 word, unsigned int shift)
> > */
> > static inline __u64 ror64(__u64 word, unsigned int shift)
> > {
> > + if (!shift)
> > + return word;
> > +
> > return (word >> shift) | (word << (64 - shift));
> > }
>
> Is there any known architecture or compiler for which UL<<64 doesn't
> reliably produce zero? Is there any prospect that this will become a
> problem in the future?
Compiler is free to assume that shift !=0 after running ror64()... and
use that fact in optimalizations. so... if it is not problem today it
may easily become problem tommorow.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
prev parent reply other threads:[~2019-04-09 9:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-07 12:53 [PATCH v1 bitops] bitops: Fix UBSAN undefined behavior warning for rotation right Vadim Pasternak
2019-04-08 22:51 ` Andrew Morton
2019-04-08 22:52 ` Andrew Morton
2019-04-09 7:36 ` Vadim Pasternak
2019-04-09 8:08 ` Rasmus Villemoes
2019-04-09 8:57 ` Rasmus Villemoes
2019-04-09 9:50 ` Pavel Machek [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=20190409095041.GA32344@atrey.karlin.mff.cuni.cz \
--to=pavel@ucw.cz \
--cc=akpm@linux-foundation.org \
--cc=aryabinin@virtuozzo.com \
--cc=idosch@mellanox.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=vadimp@mellanox.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