From: Greg Kroah-Hartman Date: Tue, 21 Jul 2026 10:01:17 +0000 (+0200) Subject: 6.18-stable patches X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ca03792dad9dd5968cae09495cae76b91f1cfa1;p=thirdparty%2Fkernel%2Fstable-queue.git 6.18-stable patches added patches: crypto-xilinx-trng-remove-crypto_rng-interface.patch --- diff --git a/queue-6.18/crypto-xilinx-trng-remove-crypto_rng-interface.patch b/queue-6.18/crypto-xilinx-trng-remove-crypto_rng-interface.patch new file mode 100644 index 0000000000..ddbcb75d6a --- /dev/null +++ b/queue-6.18/crypto-xilinx-trng-remove-crypto_rng-interface.patch @@ -0,0 +1,194 @@ +From 32b4d29280ed2a991dc196d5845b892acedc63b8 Mon Sep 17 00:00:00 2001 +From: Eric Biggers +Date: Sun, 31 May 2026 12:17:35 -0700 +Subject: crypto: xilinx-trng - Remove crypto_rng interface + +From: Eric Biggers + +commit 32b4d29280ed2a991dc196d5845b892acedc63b8 upstream. + +Implementing the crypto_rng interface has no purpose, as it isn't used +in practice. It's being removed from other drivers too. Just remove +it. This leaves hwrng, which is actually used. + +Tagging with 'Cc stable' due to the bugs that this removes: + + - xtrng_trng_generate() sometimes returned success even when it didn't + fill in all the bytes. + + - It was possible for xtrng_trng_generate() and + xtrng_hwrng_trng_read() to run concurrently and interfere with each + other, as the locking code in xtrng_hwrng_trng_read() was broken. + +Fixes: 8979744aca80 ("crypto: xilinx - Add TRNG driver for Versal") +Cc: stable@vger.kernel.org +Signed-off-by: Eric Biggers +Signed-off-by: Herbert Xu +Signed-off-by: Greg Kroah-Hartman +--- + drivers/crypto/Kconfig | 1 + drivers/crypto/xilinx/xilinx-trng.c | 75 ------------------------------------ + 2 files changed, 1 insertion(+), 75 deletions(-) + +--- a/drivers/crypto/Kconfig ++++ b/drivers/crypto/Kconfig +@@ -728,7 +728,6 @@ config CRYPTO_DEV_TEGRA + config CRYPTO_DEV_XILINX_TRNG + tristate "Support for Xilinx True Random Generator" + depends on ZYNQMP_FIRMWARE || COMPILE_TEST +- select CRYPTO_RNG + select HW_RANDOM + help + Xilinx Versal SoC driver provides kernel-side support for True Random Number +--- a/drivers/crypto/xilinx/xilinx-trng.c ++++ b/drivers/crypto/xilinx/xilinx-trng.c +@@ -6,7 +6,6 @@ + + #include + #include +-#include + #include + #include + #include +@@ -15,12 +14,10 @@ + #include + #include + #include +-#include + #include + #include + #include + #include +-#include + #include + + /* TRNG Registers Offsets */ +@@ -59,16 +56,9 @@ + struct xilinx_rng { + void __iomem *rng_base; + struct device *dev; +- struct mutex lock; /* Protect access to TRNG device */ + struct hwrng trng; + }; + +-struct xilinx_rng_ctx { +- struct xilinx_rng *rng; +-}; +- +-static struct xilinx_rng *xilinx_rng_dev; +- + static void xtrng_readwrite32(void __iomem *addr, u32 mask, u8 value) + { + u32 val; +@@ -235,47 +225,6 @@ static int xtrng_random_bytes_generate(s + return nbytes; + } + +-static int xtrng_trng_generate(struct crypto_rng *tfm, const u8 *src, u32 slen, +- u8 *dst, u32 dlen) +-{ +- struct xilinx_rng_ctx *ctx = crypto_rng_ctx(tfm); +- int ret; +- +- mutex_lock(&ctx->rng->lock); +- ret = xtrng_random_bytes_generate(ctx->rng, dst, dlen, true); +- mutex_unlock(&ctx->rng->lock); +- +- return ret < 0 ? ret : 0; +-} +- +-static int xtrng_trng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen) +-{ +- return 0; +-} +- +-static int xtrng_trng_init(struct crypto_tfm *rtfm) +-{ +- struct xilinx_rng_ctx *ctx = crypto_tfm_ctx(rtfm); +- +- ctx->rng = xilinx_rng_dev; +- +- return 0; +-} +- +-static struct rng_alg xtrng_trng_alg = { +- .generate = xtrng_trng_generate, +- .seed = xtrng_trng_seed, +- .seedsize = 0, +- .base = { +- .cra_name = "stdrng", +- .cra_driver_name = "xilinx-trng", +- .cra_priority = 300, +- .cra_ctxsize = sizeof(struct xilinx_rng_ctx), +- .cra_module = THIS_MODULE, +- .cra_init = xtrng_trng_init, +- }, +-}; +- + static int xtrng_hwrng_trng_read(struct hwrng *hwrng, void *data, size_t max, bool wait) + { + u8 buf[TRNG_SEC_STRENGTH_BYTES]; +@@ -283,12 +232,6 @@ static int xtrng_hwrng_trng_read(struct + int ret = -EINVAL, i = 0; + + rng = container_of(hwrng, struct xilinx_rng, trng); +- /* Return in case wait not set and lock not available. */ +- if (!mutex_trylock(&rng->lock) && !wait) +- return 0; +- else if (!mutex_is_locked(&rng->lock) && wait) +- mutex_lock(&rng->lock); +- + while (i < max) { + ret = xtrng_random_bytes_generate(rng, buf, TRNG_SEC_STRENGTH_BYTES, wait); + if (ret < 0) +@@ -297,8 +240,6 @@ static int xtrng_hwrng_trng_read(struct + memcpy(data + i, buf, min_t(int, ret, (max - i))); + i += min_t(int, ret, (max - i)); + } +- mutex_unlock(&rng->lock); +- + return ret; + } + +@@ -344,26 +285,14 @@ static int xtrng_probe(struct platform_d + return ret; + } + +- xilinx_rng_dev = rng; +- mutex_init(&rng->lock); +- ret = crypto_register_rng(&xtrng_trng_alg); +- if (ret) { +- dev_err(&pdev->dev, "Crypto Random device registration failed: %d\n", ret); +- return ret; +- } + ret = xtrng_hwrng_register(&rng->trng); + if (ret) { + dev_err(&pdev->dev, "HWRNG device registration failed: %d\n", ret); +- goto crypto_rng_free; ++ return ret; + } + platform_set_drvdata(pdev, rng); + + return 0; +- +-crypto_rng_free: +- crypto_unregister_rng(&xtrng_trng_alg); +- +- return ret; + } + + static void xtrng_remove(struct platform_device *pdev) +@@ -373,13 +302,11 @@ static void xtrng_remove(struct platform + + rng = platform_get_drvdata(pdev); + xtrng_hwrng_unregister(&rng->trng); +- crypto_unregister_rng(&xtrng_trng_alg); + xtrng_write_multiple_registers(rng->rng_base + TRNG_EXT_SEED_OFFSET, zero, + TRNG_NUM_INIT_REGS); + xtrng_write_multiple_registers(rng->rng_base + TRNG_PER_STRNG_OFFSET, zero, + TRNG_NUM_INIT_REGS); + xtrng_hold_reset(rng->rng_base); +- xilinx_rng_dev = NULL; + } + + static const struct of_device_id xtrng_of_match[] = { diff --git a/queue-6.18/series b/queue-6.18/series index 17becdd3f0..42ada9ade2 100644 --- a/queue-6.18/series +++ b/queue-6.18/series @@ -1515,3 +1515,4 @@ mmc-sdhci-esdhc-imx-disable-irq-during-suspend-to-fix-unhandled-interrupt.patch mmc-sdhci-esdhc-imx-use-pm_runtime_resume_and_get-in-suspend.patch mmc-sdhci-esdhc-imx-make-non-fatal-errors-non-blocking-in-suspend.patch mmc-sdhci-esdhc-imx-fix-resume-error-handling.patch +crypto-xilinx-trng-remove-crypto_rng-interface.patch