linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Vadim Pasternak <vadimp@mellanox.com>
Cc: jacek.anaszewski@gmail.com, pavel@ucw.cz,
	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: Mon, 8 Apr 2019 15:52:17 -0700	[thread overview]
Message-ID: <20190408155217.3f723554ae7fbcb34eeacb30@linux-foundation.org> (raw)
In-Reply-To: <20190407125325.24440-1-vadimp@mellanox.com>

(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?


  parent reply	other threads:[~2019-04-08 22:52 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 [this message]
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

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=20190408155217.3f723554ae7fbcb34eeacb30@linux-foundation.org \
    --to=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=pavel@ucw.cz \
    --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;
as well as URLs for NNTP newsgroup(s).