Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH v2] crypto: algapi - add REQ_VIRT to shash/scomp type check
@ 2026-12-03 22:31 Bruno Meneguele
  2026-12-03 23:00 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Meneguele @ 2026-12-03 22:31 UTC (permalink / raw)
  To: linux-crypto
  Cc: linux-kernel, herbert, davem, ebiggers, Bruno Meneguele, stable,
	Eric Biggers

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

However, templates like cmac, xcbc and cbcmac validates 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, and fails with -EINVAL in the current code because
REQ_VIRT flag is missing from 'type' during comparison.

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)

Considering shash and scomp algorithms always carry CRYPTO_ALG_REQ_VIRT, add the
flag to the type for those two directly, so the check validates every template.

Fixes: 9d7a0ab1c753 ("crypto: ahash - Handle partial blocks in API")
Cc: stable@vger.kernel.org
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
---
v2: moved fix into crypto_check_attr_type() instead of each shash template
v1: https://lore.kernel.org/all/20261203210119.42352-1-bmeneg@redhat.com/

 crypto/algapi.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/crypto/algapi.c b/crypto/algapi.c
index a6839e2a20f3..343e989a5a08 100644
--- a/crypto/algapi.c
+++ b/crypto/algapi.c
@@ -916,6 +916,10 @@ int crypto_check_attr_type(struct rtattr **tb, u32 type, u32 *mask_ret)
 	if (IS_ERR(algt))
 		return PTR_ERR(algt);

+	/* shash and scomp algs always set REQ_VIRT */
+	if (type == CRYPTO_ALG_TYPE_SHASH || type == CRYPTO_ALG_TYPE_SCOMPRESS)
+		type |= CRYPTO_ALG_REQ_VIRT;
+
 	if ((algt->type ^ type) & algt->mask)
 		return -EINVAL;

--
2.55.0


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

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

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 22:31 [PATCH v2] crypto: algapi - add REQ_VIRT to shash/scomp type check Bruno Meneguele
2026-12-03 23:00 ` Eric Biggers

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