Source-Changes-HG archive

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

[src/trunk]: src/sys/rump/librump/rumpkern Actually get as many bytes as requ...



details:   https://anonhg.NetBSD.org/src/rev/d2862611b399
branches:  trunk
changeset: 345351:d2862611b399
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat May 21 14:59:45 2016 +0000

description:
Actually get as many bytes as requested from rumpuser_random.

rumpuser_random is limited to 32 bytes at a time -- which would be
reasonable, except that there are too many buffers in the way between
entropy sources and users of the entropy pool.

Partial fix for PR kern/51135.

diffstat:

 sys/rump/librump/rumpkern/hyperentropy.c |  19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)

diffs (43 lines):

diff -r 7b825b020ba0 -r d2862611b399 sys/rump/librump/rumpkern/hyperentropy.c
--- a/sys/rump/librump/rumpkern/hyperentropy.c  Sat May 21 12:39:32 2016 +0000
+++ b/sys/rump/librump/rumpkern/hyperentropy.c  Sat May 21 14:59:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperentropy.c,v 1.14 2016/02/17 01:48:36 riastradh Exp $      */
+/*     $NetBSD: hyperentropy.c,v 1.15 2016/05/21 14:59:45 riastradh Exp $      */
 
 /*
  * Copyright (c) 2014 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hyperentropy.c,v 1.14 2016/02/17 01:48:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperentropy.c,v 1.15 2016/05/21 14:59:45 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -46,13 +46,20 @@
 feedrandom(size_t bytes, void *cookie __unused)
 {
        uint8_t *rnddata;
-       size_t dsize;
+       size_t n, nread;
 
        rnddata = kmem_intr_alloc(MAXGET, KM_SLEEP);
-       if (rumpuser_getrandom(rnddata, MIN(MAXGET, bytes),
-           RUMPUSER_RANDOM_HARD|RUMPUSER_RANDOM_NOWAIT, &dsize) == 0) {
+       n = 0;
+       while (n < MIN(MAXGET, bytes)) {
+               if (rumpuser_getrandom(rnddata + n, MIN(MAXGET, bytes) - n,
+                       RUMPUSER_RANDOM_HARD|RUMPUSER_RANDOM_NOWAIT, &nread)
+                   != 0)
+                       break;
+               n += MIN(nread, MIN(MAXGET, bytes) - n);
+       }
+       if (n) {
                mutex_enter(&rndsrc_lock);
-               rnd_add_data_sync(&rndsrc, rnddata, dsize, NBBY*dsize);
+               rnd_add_data_sync(&rndsrc, rnddata, n, NBBY*n);
                mutex_exit(&rndsrc_lock);
        }
        kmem_intr_free(rnddata, MAXGET);



Home | Main Index | Thread Index | Old Index