Module Name:    src
Committed By:   riastradh
Date:           Sat May 21 14:59:45 UTC 2016

Modified Files:
        src/sys/rump/librump/rumpkern: hyperentropy.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/rump/librump/rumpkern/hyperentropy.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/librump/rumpkern/hyperentropy.c
diff -u src/sys/rump/librump/rumpkern/hyperentropy.c:1.14 src/sys/rump/librump/rumpkern/hyperentropy.c:1.15
--- src/sys/rump/librump/rumpkern/hyperentropy.c:1.14	Wed Feb 17 01:48:36 2016
+++ src/sys/rump/librump/rumpkern/hyperentropy.c	Sat May 21 14:59:45 2016
@@ -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 @@ static void
 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);

Reply via email to