Skip to contentSkip to conversation

crypto: sun4i-ss: restrict PRNG seed length to prevent heap overflow

PATCH Superseded Tianchu Chen 5 participants 13 messages May 28 – Jun 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: sun4i-ss: restrict PRNG seed length to prevent heap overflow

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Add a length check rejecting seeds larger than the buffer.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")
---
 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +2 -0
index 491fcb7b8..010fa891c 100644
@@ -8,6 +8,8 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 	struct rng_alg *alg = crypto_rng_alg(tfm);
 
 	algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
+	if (slen > sizeof(algt->ss->seed))
+		return -EINVAL;
 	memcpy(algt->ss->seed, seed, slen);
 
 	return 0;
Signature · 1 line
2.51.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [Critical] The newly added bounds check unconditionally rejects valid seeds and completely breaks PRNG initialization on 64-bit architectures.

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but the PRNG generation function silently truncates unaligned requested lengths, failing to generate random bytes for the remainder of the buffer while still returning success.
- [High] This problem wasn't introduced by this patch, but the patch silently permits undersized seeds, leading to partial seed updates.
- [High] This problem wasn't introduced by this patch, but the PRNG seed is copied into the shared device state without any locking, creating a data race with concurrent PRNG generations.
- [High] This problem wasn't introduced by this patch, but there is a blind read from TXFIFO in PRNG generation without checking if data is available.
--

commit ce68b95827dcfbd778d1a5a3d2de5fd10e821954
Author: Tianchu Chen <[email protected]>
crypto: sun4i-ss: restrict PRNG seed length to prevent heap overflow

This commit restricts the PRNG seed length in sun4i_ss_prng_seed() to prevent a heap overflow. Without bounds checking, user-supplied seeds via AF_ALG could exceed the fixed-size buffer and corrupt adjacent memory.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 12

Quoted 10 lines
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +2 -0
index 491fcb7b81b40..010fa891c1056 100644
@@ -8,6 +8,8 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 	struct rng_alg *alg = crypto_rng_alg(tfm);
 
 	algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
+	if (slen > sizeof(algt->ss->seed))
+		return -EINVAL;

[Severity: Critical]
Does sizeof(algt->ss->seed) unconditionally reject valid seeds?

On 64-bit architectures, BITS_PER_LONG is 64, which makes the evaluation of SS_SEED_LEN / BITS_PER_LONG result in 3. The seed array becomes u32 seed[3], yielding a total size of 12 bytes. This would trigger the EINVAL branch for standard 24-byte seeds and completely break PRNG initialization.

[Severity: High]
This is a pre-existing issue, but does this check silently permit undersized seeds?

Allowing slen < seedsize enables partial memcpy operations that mix stale memory with new entropy.

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 13

Quoted 1 line
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
 	memcpy(algt->ss->seed, seed, slen);

[Severity: High]
This isn't a bug introduced by this patch, but could this copy operation create a data race?

The PRNG seed is copied into the shared device state without any locking, which could lead to torn reads or writes with concurrent PRNG generations.

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 15

Quoted 3 lines
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
 	return 0;
 }

[Severity: Critical]
This problem wasn't introduced by this patch, but are unaligned requested lengths silently truncated by the generation function?

Looking at sun4i_ss_prng_generate() in the same file:

	unsigned int todo = (dlen / 4) * 4;
	...
	while (todo > 0) {
		...
	}

The unaligned modulo truncation skips remainder bytes while still returning success. This fails to generate random bytes for the remainder of the buffer and could potentially leak uninitialized memory to userspace.

[Severity: High]
This is a pre-existing issue, but does the generator perform a blind read from the TXFIFO?

Looking at sun4i_ss_prng_generate() in the same file:

		/* Read the random data */
		len = min_t(size_t, SS_DATA_LEN / BITS_PER_BYTE, todo);
		readsl(ss->base + SS_TXFIFO, data, len / 4);

This reads from the TXFIFO without checking if data is actually available, which could fetch unready values before hardware generation completes and result in predictable or garbage PRNG output.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
Quoted 39 lines · May 28, 2026 at 11:29 PM, [email protected] mailto:[email protected]…

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [Critical] The newly added bounds check unconditionally rejects valid seeds and completely breaks PRNG initialization on 64-bit architectures.

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but the PRNG generation function silently truncates unaligned requested lengths, failing to generate random bytes for the remainder of the buffer while still returning success.
- [High] This problem wasn't introduced by this patch, but the patch silently permits undersized seeds, leading to partial seed updates.
- [High] This problem wasn't introduced by this patch, but the PRNG seed is copied into the shared device state without any locking, creating a data race with concurrent PRNG generations.
- [High] This problem wasn't introduced by this patch, but there is a blind read from TXFIFO in PRNG generation without checking if data is available.
--

commit ce68b95827dcfbd778d1a5a3d2de5fd10e821954
Author: Tianchu Chen <[email protected]>
crypto: sun4i-ss: restrict PRNG seed length to prevent heap overflow

This commit restricts the PRNG seed length in sun4i_ss_prng_seed() to prevent a heap overflow. Without bounds checking, user-supplied seeds via AF_ALG could exceed the fixed-size buffer and corrupt adjacent memory.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c

Quoted 12 lines
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
 index 491fcb7b81b40..010fa891c1056 100644
 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
 +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
 @@ -8,6 +8,8 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 struct rng_alg *alg = crypto_rng_alg(tfm);
 
 algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
 + if (slen > sizeof(algt->ss->seed))
 + return -EINVAL;

[Severity: Critical]
Does sizeof(algt->ss->seed) unconditionally reject valid seeds?

Quoted 5 lines

On 64-bit architectures, BITS_PER_LONG is 64, which makes the evaluation of SS_SEED_LEN / BITS_PER_LONG result in 3. The seed array becomes u32 seed[3], yielding a total size of 12 bytes. This would trigger the EINVAL branch for standard 24-byte seeds and completely break PRNG initialization.

sun4i-ss is designed for 32-bit ARM only (A10/A13/A20/A33). It's behind ARCH_SUNXI in Kconfig so it never builds on 64-bit. On the real hardware sizeof(ss->seed) is always 24, same as .seedsize.

maintainer
#3 lore raw
In reply to Tianchu Chen

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 12

Quoted 11 lines · Tianchu Chen
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +2 -0
index 491fcb7b8..010fa891c 100644
@@ -8,6 +8,8 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 	struct rng_alg *alg = crypto_rng_alg(tfm);
 
 	algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
+	if (slen > sizeof(algt->ss->seed))
+		return -EINVAL;

This should simply ignore the extra data instead of failing.

Thanks,

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
#4 lore raw
Quoted 11 lines · Herbert Xu
Quoted 8 lines · Tianchu Chen
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
 index 491fcb7b8..010fa891c 100644
 --- a/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
 +++ b/drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c
 @@ -8,6 +8,8 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 struct rng_alg *alg = crypto_rng_alg(tfm);
Quoted 5 lines
Quoted 4 lines

algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
+ if (slen > sizeof(algt->ss->seed))
+ return -EINVAL;

This should simply ignore the extra data instead of failing.

Thanks for pointing out, silent truncation is more appropriate here.

I'll send a v2 patch with min_t soon.

Best regards,
Tianchu Chen

#5 lore raw

PATCH v2 1/1 crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

In reply to Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

 drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +1 -1
index 491fcb7b8..7f6a51dd8 100644
@@ -8,7 +8,7 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 	struct rng_alg *alg = crypto_rng_alg(tfm);
 
 	algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
-	memcpy(algt->ss->seed, seed, slen);
+	memcpy(algt->ss->seed, seed, min_t(unsigned int, slen, sizeof(algt->ss->seed)));
 
 	return 0;
 }
Signature · 1 line
2.51.0
#6 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

Pre-existing issues:
- [Critical] The PRNG hardware state is shared globally across all crypto API instances, allowing unprivileged users to predictably control the RNG state for others.
- [High] The PRNG seed buffer size incorrectly depends on BITS_PER_LONG, causing seed truncation and halving entropy on 64-bit systems.
- [High] sun4i_ss_prng_seed modifies the shared PRNG seed buffer without taking the required device spinlock.
- [High] The driver fails to validate that the provided seed length is sufficient before updating the PRNG seed state.
- [High] sun4i_ss_prng_generate silently ignores trailing bytes when the requested length is not a multiple of 4, leaving parts of the caller's buffer uninitialized. --

commit c4469644d7be8a19b75d7ee7a736e9f34531be57
Author: Tianchu Chen <[email protected]>
crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

This commit clamps the copy length in sun4i_ss_prng_seed() to prevent a heap overflow when a user supplies an oversized seed via AF_ALG. It uses min_t to restrict the length to the size of the destination seed buffer.

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 10

Quoted 8 lines
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
index 491fcb7b81b40..7f6a51dd8f923 100644
@@ -8,7 +8,7 @@ int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
 	struct rng_alg *alg = crypto_rng_alg(tfm);
 
 	algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);

[Severity: Critical]
This is a pre-existing issue, but the PRNG hardware state is shared globally across all crypto API instances. Since there is no per-tfm context and the driver registers as stdrng with priority 300, can an unprivileged user open an AF_ALG socket and use setsockopt to inject a chosen seed here? This would allow them to predict the sequence of random numbers generated for other processes or kernel subsystems relying on the same RNG.

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 11

Quoted 1 line
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -1
-	memcpy(algt->ss->seed, seed, slen);

[Severity: High]
This is a pre-existing issue, but does this function modify the shared PRNG seed buffer without taking the required device spinlock? In sun4i_ss_prng_generate(), the code acquires spin_lock_bh(&ss->slock) before accessing the buffer. Concurrent calls to sun4i_ss_prng_seed() and generate could cause a data race resulting in torn state.

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 11

Quoted 1 line
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +1 -0
+	memcpy(algt->ss->seed, seed, min_t(unsigned int, slen, sizeof(algt->ss->seed)));

[Severity: High]
This is a pre-existing issue, but does the seed buffer size incorrectly depend on BITS_PER_LONG? If the driver defines the seed array using SS_SEED_LEN / BITS_PER_LONG, on 64-bit systems this becomes an array of 3 elements (12 bytes) instead of the expected 24 bytes. This would mean the sizeof() calculation silently truncates valid 24-byte seeds to 12 bytes and fails to initialize half of the PRNG hardware seed registers.

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 13

Quoted 2 lines
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
 	return 0;

[Severity: High]
This is a pre-existing issue, but does this function fail to validate that the provided seed length is sufficient? If a caller provides an undersized seed, the memcpy will partially update the array, but the function will still unconditionally return 0. Should the code return an error when the seed is too small instead of signaling a successful reseeding?

drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, · line 13

Quoted 1 line
drivers/crypto/allwinner/sun4i-ss/sun4i-ss-prng.c +0 -0
 }

[Severity: High]
This is a pre-existing issue, but looking at sun4i_ss_prng_generate(), if the requested length is not a multiple of 4, the remaining bytes are silently ignored while still returning 0 (success). Does this leave portions of the caller's buffer completely uninitialized, potentially causing information disclosure or cryptographic vulnerabilities if predictable memory is used as key material?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#7 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

In reply to Tianchu Chen
Quoted 12 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Quoted 8 lines

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

sun4i-ss-prng.c is useless, is still broken, and should just be deleted.

- Eric

maintainer
#8 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

Quoted 15 lines · Eric Biggers
Quoted 14 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Quoted 8 lines
Quoted 6 lines
Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

sun4i-ss-prng.c is useless, is still broken, and should just be deleted.

Hello

useless ? clearly no, it helped a lot on devices where it is.

Regards

#9 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

Quoted 23 lines · Corentin Labbe
Quoted 22 lines · Eric Biggers
Quoted 20 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

Quoted 5 lines
Quoted 1 line

sun4i-ss-prng.c is useless, is still broken, and should just be deleted.

Hello

useless ? clearly no, it helped a lot on devices where it is.

The only way this code is reachable is via "rng" algorithm type in AF_ALG, which is almost never used. Everyone just uses the regular Linux RNG (/dev/random etc) instead, as they should.

In fact, anyone were to accidentally use this it would be a security vulnerability, seeing as sun4i_ss_prng_generate() doesn't actually fill in all the bytes that were requested. It also doesn't wait for the FIFO to be ready when reading data from it.

Is it possible that there's a misunderstanding here and you think this provides entropy to the regular Linux RNG? It doesn't. hwrng does that, crypto_rng does not.

The correct fix is to mark CRYPTO_DEV_SUN8I_CE_PRNG as BROKEN or remove it entirely. Doing otherwise is not responsible.

- Eric

#10 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

Quoted 39 lines · Eric Biggers
Quoted 23 lines · Corentin Labbe
Quoted 22 lines · Eric Biggers
Quoted 20 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

Quoted 5 lines
Quoted 1 line

sun4i-ss-prng.c is useless, is still broken, and should just be deleted.

Hello

useless ? clearly no, it helped a lot on devices where it is.

The only way this code is reachable is via "rng" algorithm type in AF_ALG, which is almost never used. Everyone just uses the regular Linux RNG (/dev/random etc) instead, as they should.

In fact, anyone were to accidentally use this it would be a security vulnerability, seeing as sun4i_ss_prng_generate() doesn't actually fill in all the bytes that were requested. It also doesn't wait for the FIFO to be ready when reading data from it.

Quoted 6 lines

Is it possible that there's a misunderstanding here and you think this provides entropy to the regular Linux RNG? It doesn't. hwrng does that, crypto_rng does not.

The correct fix is to mark CRYPTO_DEV_SUN8I_CE_PRNG as BROKEN or remove it entirely. Doing otherwise is not responsible.

Looking into it a bit more, just removing CRYPTO_DEV_SUN4I_SS_PRNG is clearly the way to go. This patch does it:
https://lore.kernel.org/linux-crypto/[email protected]

- Eric

maintainer
#11 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

In reply to Eric Biggers
Quoted 34 lines · Eric Biggers
Quoted 23 lines · Corentin Labbe
Quoted 22 lines · Eric Biggers
Quoted 20 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

Quoted 5 lines
Quoted 1 line

sun4i-ss-prng.c is useless, is still broken, and should just be deleted.

Hello

useless ? clearly no, it helped a lot on devices where it is.

The only way this code is reachable is via "rng" algorithm type in AF_ALG, which is almost never used. Everyone just uses the regular Linux RNG (/dev/random etc) instead, as they should.

Quoted 9 lines

In fact, anyone were to accidentally use this it would be a security vulnerability, seeing as sun4i_ss_prng_generate() doesn't actually fill in all the bytes that were requested. It also doesn't wait for the FIFO to be ready when reading data from it.

Is it possible that there's a misunderstanding here and you think this provides entropy to the regular Linux RNG? It doesn't. hwrng does that, crypto_rng does not.

I believe to have used rngd for that. ( or something like that)

Anyway, I understand why want to remove it.

#12 lore raw

Re: [PATCH v2] crypto: sun4i-ss - clamp PRNG seed length to prevent heap overflow

Quoted 40 lines · Corentin Labbe
Quoted 39 lines · Eric Biggers
Quoted 23 lines · Corentin Labbe
Quoted 22 lines · Eric Biggers
Quoted 20 lines · Tianchu Chen

From: Tianchu Chen <[email protected]>

sun4i_ss_prng_seed() copies the user-supplied seed into ss->seed using the user-provided length with no bounds check. The crypto core does not enforce slen <= seedsize before calling into the driver, so a userspace caller via AF_ALG setsockopt(ALG_SET_KEY) can pass up to sysctl_optmem_max bytes, overflowing the fixed-size buffer and corrupting adjacent heap memory.

Clamp the copy length to the buffer size, matching the approach used by loongson-rng for oversized seeds.

Discovered by Atuin - Automated Vulnerability Discovery Engine.

Fixes 6298e948215f ("crypto: sunxi-ss - Add Allwinner Security System crypto accelerator")

---
v2: Silently clamp oversized seeds with min_t instead of returning
-EINVAL (Herbert Xu).

Quoted 5 lines
Quoted 1 line

sun4i-ss-prng.c is useless, is still broken, and should just be deleted.

Hello

useless ? clearly no, it helped a lot on devices where it is.

The only way this code is reachable is via "rng" algorithm type in AF_ALG, which is almost never used. Everyone just uses the regular Linux RNG (/dev/random etc) instead, as they should.

In fact, anyone were to accidentally use this it would be a security vulnerability, seeing as sun4i_ss_prng_generate() doesn't actually fill in all the bytes that were requested. It also doesn't wait for the FIFO to be ready when reading data from it.

Quoted 8 lines
Quoted 4 lines

Is it possible that there's a misunderstanding here and you think this provides entropy to the regular Linux RNG? It doesn't. hwrng does that, crypto_rng does not.

I believe to have used rngd for that. ( or something like that)

Anyway, I understand why want to remove it.

rngd doesn't use AF_ALG. So no, it couldn't have used this driver.

- Eric