|
| 1 | +From d0e139f4e697265cd693769860b20d61c89bbd96 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Tobias Brick <tobiasb@microsoft.com> |
| 3 | +Date: Wed, 3 Jul 2024 20:24:14 +0000 |
| 4 | +Subject: [PATCH] TOBIASB: Initialize ec.mem and set minimum OSR in |
| 5 | + jent_time_entropy_init |
| 6 | + |
| 7 | +Ocassionally, the jitterentropy module was failing the FIPS self-test because it was unable to create |
| 8 | +sufficient entropy. This was due to two main reasons: |
| 9 | +A memory buffer was not being initialized in the jent_time_entropy_init function. This buffer is used |
| 10 | +to add variations based on memory access to the entropy pool. |
| 11 | + |
| 12 | +The OSR value was being set to 1, rather than the standard minimum of 3. Since this affects the threshold |
| 13 | +for number of times the allows itself to attempt to generate entropy before failing out, this made the issue |
| 14 | +more likely to occur. |
| 15 | + |
| 16 | +This patch initializes that buffer and enforces the standard minmum OSR value. |
| 17 | + |
| 18 | +--- |
| 19 | + crypto/fips/jitterentropy-base.c | 19 ++++++++++++++++++- |
| 20 | + 1 file changed, 18 insertions(+), 1 deletion(-) |
| 21 | + |
| 22 | +diff --git a/crypto/fips/jitterentropy-base.c b/crypto/fips/jitterentropy-base.c |
| 23 | +index 9fb5b96..a5079a0 100644 |
| 24 | +--- a/crypto/fips/jitterentropy-base.c |
| 25 | ++++ b/crypto/fips/jitterentropy-base.c |
| 26 | +@@ -1265,13 +1265,27 @@ static int jent_time_entropy_init(unsigned int enable_notime) |
| 27 | + |
| 28 | + memset(&ec, 0, sizeof(ec)); |
| 29 | + |
| 30 | ++ /* Allocate memory for adding variations based on memory |
| 31 | ++ * access |
| 32 | ++ */ |
| 33 | ++ ec.mem = |
| 34 | ++ (unsigned char *)jent_zalloc(JENT_MEMORY_SIZE); |
| 35 | ++ if (ec.mem == NULL) { |
| 36 | ++ ret = EHEALTH; |
| 37 | ++ goto out; |
| 38 | ++ } |
| 39 | ++ |
| 40 | ++ ec.memblocksize = JENT_MEMORY_BLOCKSIZE; |
| 41 | ++ ec.memblocks = JENT_MEMORY_BLOCKS; |
| 42 | ++ ec.memaccessloops = JENT_MEMORY_ACCESSLOOPS; |
| 43 | ++ |
| 44 | + if (enable_notime) { |
| 45 | + ec.enable_notime = 1; |
| 46 | + jent_notime_settick(&ec); |
| 47 | + } |
| 48 | + |
| 49 | + /* Required for RCT */ |
| 50 | +- ec.osr = 1; |
| 51 | ++ ec.osr = JENT_MIN_OSR; |
| 52 | + if (jent_fips_enabled()) |
| 53 | + ec.fips_enabled = 1; |
| 54 | + |
| 55 | +@@ -1429,6 +1443,9 @@ static int jent_time_entropy_init(unsigned int enable_notime) |
| 56 | + ret = ESTUCK; |
| 57 | + |
| 58 | + out: |
| 59 | ++ if (ec.mem != NULL) |
| 60 | ++ jent_zfree(ec.mem, JENT_MEMORY_SIZE); |
| 61 | ++ |
| 62 | + if (enable_notime) |
| 63 | + jent_notime_unsettick(&ec); |
| 64 | + |
| 65 | +-- |
| 66 | +2.39.4 |
| 67 | + |
0 commit comments