[PATCH v2] crypto: algapi - add REQ_VIRT to shash/scomp type check
From: Bruno Meneguele
Date: Thu Dec 03 2026 - 17:32:19 EST
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@xxxxxxxxxxxxxxx
Suggested-by: Eric Biggers <ebiggers@xxxxxxxxxx>
Signed-off-by: Bruno Meneguele <bmeneg@xxxxxxxxxx>
---
v2: moved fix into crypto_check_attr_type() instead of each shash template
v1: https://lore.kernel.org/all/20261203210119.42352-1-bmeneg@xxxxxxxxxx/
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