linux/lib/crypto/x86
Eric Biggers 3b95fdb75d lib/crypto: x86/blake2s: Fix 32-bit arg treated as 64-bit
commit 2f22115709 upstream.

In the C code, the 'inc' argument to the assembly functions
blake2s_compress_ssse3() and blake2s_compress_avx512() is declared with
type u32, matching blake2s_compress().  The assembly code then reads it
from the 64-bit %rcx.  However, the ABI doesn't guarantee zero-extension
to 64 bits, nor do gcc or clang guarantee it.  Therefore, fix these
functions to read this argument from the 32-bit %ecx.

In theory, this bug could have caused the wrong 'inc' value to be used,
causing incorrect BLAKE2s hashes.  In practice, probably not: I've fixed
essentially this same bug in many other assembly files too, but there's
never been a real report of it having caused a problem.  In x86_64, all
writes to 32-bit registers are zero-extended to 64 bits.  That results
in zero-extension in nearly all situations.  I've only been able to
demonstrate a lack of zero-extension with a somewhat contrived example
involving truncation, e.g. when the C code has a u64 variable holding
0x1234567800000040 and passes it as a u32 expecting it to be truncated
to 0x40 (64).  But that's not what the real code does, of course.

Fixes: ed0356eda1 ("crypto: blake2s - x86_64 SIMD implementation")
Cc: stable@vger.kernel.org
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20251102234209.62133-2-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-01-02 12:57:07 +01:00
..
.gitignore lib/crypto: x86: Move arch/x86/lib/crypto/ into lib/crypto/ 2025-06-30 09:26:20 -07:00
blake2s-core.S lib/crypto: x86/blake2s: Fix 32-bit arg treated as 64-bit 2026-01-02 12:57:07 +01:00
blake2s.h lib/crypto: blake2s: Consolidate into single C translation unit 2025-08-29 09:50:19 -07:00
chacha-avx2-x86_64.S lib/crypto: x86: Move arch/x86/lib/crypto/ into lib/crypto/ 2025-06-30 09:26:20 -07:00
chacha-avx512vl-x86_64.S lib/crypto: x86: Move arch/x86/lib/crypto/ into lib/crypto/ 2025-06-30 09:26:20 -07:00
chacha-ssse3-x86_64.S lib/crypto: x86: Move arch/x86/lib/crypto/ into lib/crypto/ 2025-06-30 09:26:20 -07:00
chacha.h lib/crypto: chacha: Consolidate into single module 2025-08-29 09:50:19 -07:00
curve25519.h lib/crypto: curve25519: Consolidate into single module 2025-09-06 16:32:43 -07:00
poly1305-x86_64-cryptogams.pl lib/crypto: poly1305: Consolidate into single module 2025-08-29 09:49:18 -07:00
poly1305.h lib/crypto: poly1305: Consolidate into single module 2025-08-29 09:49:18 -07:00
sha1-avx2-asm.S lib/crypto: x86/sha1: Migrate optimized code into library 2025-07-14 11:28:35 -07:00
sha1-ni-asm.S lib/crypto: x86/sha1-ni: Convert to use rounds macros 2025-07-20 21:42:42 -07:00
sha1-ssse3-and-avx.S lib/crypto: x86/sha1: Migrate optimized code into library 2025-07-14 11:28:35 -07:00
sha1.h lib/crypto: Drop inline from all *_mod_init_arch() functions 2025-08-27 08:15:35 -07:00
sha256-avx-asm.S lib/crypto: x86/sha256: Remove unnecessary checks for nblocks==0 2025-07-04 10:23:56 -07:00
sha256-avx2-asm.S lib/crypto: x86/sha256: Remove unnecessary checks for nblocks==0 2025-07-04 10:23:56 -07:00
sha256-ni-asm.S lib/crypto: x86/sha256: Add support for 2-way interleaved hashing 2025-09-17 13:09:40 -05:00
sha256-ssse3-asm.S lib/crypto: x86/sha256: Remove unnecessary checks for nblocks==0 2025-07-04 10:23:56 -07:00
sha256.h Optimize fsverity with 2-way interleaved hashing 2025-09-29 15:55:20 -07:00
sha512-avx-asm.S lib/crypto: x86/sha512: Remove unnecessary checks for nblocks==0 2025-06-30 09:26:20 -07:00
sha512-avx2-asm.S lib/crypto: x86/sha512: Remove unnecessary checks for nblocks==0 2025-06-30 09:26:20 -07:00
sha512-ssse3-asm.S lib/crypto: x86/sha512: Remove unnecessary checks for nblocks==0 2025-06-30 09:26:20 -07:00
sha512.h lib/crypto: Drop inline from all *_mod_init_arch() functions 2025-08-27 08:15:35 -07:00