* [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
2026-12-03 21:21 ` sashiko-bot
0 siblings, 2 replies; 4+ 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] 4+ messages in thread* Re: [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
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
2026-12-03 21:36 ` Bruno Meneguele
2026-12-03 21:21 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Eric Biggers @ 2026-12-03 21:18 UTC (permalink / raw)
To: Bruno Meneguele; +Cc: linux-crypto, linux-kernel, herbert, davem, stable
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@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(-)
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.
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.
- Eric
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
2026-12-03 21:18 ` Eric Biggers
@ 2026-12-03 21:36 ` Bruno Meneguele
0 siblings, 0 replies; 4+ messages in thread
From: Bruno Meneguele @ 2026-12-03 21:36 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto, linux-kernel, herbert, davem, stable
[-- Attachment #1: Type: text/plain, Size: 2652 bytes --]
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@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(-)
>
> 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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
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
@ 2026-12-03 21:21 ` sashiko-bot
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-03 21:21 UTC (permalink / raw)
To: Bruno Meneguele, linux-crypto; +Cc: herbert, davem, ebiggers
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] crypto: hmac_create_shash() omitted from CRYPTO_ALG_REQ_VIRT
type check
--
commit dd045144cfb684760383283e25dcfff6615c568c
Author: Bruno Meneguele <bmeneg@redhat.com>
crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
This commit updates cbcmac_create(), cmac_create(), and xcbc_create() to
pass CRYPTO_ALG_TYPE_SHASH | CRYPTO_ALG_REQ_VIRT to
crypto_check_attr_type(), so that fallback lookups from
crypto_ahash_init_tfm() with CRYPTO_ALG_REQ_VIRT set are accepted.
[ ... ]
> diff --git a/crypto/cmac.c b/crypto/cmac.c
> index 83e58937f0136..74786612a6f16 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;
[Severity: Low]
Should hmac_create_shash() in crypto/hmac.c also include
CRYPTO_ALG_REQ_VIRT?
shash_prepare_alg() sets CRYPTO_ALG_REQ_VIRT on every registered shash
instance, and hmac_create_shash() is the only remaining shash template
still calling crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_SHASH, &mask).
Via crypto_add_alg(), a NETLINK_CRYPTO CRYPTO_MSG_NEWALG request for
hmac-shash(...) with CRYPTO_ALG_REQ_VIRT set in type and mask fails with
-ENOENT, while a request requiring it clear still registers the shash
instance and fails re-lookup with -EAGAIN.
Updating hmac_create_shash() as well, or handling CRYPTO_ALG_REQ_VIRT
centrally for CRYPTO_ALG_TYPE_SHASH in crypto_check_attr_type(), would
keep all four shash templates consistent and avoid repeating the flag in
future shash templates.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203210119.42352-1-bmeneg@redhat.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 21:36 UTC | newest]
Thread overview: 4+ 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
2026-12-03 21:36 ` Bruno Meneguele
2026-12-03 21:21 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox