From: Bruno Meneguele <bmeneg@redhat.com>
To: linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, herbert@gondor.apana.org.au,
davem@davemloft.net, ebiggers@google.com,
Bruno Meneguele <bmeneg@redhat.com>,
stable@vger.kernel.org, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH v2] crypto: algapi - add REQ_VIRT to shash/scomp type check
Date: Thu, 3 Dec 2026 19:31:49 -0300 [thread overview]
Message-ID: <20261203223149.71733-1-bmeneg@redhat.com> (raw)
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
next reply other threads:[~2026-12-03 22:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 22:31 Bruno Meneguele [this message]
2026-12-03 23:00 ` [PATCH v2] crypto: algapi - add REQ_VIRT to shash/scomp type check Eric Biggers
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=20261203223149.71733-1-bmeneg@redhat.com \
--to=bmeneg@redhat.com \
--cc=davem@davemloft.net \
--cc=ebiggers@google.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.