mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Neil Horman' <nhorman@tuxdriver.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Steve Grubb <sgrubb@redhat.com>, Theodore Ts'o <tytso@mit.edu>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: RE: [PATCH] Fix xoring of arch_get_random_long into crng->state array
Date: Wed, 29 May 2019 15:57:07 +0000	[thread overview]
Message-ID: <a3b2a53687004601873914931e9ee75a@AcuMS.aculab.com> (raw)
In-Reply-To: <20190529155156.GB31099@hmswarspite.think-freely.org>

From: Neil Horman [mailto:nhorman@tuxdriver.com]
> Sent: 29 May 2019 16:52
> On Wed, May 29, 2019 at 01:51:24PM +0000, David Laight wrote:
> > From: Neil Horman
> > > Sent: 29 May 2019 14:42
> > > On Tue, Apr 02, 2019 at 06:00:25PM -0400, Neil Horman wrote:
> > > > When _crng_extract is called, any arch that has a registered
> > > > arch_get_random_long method, attempts to mix an unsigned long value into
> > > > the crng->state buffer, it only mixes in 32 of the 64 bits available,
> > > > because the state buffer is an array of u32 values, even though 2 u32
> > > > are expected to be filled (owing to the fact that it expects indexes 14
> > > > and 15 to be filled).
> > > >
> > > > Bring the expected behavior into alignment by casting index 14 to an
> > > > unsignled long pointer, and xoring that in instead.
> > ...
> > > > diff --git a/drivers/char/random.c b/drivers/char/random.c
> > > > index 38c6d1af6d1c..8178618458ac 100644
> > > > --- a/drivers/char/random.c
> > > > +++ b/drivers/char/random.c
> > > > @@ -975,14 +975,16 @@ static void _extract_crng(struct crng_state *crng,
> > > >  			  __u8 out[CHACHA_BLOCK_SIZE])
> > > >  {
> > > >  	unsigned long v, flags;
> > > > -
> > > > +	unsigned long *archrnd;
> > > >  	if (crng_ready() &&
> > > >  	    (time_after(crng_global_init_time, crng->init_time) ||
> > > >  	     time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL)))
> > > >  		crng_reseed(crng, crng == &primary_crng ? &input_pool : NULL);
> > > >  	spin_lock_irqsave(&crng->lock, flags);
> > > > -	if (arch_get_random_long(&v))
> > > > -		crng->state[14] ^= v;
> > > > +	if (arch_get_random_long(&v)) {
> > > > +		archrnd = (unsigned long *)&crng->state[14];
> > > > +		*archrnd ^= v;
> > > > +	}
> >
> > Isn't that likely to generate a misaligned memory access?
> >
> I'm not quite sure how it would, crng->state is an array of _u32's, and so every
> even element should be on a 64 bit boundary.

Only if the first item is aligned....
Add a u32 before it and you'll probably flip the alignment.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


  reply	other threads:[~2019-05-29 15:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 22:00 Neil Horman
2019-05-29 13:42 ` Neil Horman
2019-05-29 13:51   ` David Laight
2019-05-29 15:51     ` Neil Horman
2019-05-29 15:57       ` David Laight [this message]
2019-05-29 16:27         ` Neil Horman
2019-05-30  3:12 ` Theodore Ts'o
2019-05-30 11:14   ` Neil Horman

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=a3b2a53687004601873914931e9ee75a@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=sgrubb@redhat.com \
    --cc=tytso@mit.edu \
    /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

Powered by JetHome