linux/lib/crypto
Eric Biggers b416a4245f lib/crypto: chacha: Zeroize permuted_state before it leaves scope
commit e5046823f8 upstream.

Since the ChaCha permutation is invertible, the local variable
'permuted_state' is sufficient to compute the original 'state', and thus
the key, even after the permutation has been done.

While the kernel is quite inconsistent about zeroizing secrets on the
stack (and some prominent userspace crypto libraries don't bother at all
since it's not guaranteed to work anyway), the kernel does try to do it
as a best practice, especially in cases involving the RNG.

Thus, explicitly zeroize 'permuted_state' before it goes out of scope.

Fixes: c08d0e6473 ("crypto: chacha20 - Add a generic ChaCha20 stream cipher implementation")
Cc: stable@vger.kernel.org
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20260326032920.39408-1-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-04-18 10:33:35 +02:00
..
aes.c lib/crypto: aes: Fix missing MMU protection for AES S-box 2026-01-19 13:10:13 +01:00
arc4.c crypto: arc4 - refactor arc4 core code into separate library 2019-06-20 14:18:33 +08:00
blake2s-generic.c lib/crypto: blake2s: include as built-in 2022-05-30 09:28:59 +02:00
blake2s-selftest.c crypto: lib/blake2s - reduce stack frame usage in self test 2022-08-17 14:24:29 +02:00
blake2s.c crypto: blake2s - remove shash module 2022-08-17 14:24:19 +02:00
chacha.c lib/crypto: chacha: Zeroize permuted_state before it leaves scope 2026-04-18 10:33:35 +02:00
chacha20poly1305-selftest.c crypto: arm64/chacha - correctly walk through blocks 2020-03-20 14:35:27 +11:00
chacha20poly1305.c crypto: lib - rename 'mod_init' & 'mod_exit' functions to be module-specific 2021-07-16 15:49:36 +08:00
curve25519-fiat32.c crypto: lib/curve25519 - work around Clang stack spilling issue 2019-11-17 09:02:43 +08:00
curve25519-generic.c crypto: curve25519 - Fix selftest build error 2020-01-16 15:18:13 +08:00
curve25519-hacl64.c crypto: curve25519 - generic C library implementations 2019-11-17 09:02:43 +08:00
curve25519-selftest.c crypto: lib/curve25519 - re-add selftests 2019-12-27 18:18:03 +08:00
curve25519.c crypto: lib - rename 'mod_init' & 'mod_exit' functions to be module-specific 2021-07-16 15:49:36 +08:00
des.c crypto: des - split off DES library from generic DES cipher driver 2019-08-22 14:57:33 +10:00
Kconfig crypto: lib - remove unneeded selection of XOR_BLOCKS 2022-09-05 10:30:03 +02:00
libchacha.c crypto: chacha - move existing library code into lib/crypto 2019-11-17 09:02:39 +08:00
Makefile lib/crypto: curve25519-hacl64: Fix older clang KASAN workaround for GCC 2025-12-07 06:09:26 +09:00
poly1305-donna32.c crypto: poly1305 - fix poly1305_core_setkey() declaration 2021-04-02 18:28:12 +11:00
poly1305-donna64.c crypto: poly1305 - fix poly1305_core_setkey() declaration 2021-04-02 18:28:12 +11:00
poly1305.c crypto: poly1305 - fix poly1305_core_setkey() declaration 2021-04-02 18:28:12 +11:00
sha256.c crypto: sha - split sha.h into sha1.h and sha2.h 2020-11-20 14:45:33 +11:00
sm4.c crypto: sm4 - Do not change section of ck and sbox 2021-11-18 19:16:23 +01:00