From: Bruno Meneguele <bmeneg@redhat.com>
To: linux-crypto@vger.kernel.org, linux-tegra@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, herbert@gondor.apana.org.au,
akhilrajeev@nvidia.com, thierry.reding@kernel.org,
jonathanh@nvidia.com, thuth@redhat.com,
Bruno Meneguele <bmeneg@redhat.com>,
stable@vger.kernel.org
Subject: [PATCH] crypto: tegra - Fix empty message check on cmac final()
Date: Thu, 3 Dec 2026 23:26:32 -0300 [thread overview]
Message-ID: <20261204022632.462133-1-bmeneg@redhat.com> (raw)
The fallback tfm is being called on tegra_cmac_do_final() with the assumption
that the message with nbytes == 0 is empty, however tegra_cmac_do_update()
always keeps the last block of the message, full or partial, in the residue
buffer for tegra_cmac_do_final(), while req->nbytes is always set to 0 by
crypto_ahash_final(), meaning we have a request with nbytes == 0 but
residue.size > 0.
Checked on a NVIDIA Orin IGX system during its self-test:
alg: ahash: tegra-se-cmac test failed (wrong result) on test vector 1,
cfg="init+update+final aligned buffer"
alg: self-tests for cmac(aes) using tegra-se-cmac failed (rc=-22)
And no self-tests failures after the patch applied. From /proc/crypto:
driver : tegra-se-cmac
module : tegra_se
...
selftest : passed
This commit changes the check to use the residue size instead of req->nbytes and
also free the residue buffer on the fallback path, which was being skipped,
leaking it on every CMAC of an empty message.
Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Cc: stable@vger.kernel.org
Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
---
drivers/crypto/tegra/tegra-se-aes.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/crypto/tegra/tegra-se-aes.c b/drivers/crypto/tegra/tegra-se-aes.c
index 0fd1d7035899..122c3345b7e7 100644
--- a/drivers/crypto/tegra/tegra-se-aes.c
+++ b/drivers/crypto/tegra/tegra-se-aes.c
@@ -1647,9 +1647,11 @@ static int tegra_cmac_do_final(struct ahash_request *req)
u32 *result = (u32 *)req->result;
int ret = 0, i, cmdlen;
- if (!req->nbytes && !rctx->total_len && ctx->fallback_tfm) {
- return crypto_shash_tfm_digest(ctx->fallback_tfm,
- NULL, 0, req->result);
+ /* After update, leftover data is kept in the residue buffer. */
+ if (!rctx->residue.size && !rctx->total_len && ctx->fallback_tfm) {
+ ret = crypto_shash_tfm_digest(ctx->fallback_tfm, NULL, 0,
+ req->result);
+ goto out_free;
}
if (rctx->residue.size) {
--
2.52.0
reply other threads:[~2026-12-04 2:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204022632.462133-1-bmeneg@redhat.com \
--to=bmeneg@redhat.com \
--cc=akhilrajeev@nvidia.com \
--cc=herbert@gondor.apana.org.au \
--cc=jonathanh@nvidia.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=thierry.reding@kernel.org \
--cc=thuth@redhat.com \
/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
all inboxes | Powered by JetHome®