Re: [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
From: Bruno Meneguele
Date: Thu Dec 03 2026 - 16:36:57 EST
On Thu Dec 3, 2026 at 6:18 PM -03, Eric Biggers wrote:
On Thu, Dec 03, 2026 at 06:01:19PM -0300, Bruno Meneguele wrote:
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@xxxxxxxxxxxxxxx
Signed-off-by: Bruno Meneguele <bmeneg@xxxxxxxxxx>
---
crypto/ccm.c | 3 ++-
crypto/cmac.c | 3 ++-
crypto/xcbc.c | 3 ++-
3 files changed, 6 insertions(+), 3 deletions(-)
The "Handle partial blocks in API" design is still a bit perplexing to
me. But I *think* a better for this issue would actually be
crypto_check_attr_type() itself:
if (type == CRYPTO_ALG_TYPE_SHASH || type == CRYPTO_ALG_TYPE_SCOMPRESS)
type |= CRYPTO_ALG_REQ_VIRT;
That would be consistent with the documentation for
crypto_check_attr_type()'s type parameter, which says it's the algorithm
type. It doesn't say that you can pass other flags too. It would also
ensure that other templates like hmac-shash aren't missed.
Well pointed and agreed.
I'll prepare a v2.
Of course, if we take a step back, this issue also makes it clear that
~6 drivers in drivers/crypto/ (the ones that register one of the
affected algorithms) haven't been tested in the last 18 months. Such
untested crypto drivers do not belong in the kernel in the first place.
I found it while testing NVIDIA Tegra Secure Engine driver and made me wonder
the same thing (I do have another patch to submit specifically for this driver).
--
Bruno Meneguele
PGP Key: http://bmeneg.com/pubkey.txt
Attachment:
signature.asc
Description: PGP signature