Re: random: ensure use of aligned buffers with ChaCha20

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 10, 2018 at 08:20:51AM +0200, Stephan Mueller wrote:
> > 	while (nbytes >= CHACHA20_BLOCK_SIZE) {
> > 		int adjust = (unsigned long)buf & (sizeof(tmp[0]) - 1);
> > 
> > 		extract_crng(buf);
> 
> Why this line?
> 
> > 		buf += CHACHA20_BLOCK_SIZE;

Sorry, the above two lines should be removed, of course.

> > 		if (likely(adjust == 0)) {
> > 			extract_crng(buf);
> > 			buf += CHACHA20_BLOCK_SIZE;
> > 			nbytes -= CHACHA20_BLOCK_SIZE;
> > 		} else {
> > 			extract_crng(tmp);
> > 			memcpy(buf, tmp, CHACHA20_BLOCK_SIZE - adjust);
> > 			buf += CHACHA20_BLOCK_SIZE - adjust;
> > 			nbytes -= CHACHA20_BLOCK_SIZE - adjust;
> 
> Sure, why not.
> 
> > 		}
> > 
> > 	}
> > 
> > This may be a hyper optimization, though --- it's not clear how often,
> > say the kernel would be calling get_random_bytes with size >> 64 at
> > all, never mind with an unaligned buffer.
> 
> I agree it is not likely that we have unaligned buffers. But in case we have, 
> we have the potential to overwrite memory that does not belong to us with 
> unknown consequences.

Sure, faire enough.  The potential wouldn't be overwriting memory,
though.  It would be a kernel panic when the CPU trapped a non-aligned
pointer dereference.

						- Ted
						



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux