Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
@ 2026-12-03 21:01 Bruno Meneguele
  2026-12-03 21:18 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Meneguele @ 2026-12-03 21:01 UTC (permalink / raw)
  To: linux-crypto
  Cc: linux-kernel, herbert, davem, ebiggers, Bruno Meneguele, stable

Since commit 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API"),
crypto_ahash_init_tfm() allocates a fallback for every async driver by setting
CRYPTO_ALG_REQ_VIRT flag in both type and mask.

However, the cmac, xcbc and cbcmac templates validate the request with:

  crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask)

which compares the whole flag word, including the previously set
CRYPTO_ALG_REQ_VIRT flag, which is now missing during comparison, causing it to
return -EINVAL.

The error propagates to crypto_ahash_init_tfm(), even before a driver's own init
runs, causing the driver to fail on its self-test.  For instance, on NVIDIA
Tegra:

  alg: hash: failed to allocate transform for tegra-se-cmac: -22
  alg: self-tests for cmac(aes) using tegra-se-cmac failed (rc=-22)

With this commit these templates pass CRYPTO_ALG_TYPE_SHASH|CRYPTO_ALG_REQ_VIRT
instead, so requests that need REQ_VIRT set are accepted, and requests that need
it clear, are still rejected.

Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
Cc: stable@vger.kernel.org
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
---
 crypto/ccm.c  | 3 ++-
 crypto/cmac.c | 3 ++-
 crypto/xcbc.c | 3 ++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/crypto/ccm.c b/crypto/ccm.c
index 916441e4f2b8..250af56cfe1f 100644
--- a/crypto/ccm.c
+++ b/crypto/ccm.c
@@ -852,7 +852,8 @@ static int cbcmac_create(struct crypto_template *tmpl, struct rtattr **tb)
 	u32 mask;
 	int err;
 
-	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask);
+	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH |
+				     CRYPTO_ALG_REQ_VIRT, &mask);
 	if (err)
 		return err;
 
diff --git a/crypto/cmac.c b/crypto/cmac.c
index 83e58937f013..74786612a6f1 100644
--- a/crypto/cmac.c
+++ b/crypto/cmac.c
@@ -165,7 +165,8 @@ static int cmac_create(struct crypto_template *tmpl, struct rtattr **tb)
 	u32 mask;
 	int err;
 
-	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask);
+	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH |
+				     CRYPTO_ALG_REQ_VIRT, &mask);
 	if (err)
 		return err;
 
diff --git a/crypto/xcbc.c b/crypto/xcbc.c
index 6c5f6766fdd6..50f14bd7d88d 100644
--- a/crypto/xcbc.c
+++ b/crypto/xcbc.c
@@ -132,7 +132,8 @@ static int xcbc_create(struct crypto_template *tmpl, struct rtattr **tb)
 	u32 mask;
 	int err;
 
-	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask);
+	err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH |
+				     CRYPTO_ALG_REQ_VIRT, &mask);
 	if (err)
 		return err;
 
-- 
2.55.0


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

end of thread, other threads:[~2026-12-03 21:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 21:01 [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check Bruno Meneguele
2026-12-03 21:18 ` Eric Biggers

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