Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Oct 2018 21:03:57 +0000 (UTC)
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r339790 - head/sys/dev/random
Message-ID:  <201810262103.w9QL3vJe091349@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Fri Oct 26 21:03:57 2018
New Revision: 339790
URL: https://svnweb.freebsd.org/changeset/base/339790

Log:
  Fortuna: Add failpoints to simulate initial seeding conditions
  
  Set debug.fail_point.random_fortuna_pre_read=return(1) and
  debug.fail_point.random_fortuna_seeded=return(1) to return to unseeded
  status (sort of).  See the Differential URL for more detail.
  
  The goal is to reproduce e.g. Lev's recent CURRENT report[1] about failing
  newfs arc4random(3) usage (fixed in r338542).
  
  No functional change when failpoints are not set.
  
  [1]: https://lists.freebsd.org/pipermail/freebsd-current/2018-September/071067.html
  
  Reported by:	lev
  Reviewed by:	delphij, markm
  Approved by:	secteam (delphij)
  Sponsored by:	Dell EMC Isilon
  Differential Revision:	https://reviews.freebsd.org/D17047

Modified:
  head/sys/dev/random/fortuna.c

Modified: head/sys/dev/random/fortuna.c
==============================================================================
--- head/sys/dev/random/fortuna.c	Fri Oct 26 21:00:26 2018	(r339789)
+++ head/sys/dev/random/fortuna.c	Fri Oct 26 21:03:57 2018	(r339790)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
 
 #ifdef _KERNEL
 #include <sys/param.h>
+#include <sys/fail.h>
 #include <sys/kernel.h>
 #include <sys/lock.h>
 #include <sys/malloc.h>
@@ -385,6 +386,18 @@ random_fortuna_pre_read(void)
 	}
 
 #ifdef _KERNEL
+	/*
+	 * When set, pretend we do not have enough entropy to reseed yet.
+	 */
+	KFAIL_POINT_CODE(DEBUG_FP, random_fortuna_pre_read, {
+		if (RETURN_VALUE != 0) {
+			RANDOM_RESEED_UNLOCK();
+			return;
+		}
+	});
+#endif
+
+#ifdef _KERNEL
 	fortuna_state.fs_lasttime = now;
 #endif
 
@@ -441,6 +454,14 @@ random_fortuna_read(uint8_t *buf, u_int bytecount)
 bool
 random_fortuna_seeded(void)
 {
+
+#ifdef _KERNEL
+	/* When set, act as if we are not seeded. */
+	KFAIL_POINT_CODE(DEBUG_FP, random_fortuna_seeded, {
+		if (RETURN_VALUE != 0)
+			fortuna_state.fs_counter = UINT128_ZERO;
+	});
+#endif
 
 	return (!uint128_is_zero(fortuna_state.fs_counter));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201810262103.w9QL3vJe091349>