From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794590542; b=0PlUtletfR1hA8//ySvlyDqDSINJTY6k3cdOe7D5ZjgQgeAG4eXT8E3QEICk5mBwFu3i T9c7NEGSzA438xsSiW9sDxEF48ePKPXoNm2fvaEqwcgfINUwBvgVJDSNKol49xaUw4pch JItBe5YpOBrK3d1JZW3j4avIW8kuiW+UxNo/tz7mRRegnNq5BmDkAvdEpGvewJDXjxn9X fDMikt7Gn/cUrsx1tVwoDmtQzNCQ67kHbeVyTT1piMk6hUegL0uHE/hTASPW9pSQZZWta bUEAKN8rnMJUJz01WXWzWFkSiKrQ4HjDaL2P55Orp4OmpF0sxuNmLADfUm4Vhru2D2g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590542; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=j8D5S8wrdu5rF8Dv8P4S0ZwUXE6C09o9b0t7IFvQmxI=; b=sNRL3241wTK1PJo3wMrQu+J25EZqgHxD9FgN3qwLD0PTQSdKaqvkOWP7yhD3IFP+8LEx 1GlwlZ41I9lj8ysrhhqq532x/YFX9U+f6AOHEEtv3mu8Fm7XPtcJogogAvgN0gTajdGvG iq0r+SRUe1N5GY/Fn5/BXS2CQzjvhRaWrduQrIz5K5WmxPNTkZRmLU4SV7oZ/xyKz2IKg on66hzbhHj4svl36g/OVky2qU4TYAwoARXmIVagXGHQ/cJgw6GkC89K3V8ls5/pZMiw22 2jRg0ed35WiZMMBIFtQdeVFOmieZR+wcwBjdXCNPRD+8FZgOMYPJO+nTiudbP8MxolQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=OAe1WqJG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74B4A606B366; Fri, 13 Nov 2026 17:22:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=OAe1WqJG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 217341F000C4; Fri, 13 Nov 2026 17:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590542; bh=j8D5S8wrdu5rF8Dv8P4S0ZwUXE6C09o9b0t7IFvQmxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OAe1WqJGpuHHyoQmqHbnRMCJGBochnu2LMscuTnwHFJPzYJ4pbl/OQhMUnwuVxL64 tY1GXbYiCRxGhpgGVGhfVI5xvVDj4d/IJhXfdt+6ZKaFZyZJhtrdHBYzL+78txkpoI lC55XYLSQAOXMUjPxjzglc/RnF+Aq9HzKhfP2hbM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ard Biesheuvel , Eric Biggers , Sasha Levin Subject: [PATCH 6.18 482/686] lib/crypto: mips: Disable Octeon SHA code on little-endian kernels Date: Fri, 13 Nov 2026 10:50:15 -0500 Message-ID: <20261113153837.287714988@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit dd2a4edb26e1c78823c50ba10c42f2d3de2e5ec4 upstream. Kernels built for the MIPS64-based Cavium Octeon SoCs are normally big-endian, but little-endian builds are also supported. Currently, the SHA-1, SHA-256, and SHA-512 code using the Octeon crypto co-processor is enabled in both builds. This code is untestable without the hardware. However, based on the code itself, it is implausible that it computes hash values correctly in little-endian builds. Such builds write many incorrect values to COP2: - SHA-1 and SHA-256: The 64-bit integer that contains the last two 32-bit message words of each block is written to COP2 entirely byte-reflected, due to missing endianness conversion in octeon_sha1_start() and octeon_sha256_start() to compensate for using native 64-bit loads from the message bytes. This differs from all the earlier message words which are written correctly. Furthermore, the state is written to COP2 with each 32-bit word byte-reflected within each 64-bit integer, due to incorrect use of 64-bit endianness conversion in write_octeon_64bit_hash_dword() when the state is kept in memory in native-endian 32-bit words. - SHA-512: All the 64-bit message words are written to COP2 byte-reflected, due to missing endianness conversion in write_octeon_64bit_block_sha512() and octeon_sha512_start(). The SHA-512 state words seem to be written correctly. Big-endian kernels aren't affected by these bugs. These bugs also aren't new; this code has been broken on little-endian ever since it and Octeon little-endian support were first added in v4.1. Commit d2a948d2db68 ("MIPS: Octeon: Make octeon-md5 driver endian-agnostic") made the MD5 code work on little-endian kernels by adding 64-bit endianness conversions to the COP2 macros used by MD5 (some of which are shared by SHA-1 and SHA-256, despite those algorithms keeping the state words in native-endian instead of MD5's little-endian, causing some of the strange behavior described above). However, SHA-1, SHA-256, and SHA-512 were never fixed to work on little-endian kernels. Therefore, disable the Octeon SHA-1, SHA-256, and SHA-512 code in little-endian kernels. This causes the generic code that actually computes hash values correctly to be used instead. Fixes: 82be2dcfa6a1 ("crypto: octeon - add SHA1 module") Fixes: c3d0def62001 ("crypto: octeon - add SHA256 module") Fixes: fbaa4dfd51a0 ("crypto: octeon - add SHA512 module") Cc: stable@vger.kernel.org Acked-by: Ard Biesheuvel Link: https://patch.msgid.link/20261022054450.20746-1-ebiggers@kernel.org Signed-off-by: Eric Biggers Signed-off-by: Sasha Levin --- lib/crypto/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig index fa882108ba62c..2f2edeaf9de3e 100644 --- a/lib/crypto/Kconfig +++ b/lib/crypto/Kconfig @@ -142,7 +142,7 @@ config CRYPTO_LIB_SHA1_ARCH depends on CRYPTO_LIB_SHA1 && !UML default y if ARM default y if ARM64 && KERNEL_MODE_NEON - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if PPC default y if S390 default y if SPARC64 @@ -160,7 +160,7 @@ config CRYPTO_LIB_SHA256_ARCH depends on CRYPTO_LIB_SHA256 && !UML default y if ARM && !CPU_V7M default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if PPC && SPE default y if RISCV && 64BIT && TOOLCHAIN_HAS_VECTOR_CRYPTO && \ RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS @@ -180,7 +180,7 @@ config CRYPTO_LIB_SHA512_ARCH depends on CRYPTO_LIB_SHA512 && !UML default y if ARM && !CPU_V7M default y if ARM64 - default y if MIPS && CPU_CAVIUM_OCTEON + default y if MIPS && CPU_CAVIUM_OCTEON && CPU_BIG_ENDIAN default y if RISCV && 64BIT && TOOLCHAIN_HAS_VECTOR_CRYPTO && \ RISCV_EFFICIENT_VECTOR_UNALIGNED_ACCESS default y if S390 -- 2.53.0