From: Eric Biggers <ebiggers@kernel.org>
To: stable@vger.kernel.org
Cc: linux-crypto@vger.kernel.org, Haixin Xu <jerryxucs@gmail.com>,
Yifan Wu <yifanwucs@gmail.com>,
Juefei Pu <tomapufckgml@gmail.com>,
Yuan Tan <yuantan098@gmail.com>, Xin Liu <bird@lzu.edu.cn>,
Stephan Mueller <smueller@chronox.de>,
Herbert Xu <herbert@gondor.apana.org.au>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 6.1 3/3] crypto: jitterentropy - replace long-held spinlock with mutex
Date: Fri, 30 Oct 2026 10:02:20 -0700 [thread overview]
Message-ID: <20261030170220.120015-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20261030170220.120015-1-ebiggers@kernel.org>
From: Haixin Xu <jerryxucs@gmail.com>
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.
Fixes: bb5530e40824 ("crypto: jitterentropy - add jitterentropy RNG")
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Reported-by: Yuan Tan <yuantan098@gmail.com>
Suggested-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Haixin Xu <jerryxucs@gmail.com>
Reviewed-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[ebiggers: backported without commit bb897c55042e ("crypto: jitter -
replace LFSR with SHA3-256")]
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
crypto/jitterentropy-kcapi.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c
index b9edfaa51b273..29c830b47c5e2 100644
--- a/crypto/jitterentropy-kcapi.c
+++ b/crypto/jitterentropy-kcapi.c
@@ -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;
}
--
2.56.0
prev parent reply other threads:[~2026-10-30 17:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 17:02 [PATCH 6.1 0/3] Fix incorrect backports Eric Biggers
2026-10-30 17:02 ` [PATCH 6.1 1/3] Revert "crypto: jitterentropy - replace long-held spinlock with mutex" Eric Biggers
2026-10-30 17:02 ` [PATCH 6.1 2/3] Revert "crypto: jitter - replace LFSR with SHA3-256" Eric Biggers
2026-10-30 17:02 ` Eric Biggers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261030170220.120015-4-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=bird@lzu.edu.cn \
--cc=herbert@gondor.apana.org.au \
--cc=jerryxucs@gmail.com \
--cc=linux-crypto@vger.kernel.org \
--cc=smueller@chronox.de \
--cc=stable@vger.kernel.org \
--cc=tomapufckgml@gmail.com \
--cc=yifanwucs@gmail.com \
--cc=yuantan098@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox