Fix incorrect backports
Subsystems (2)
cover Fix incorrect backports
Eric Biggers (2):
Revert "crypto: jitterentropy - replace long-held spinlock with mutex" Revert "crypto: jitter - replace LFSR with SHA3-256"
Haixin Xu (1):
crypto: jitterentropy - replace long-held spinlock with mutex
crypto/Kconfig | 1 - crypto/jitterentropy-kcapi.c | 182 ++++------------------------------- crypto/jitterentropy.c | 145 +++++++++++++++++++--------- crypto/jitterentropy.h | 10 +- 4 files changed, 120 insertions(+), 218 deletions(-)
base-commit: 08889840163ebcdb7e24bf7ec311bc2e6fc3aaea
Signature · 1 line
2.56.0
PATCH 1/3 Revert "crypto: jitterentropy - replace long-held spinlock with mutex"
This reverts commit 21de77d06f6b540e870e64ef5ff56be4eb8ba08f.
This is needed to cleanly revert commit fc659f1a6903 ("crypto: jitter - replace LFSR with SHA3-256"). It will be reapplied.
--- crypto/jitterentropy-kcapi.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
crypto/jitterentropy-kcapi.c +7 -7
@@ -42,7 +42,6 @@#include <linux/fips.h> #include <linux/kernel.h> #include <linux/module.h> -#include <linux/mutex.h> #include <linux/slab.h> #include <linux/time.h> #include <crypto/internal/rng.h>
@@ -181,7 +180,7 @@ int jent_read_random_block(void *hash_state, char *dst, unsigned int dst_len)***************************************************************************/ struct jitterentropy { -struct mutex jent_lock; +spinlock_t jent_lock;struct rand_data *entropy_collector;struct crypto_shash *tfm;struct shash_desc *sdesc;
@@ -191,7 +190,7 @@ static void jent_kcapi_cleanup(struct crypto_tfm *tfm) {struct jitterentropy *rng =crypto_tfm_ctx (tfm); -mutex_lock (&rng->jent_lock); +spin_lock (&rng->jent_lock);if (rng->sdesc) {shash_desc_zero (rng->sdesc);
@@ -206,7 +205,7 @@ static void jent_kcapi_cleanup(struct crypto_tfm *tfm)if (rng->entropy_collector)jent_entropy_collector_free (rng->entropy_collector); rng->entropy_collector =NULL ; -mutex_unlock (&rng->jent_lock); +spin_unlock (&rng->jent_lock); }static int jent_kcapi_init (struct crypto_tfm *tfm)
@@ -216,7 +215,7 @@ static int jent_kcapi_init(struct crypto_tfm *tfm)struct shash_desc *sdesc;int size, ret =0 ; -mutex_init (&rng->jent_lock); +spin_lock_init (&rng->jent_lock);/* * Use SHA3-256 as conditioner. We allocate only the generic
@@ -251,6 +250,7 @@ static int jent_kcapi_init(struct crypto_tfm *tfm) goto err; } +spin_lock_init (&rng->jent_lock);return 0 ; err:
@@ -265,7 +265,7 @@ static int jent_kcapi_random(struct crypto_rng *tfm,struct jitterentropy *rng =crypto_rng_ctx (tfm);int ret =0 ; -mutex_lock (&rng->jent_lock); +spin_lock (&rng->jent_lock); ret =jent_read_entropy (rng->entropy_collector, rdata, dlen);
@@ -291,7 +291,7 @@ static int jent_kcapi_random(struct crypto_rng *tfm, ret = -EINVAL ; } -mutex_unlock (&rng->jent_lock); +spin_unlock (&rng->jent_lock);return ret; }
Signature · 1 line
2.56.0
PATCH 2/3 Revert "crypto: jitter - replace LFSR with SHA3-256"
In reply to Eric BiggersThis reverts commit fc659f1a690351c0d18ed76c24ca5c4204bfc973.
This commit is known-broken, does not meet the stable inclusion criteria, and has several follow-up fixes that were not included including fixes for a use-after-finalization bug and initialization failure on many systems. Note also that before v7.1, this code was sometimes used even when the kernel wasn't booted in fips mode. It was also accessible to unprivileged users via AF_ALG.
It was released in v6.1.191 kernel anyway, without Cc'ing the corresponding subsystem mailing list, and over my objection as well (after I happened to find the thread by searching lore -- see
https://lore.kernel.org/stable/20261029210038.GB49373@quark).
Revert it.
--- crypto/Kconfig | 1 - crypto/jitterentropy-kcapi.c | 183 ++++------------------------------- crypto/jitterentropy.c | 145 ++++++++++++++++++--------- crypto/jitterentropy.h | 10 +- 4 files changed, 120 insertions(+), 219 deletions(-)
crypto/Kconfig +0 -1
@@ -1279,7 +1279,6 @@ endif # if CRYPTO_DRBG_MENU config CRYPTO_JITTERENTROPY tristate "CPU Jitter Non-Deterministic RNG (Random Number Generator)" select CRYPTO_RNG - select CRYPTO_SHA3 help CPU Jitter RNG (Random Number Generator) from the Jitterentropy library
crypto/jitterentropy-kcapi.c +20 -163
246 lines not on this page · raw message
crypto/jitterentropy.c +97 -48
266 lines not on this page · raw message
crypto/jitterentropy.h +3 -7
@@ -2,18 +2,14 @@extern void *jent_zalloc (unsigned int len);extern void jent_zfree (void *ptr); +extern void jent_memcpy (void *dest,const void *src,unsigned int n);extern void jent_get_nstime (__u64 *out); -extern int jent_hash_time (void *hash_state,__u64 time,u8 *addtl, -unsigned int addtl_len,__u64 hash_loop_cnt, -unsigned int stuck); -int jent_read_random_block (void *hash_state,char *dst,unsigned int dst_len);struct rand_data ; -extern int jent_entropy_init (void *hash_state); +extern int jent_entropy_init (void );extern int jent_read_entropy (struct rand_data *ec,unsigned char *data,unsigned int len);extern struct rand_data *jent_entropy_collector_alloc (unsigned int osr, -unsigned int flags, -void *hash_state); +unsigned int flags);extern void jent_entropy_collector_free (struct rand_data *entropy_collector);
Signature · 1 line
2.56.0
PATCH 3/3 crypto: jitterentropy - replace long-held spinlock with mutex
In reply to Eric BiggersFrom: Haixin Xu <[email protected]>
commit 01d798e9feb30212952d4e992801ba6bd6a82351 upstream.
jent_kcapi_random() serializes the shared jitterentropy state, but it currently holds a spinlock across the jent_read_entropy() call. That path performs expensive jitter collection and SHA3 conditioning, so parallel readers can trigger stalls as contending waiters spin for the same lock.
To prevent non-preemptible lock hold, replace rng->jent_lock with a mutex so contended readers sleep instead of spinning on a shared lock held across expensive entropy generation.
[ebiggers: backported without commit bb897c55042e ("crypto: jitter -
replace LFSR with SHA3-256")]
--- crypto/jitterentropy-kcapi.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
crypto/jitterentropy-kcapi.c +7 -6
@@ -40,6 +40,7 @@#include <linux/fips.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/mutex.h> #include <linux/slab.h> #include <linux/time.h> #include <crypto/internal/rng.h>
@@ -96,7 +97,7 @@ void jent_get_nstime(__u64 *out)***************************************************************************/ struct jitterentropy { -spinlock_t jent_lock; +struct mutex jent_lock;struct rand_data *entropy_collector; };
@@ -109,7 +110,7 @@ static int jent_kcapi_init(struct crypto_tfm *tfm)if (!rng->entropy_collector) ret = -ENOMEM ; -spin_lock_init (&rng->jent_lock); +mutex_init (&rng->jent_lock);return ret; }
@@ -117,11 +118,11 @@ static void jent_kcapi_cleanup(struct crypto_tfm *tfm) {struct jitterentropy *rng =crypto_tfm_ctx (tfm); -spin_lock (&rng->jent_lock); +mutex_lock (&rng->jent_lock);if (rng->entropy_collector)jent_entropy_collector_free (rng->entropy_collector); rng->entropy_collector =NULL ; -spin_unlock (&rng->jent_lock); +mutex_unlock (&rng->jent_lock); } static int jent_kcapi_random(struct crypto_rng *tfm,
@@ -131,7 +132,7 @@ static int jent_kcapi_random(struct crypto_rng *tfm,struct jitterentropy *rng =crypto_rng_ctx (tfm);int ret =0 ; -spin_lock (&rng->jent_lock); +mutex_lock (&rng->jent_lock); ret =jent_read_entropy (rng->entropy_collector, rdata, dlen);
@@ -157,7 +158,7 @@ static int jent_kcapi_random(struct crypto_rng *tfm, ret = -EINVAL ; } -spin_unlock (&rng->jent_lock); +mutex_unlock (&rng->jent_lock);return ret; }
Signature · 1 line
2.56.0