From: "Bruno Meneguele" <bmeneg@redhat.com>
To: "Eric Biggers" <ebiggers@kernel.org>
Cc: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<herbert@gondor.apana.org.au>, <davem@davemloft.net>,
<stable@vger.kernel.org>
Subject: Re: [PATCH] crypto: cmac,xcbc,ccm - accept CRYPTO_ALG_REQ_VIRT in template type check
Date: Thu, 03 Dec 2026 18:36:38 -0300 [thread overview]
Message-ID: <DNBF6QTUHJ47.1DKL5YSHI4K2V@redhat.com> (raw)
In-Reply-To: <20261203211816.GA601100@google.com>
[-- 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 --]
prev parent reply other threads:[~2026-12-03 21:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DNBF6QTUHJ47.1DKL5YSHI4K2V@redhat.com \
--to=bmeneg@redhat.com \
--cc=davem@davemloft.net \
--cc=ebiggers@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox