mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] crypto: tegra - Fix empty message check on cmac final()
@ 2026-12-04  2:26 Bruno Meneguele
  0 siblings, 0 replies; only message in thread
From: Bruno Meneguele @ 2026-12-04  2:26 UTC (permalink / raw)
  To: linux-crypto, linux-tegra
  Cc: linux-kernel, herbert, akhilrajeev, thierry.reding, jonathanh,
	thuth, Bruno Meneguele, stable

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04  2:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04  2:26 [PATCH] crypto: tegra - Fix empty message check on cmac final() Bruno Meneguele

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®