[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <544A52D7.6000202@oracle.com>
Date: Fri, 24 Oct 2014 09:23:35 -0400
From: Sasha Levin <sasha.levin@...cle.com>
To: Peter Zijlstra <peterz@...radead.org>,
"Theodore Ts'o" <tytso@....edu>,
Daniel Borkmann <dborkman@...hat.com>,
Andrey Ryabinin <a.ryabinin@...sung.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>, Michal Marek <mmarek@...e.cz>,
x86@...nel.org, linux-kbuild@...r.kernel.org,
linux-kernel@...r.kernel.org,
Andreas Dilger <adilger.kernel@...ger.ca>,
Dmitry Vyukov <dvyukov@...gle.com>,
Konstantin Khlebnikov <koct9i@...il.com>
Subject: Re: drivers: random: Shift out-of-bounds in _mix_pool_bytes
On 10/24/2014 06:01 AM, Peter Zijlstra wrote:
> On Mon, Oct 20, 2014 at 10:16:35AM -0400, Theodore Ts'o wrote:
>> > On Mon, Oct 20, 2014 at 04:09:30PM +0200, Daniel Borkmann wrote:
>>>> > > >
>>>> > > >It's triggering when input_rotate == 0, so UBSan complains about right shift in rol32()
>>>> > > >
>>>> > > >static inline __u32 rol32(__u32 word, unsigned int shift)
>>>> > > >{
>>>> > > > return (word << shift) | (word >> (32 - shift));
>>>> > > >}
>>> > >
>>> > > So that would be the case when the entropy store's input_rotate calls
>>> > > _mix_pool_bytes() for the very first time ... I don't think it's an
>>> > > issue though.
>> >
>> > I'm sure it's not an issue, but it's still true that
>> >
>> > return (word << 0) | (word >> 32);
>> >
>> > is technically not undefined, and while it would be unfortunate (and
>> > highly unlikely) if gcc were to say, start nethack, it's technically
>> > allowed by the C spec. :-)
> In fact, n >> 32 == n.
>
> #include <stdio.h>
>
> int main(int argc, char **argv)
> {
> int i = atoi(argv[1]);
> int shift = atoi(argv[2]);
> printf("%x\n", i >> shift);
> return 0;
> }
>
> $ ./shift 5 32
> 5
>
> On x86 at least the shift ops simply mask out the upper bits and
> therefore the 32 == 0.
>
> So you end up OR-ing the same value twice, which is harmless.
>
> So no misbehaviour on the rol32() function.
>
> I think I've ran into this before, in that case I did get fail because I
> did indeed expect the 0 and things didn't work out.
i >> 32 may happen to be "i", but is there anything that prevents the compiler
from returning, let's say, 42?
Thanks,
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists