Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 01/11] crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths
       [not found] <20261129200245.146503-1-ebiggers@kernel.org>
@ 2026-11-29 20:02 ` Eric Biggers
  2026-11-29 20:02 ` [PATCH 02/11] lib/crypto: gf128hash: Link libgf128hash before libaes Eric Biggers
  1 sibling, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2026-11-29 20:02 UTC (permalink / raw)
  To: linux-crypto
  Cc: Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu, x86,
	Antonio Quartulli, Eric Biggers, stable

The linear fast paths in crypto_aes_cbc_cts_{en,de}crypt() and
crypto_aes_xts_{en,de}crypt() write directly to sg_virt(req->dst)
without going through scatterwalk_done_dst(), so they fail to flush the
dcache on architectures where ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE is true.

Add a small __always_inline helper sg_flush_dcache() and call it from
those fast paths.  When !ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE, the helper
compiles out completely.

Fixes: 20df21a482aa ("crypto: aes - Add CBC and CBC-CTS support using library")
Fixes: 94efa0c9fb36 ("crypto: aes - Add XTS support using library")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 crypto/aes.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/crypto/aes.c b/crypto/aes.c
index a2db6351feefa..c4541f5bc6e32 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -240,6 +240,19 @@ skcipher_request_is_linear_lowmem(const struct skcipher_request *req)
 	       req->src->length >= req->cryptlen;
 }
 
+/*
+ * Flush the dcache for a linear region [off, off + len) within a single
+ * scatterlist element @sg.  This must be called after writing directly to
+ * sg_virt(sg) without going through scatterwalk_done_dst().
+ */
+static __always_inline void sg_flush_dcache(struct scatterlist *sg,
+					    unsigned int off, unsigned int len)
+{
+	if (ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE)
+		__scatterwalk_flush_dcache_pages(sg_page(sg), sg->offset + off,
+						 len);
+}
+
 /*
  * Call crypt_func() (a function that operates on simple virtual addresses) zero
  * or more times to en/decrypt 'cryptlen' bytes of data from the source
@@ -462,6 +475,7 @@ crypto_aes_cbc_cts_encrypt(struct skcipher_request *req)
 		/* Fast path */
 		aes_cbc_cts_encrypt(sg_virt(req->dst), sg_virt(req->src),
 				    req->cryptlen, req->iv, key);
+		sg_flush_dcache(req->dst, 0, req->cryptlen);
 		return 0;
 	}
 	return crypto_aes_cbc_cts_crypt_nonlinear(req, /* enc= */ true);
@@ -479,6 +493,7 @@ crypto_aes_cbc_cts_decrypt(struct skcipher_request *req)
 		/* Fast path */
 		aes_cbc_cts_decrypt(sg_virt(req->dst), sg_virt(req->src),
 				    req->cryptlen, req->iv, key);
+		sg_flush_dcache(req->dst, 0, req->cryptlen);
 		return 0;
 	}
 	return crypto_aes_cbc_cts_crypt_nonlinear(req, /* enc= */ false);
@@ -584,6 +599,7 @@ static __maybe_unused int crypto_aes_xts_encrypt(struct skcipher_request *req)
 		/* Fast path */
 		aes_xts_encrypt(sg_virt(req->dst), sg_virt(req->src),
 				req->cryptlen, req->iv, key, /* cont= */ false);
+		sg_flush_dcache(req->dst, 0, req->cryptlen);
 		return 0;
 	}
 	return crypto_aes_xts_crypt_nonlinear(req, /* enc= */ true);
@@ -600,6 +616,7 @@ static __maybe_unused int crypto_aes_xts_decrypt(struct skcipher_request *req)
 		/* Fast path */
 		aes_xts_decrypt(sg_virt(req->dst), sg_virt(req->src),
 				req->cryptlen, req->iv, key, /* cont= */ false);
+		sg_flush_dcache(req->dst, 0, req->cryptlen);
 		return 0;
 	}
 	return crypto_aes_xts_crypt_nonlinear(req, /* enc= */ false);
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 02/11] lib/crypto: gf128hash: Link libgf128hash before libaes
       [not found] <20261129200245.146503-1-ebiggers@kernel.org>
  2026-11-29 20:02 ` [PATCH 01/11] crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths Eric Biggers
@ 2026-11-29 20:02 ` Eric Biggers
  1 sibling, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2026-11-29 20:02 UTC (permalink / raw)
  To: linux-crypto
  Cc: Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu, x86,
	Antonio Quartulli, Eric Biggers, stable

Move libgf128hash above libaes in lib/crypto/Makefile so that
gf128hash_mod_init() runs first when both libgf128hash and libaes are
built-in.

This is relevant to the AES-GCM FIPS self-test, which previously didn't
use the architecture-optimized GHASH code in this case.

Fixes: fbdb43c0007b ("lib/crypto: aes: Add FIPS self-tests for GCM and CCM")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 lib/crypto/Makefile | 58 +++++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 28 deletions(-)

diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
index cefec4304d808..5ddf64ce1d453 100644
--- a/lib/crypto/Makefile
+++ b/lib/crypto/Makefile
@@ -21,6 +21,36 @@ libcryptoutils-y				:= memneq.o utils.o
 
 ################################################################################
 
+# The AES-GCM support in libaes uses libgf128hash.  Link libgf128hash before
+# libaes so that the libgf128hash initcall runs first when both are built-in.
+obj-$(CONFIG_CRYPTO_LIB_GF128HASH) += libgf128hash.o
+libgf128hash-y := gf128hash.o
+ifeq ($(CONFIG_CRYPTO_LIB_GF128HASH_ARCH),y)
+CFLAGS_gf128hash.o += -I$(src)/$(SRCARCH)
+libgf128hash-$(CONFIG_ARM) += arm/ghash-neon-core.o
+libgf128hash-$(CONFIG_ARM64) += arm64/ghash-neon-core.o \
+				arm64/polyval-ce-core.o
+
+ifeq ($(CONFIG_PPC),y)
+libgf128hash-y += powerpc/ghashp8-ppc.o
+quiet_cmd_perlasm_ghash = PERLASM $@
+      cmd_perlasm_ghash = $(PERL) $< $(ppc64-perlasm-flavour-y) $@
+$(obj)/powerpc/ghashp8-ppc.S: $(src)/powerpc/ghashp8-ppc.pl FORCE
+	$(call if_changed,perlasm_ghash)
+targets += powerpc/ghashp8-ppc.S
+OBJECT_FILES_NON_STANDARD_powerpc/ghashp8-ppc.o := y
+endif
+
+libgf128hash-$(CONFIG_RISCV) += riscv/ghash-riscv64-zvkg.o
+libgf128hash-$(CONFIG_X86) += x86/ghash-pclmul.o \
+			      x86/polyval-pclmul-avx.o
+endif # CONFIG_CRYPTO_LIB_GF128HASH_ARCH
+
+# clean-files must be defined unconditionally
+clean-files += powerpc/ghashp8-ppc.S
+
+################################################################################
+
 obj-$(CONFIG_CRYPTO_LIB_AES) += libaes.o
 libaes-y := aes.o
 ifeq ($(CONFIG_CRYPTO_LIB_AES_ARCH),y)
@@ -168,34 +198,6 @@ libdes-y					:= des.o
 
 ################################################################################
 
-obj-$(CONFIG_CRYPTO_LIB_GF128HASH) += libgf128hash.o
-libgf128hash-y := gf128hash.o
-ifeq ($(CONFIG_CRYPTO_LIB_GF128HASH_ARCH),y)
-CFLAGS_gf128hash.o += -I$(src)/$(SRCARCH)
-libgf128hash-$(CONFIG_ARM) += arm/ghash-neon-core.o
-libgf128hash-$(CONFIG_ARM64) += arm64/ghash-neon-core.o \
-				arm64/polyval-ce-core.o
-
-ifeq ($(CONFIG_PPC),y)
-libgf128hash-y += powerpc/ghashp8-ppc.o
-quiet_cmd_perlasm_ghash = PERLASM $@
-      cmd_perlasm_ghash = $(PERL) $< $(ppc64-perlasm-flavour-y) $@
-$(obj)/powerpc/ghashp8-ppc.S: $(src)/powerpc/ghashp8-ppc.pl FORCE
-	$(call if_changed,perlasm_ghash)
-targets += powerpc/ghashp8-ppc.S
-OBJECT_FILES_NON_STANDARD_powerpc/ghashp8-ppc.o := y
-endif
-
-libgf128hash-$(CONFIG_RISCV) += riscv/ghash-riscv64-zvkg.o
-libgf128hash-$(CONFIG_X86) += x86/ghash-pclmul.o \
-			      x86/polyval-pclmul-avx.o
-endif # CONFIG_CRYPTO_LIB_GF128HASH_ARCH
-
-# clean-files must be defined unconditionally
-clean-files += powerpc/ghashp8-ppc.S
-
-################################################################################
-
 obj-$(CONFIG_CRYPTO_LIB_MD5) += libmd5.o
 libmd5-y := md5.o
 
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-29 20:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261129200245.146503-1-ebiggers@kernel.org>
2026-11-29 20:02 ` [PATCH 01/11] crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths Eric Biggers
2026-11-29 20:02 ` [PATCH 02/11] lib/crypto: gf128hash: Link libgf128hash before libaes Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox