public inbox for linux-um@lists.infradead.org
 help / color / mirror / Atom feed
* jitterentropy vs. simulation
@ 2023-12-01 10:21 Johannes Berg
  2023-12-01 18:03 ` Anton Ivanov
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2023-12-01 10:21 UTC (permalink / raw)
  To: Stephan Müller; +Cc: linux-um, linux-crypto

Hi,

In ARCH=um, we have a mode where we simulate clocks completely, and even
simulate that the CPU is infinitely fast. Thus, reading the clock will
return completely predictable values regardless of the work happening.

This is clearly incompatible with jitterentropy, but now jitterentropy
seems to be mandatory on pretty much every system that needs any crypto,
so we can't just seem to turn it off (any more?)

Now given that the (simulated) clock doesn't have jitter, it's derivates
are all constant/zero, and so jent_measure_jitter() - called via
jent_entropy_collector_alloc() - will always detect a stuck measurement,
and thus jent_gen_entropy() loops infinitely.

I wonder what you'd think about a patch like this?

--- a/crypto/jitterentropy.c
+++ b/crypto/jitterentropy.c
@@ -552,10 +552,13 @@ static int jent_measure_jitter(struct rand_data *ec, __u64 *ret_current_delta)
  * Function fills rand_data->hash_state
  *
  * @ec [in] Reference to entropy collector
+ *
+ * Return: 0 if entropy reading failed (was stuck), 1 otherwise
  */
-static void jent_gen_entropy(struct rand_data *ec)
+static int jent_gen_entropy(struct rand_data *ec)
 {
 	unsigned int k = 0, safety_factor = 0;
+	unsigned int stuck_counter = 0;
 
 	if (fips_enabled)
 		safety_factor = JENT_ENTROPY_SAFETY_FACTOR;
@@ -565,8 +568,13 @@ static void jent_gen_entropy(struct rand_data *ec)
 
 	while (!jent_health_failure(ec)) {
 		/* If a stuck measurement is received, repeat measurement */
-		if (jent_measure_jitter(ec, NULL))
+		if (jent_measure_jitter(ec, NULL)) {
+			if (stuck_counter++ > 100)
+				return 0;
 			continue;
+		}
+
+		stuck_counter = 0;
 
 		/*
 		 * We multiply the loop value with ->osr to obtain the
@@ -575,6 +583,8 @@ static void jent_gen_entropy(struct rand_data *ec)
 		if (++k >= ((DATA_SIZE_BITS + safety_factor) * ec->osr))
 			break;
 	}
+
+	return 1;
 }
 
 /*
@@ -611,7 +621,8 @@ int jent_read_entropy(struct rand_data *ec, unsigned char *data,
 	while (len > 0) {
 		unsigned int tocopy, health_test_result;
 
-		jent_gen_entropy(ec);
+		if (!jent_gen_entropy(ec))
+			return -3;
 
 		health_test_result = jent_health_failure(ec);
 		if (health_test_result > JENT_PERMANENT_FAILURE_SHIFT) {


johannes

_______________________________________________
linux-um mailing list
linux-um@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-um

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-04 12:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01 10:21 jitterentropy vs. simulation Johannes Berg
2023-12-01 18:03 ` Anton Ivanov
2023-12-01 18:35   ` Johannes Berg
2023-12-01 19:25     ` Simo Sorce
2023-12-01 20:04       ` Johannes Berg
2023-12-04  8:52     ` Stephan Mueller
2023-12-04 10:24       ` Johannes Berg
2023-12-04 10:35         ` Stephan Mueller
2023-12-04 12:06     ` Benjamin Beichler
2023-12-04 12:50       ` Anton Ivanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox