From: "H. Peter Anvin" <hpa@zytor.com>
To: One Thousand Gnomes <gnomes@lxorguk.ukuu.org.uk>,
Dmitry Vyukov <dvyukov@google.com>
Cc: Sasha Levin <sasha.levin@oracle.com>,
Peter Zijlstra <peterz@infradead.org>,
Theodore Ts'o <tytso@mit.edu>,
Daniel Borkmann <dborkman@redhat.com>,
Andrey Ryabinin <a.ryabinin@samsung.com>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Michal Marek <mmarek@suse.cz>,
"x86@kernel.org" <x86@kernel.org>,
linux-kbuild@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
Andreas Dilger <adilger.kernel@dilger.ca>,
Konstantin Khlebnikov <koct9i@gmail.com>
Subject: Re: drivers: random: Shift out-of-bounds in _mix_pool_bytes
Date: Fri, 24 Oct 2014 15:23:40 -0700 [thread overview]
Message-ID: <544AD16C.40904@zytor.com> (raw)
In-Reply-To: <20141024220502.54cac82d@alan.etchedpixels.co.uk>
On 10/24/2014 02:05 PM, One Thousand Gnomes wrote:
> On Fri, 24 Oct 2014 19:10:49 +0400
> Dmitry Vyukov <dvyukov@google.com> wrote:
>
>> On Fri, Oct 24, 2014 at 7:04 PM, Sasha Levin <sasha.levin@oracle.com> wrote:
>>> On 10/24/2014 09:42 AM, Peter Zijlstra wrote:
>>>> On Fri, Oct 24, 2014 at 09:23:35AM -0400, Sasha Levin wrote:
>>>>>
>>>>> i >> 32 may happen to be "i", but is there anything that prevents the compiler
>>>>> from returning, let's say, 42?
>>>>
>>>> Not really, although gcc seems to opt for the 'sane' option and emit the
>>>> instruction and let the arch figure out how to deal with it. Hence the
>>>> 'fun' difference between x86 and ARM.
>>>
>>> It's interesting how many different views on undefined behaviour there are between
>>> kernel folks.
>>>
>>> Everything between Ted Ts'o saying that GCC can launch nethack on oversized shifts,
>>> to DaveM saying he will file a GCC bug if the behaviour isn't sane w.r.t to memcpy().
>>
>> One of the benefits of fixing such issues (or not letting them into
>> code in the first place) is just saving numerous hours of top-notch
>> engineers spent on disputes like this.
>
> Also it means when someone quietly changes the default behaviour next
> year in the compiler they won't spend months trying to work out why it
> broke.
>
> gcc has one behaviour but people also try and build the kernel with icc
> and with llvm. In addition in some cases you risk the compiler simply
> generating an undefined in hardware operation and the hardware behaviour
> changing. If x >> 32 is undefined then generating "load Y with the
> shift, shift X left by Y" is fine. What happens in future silicon - who
> knows.
>
> Most of the kernel is already very careful about the >> 32 problem.
>
The real question is if we can rely on the gcc-ism:
(x >> (S-y)) | (x << y)
... where S is the number of bits to indicate a rotate.
This is technically a gcc extension to the C language.
-hpa
next prev parent reply other threads:[~2014-10-24 22:24 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-20 10:54 [RFC] UBSan: run-time undefined behavior sanity checker Andrey Ryabinin
2014-10-20 10:54 ` [RFC PATCH] " Andrey Ryabinin
2014-10-20 19:35 ` Sasha Levin
2014-10-21 8:03 ` Andrey Ryabinin
2014-10-24 8:31 ` y.gribov
2014-10-24 10:36 ` Andrey Ryabinin
2014-10-21 9:47 ` Peter Zijlstra
2014-10-21 10:09 ` Andrey Ryabinin
2014-10-24 10:30 ` Peter Zijlstra
2014-10-21 17:06 ` Randy Dunlap
2014-10-22 9:58 ` Rasmus Villemoes
2014-10-22 11:16 ` Andrey Ryabinin
2014-10-20 11:03 ` drivers: random: Shift out-of-bounds in _mix_pool_bytes Andrey Ryabinin
2014-10-20 12:49 ` Theodore Ts'o
2014-10-20 13:58 ` Andrey Ryabinin
2014-10-20 14:08 ` Theodore Ts'o
2014-10-20 14:09 ` Daniel Borkmann
2014-10-20 14:13 ` Sasha Levin
2014-10-20 14:16 ` Theodore Ts'o
2014-10-20 14:42 ` Andrey Ryabinin
2014-10-24 10:01 ` Peter Zijlstra
2014-10-24 10:16 ` Andrey Ryabinin
2014-10-24 13:23 ` Sasha Levin
2014-10-24 13:42 ` Peter Zijlstra
2014-10-24 15:04 ` Sasha Levin
2014-10-24 15:10 ` Dmitry Vyukov
2014-10-24 21:05 ` One Thousand Gnomes
2014-10-24 22:23 ` H. Peter Anvin [this message]
2014-10-24 22:09 ` Andreas Dilger
2014-10-24 22:22 ` H. Peter Anvin
2014-10-25 0:50 ` Sasha Levin
2014-10-25 20:30 ` One Thousand Gnomes
2014-10-25 20:49 ` Andrey Ryabinin
2014-10-20 11:07 ` kernel: clockevents: shift out-of-bounds Andrey Ryabinin
2014-10-24 10:25 ` Peter Zijlstra
2014-10-20 11:16 ` fs: ext4: mballoc: negative shift exponent Andrey Ryabinin
2014-10-20 11:23 ` jbd2: revoke: negative shift exponent in hash() Andrey Ryabinin
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=544AD16C.40904@zytor.com \
--to=hpa@zytor.com \
--cc=a.ryabinin@samsung.com \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=dborkman@redhat.com \
--cc=dvyukov@google.com \
--cc=gnomes@lxorguk.ukuu.org.uk \
--cc=koct9i@gmail.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mmarek@suse.cz \
--cc=peterz@infradead.org \
--cc=sasha.levin@oracle.com \
--cc=tglx@linutronix.de \
--cc=tytso@mit.edu \
--cc=x86@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.