Merge: [RHEL-9.9] crypto: tegra - fix rctx->cryptlen calculation

MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/8466

JIRA: https://redhat.atlassian.net/browse/RHEL-168738

Backported from tree(s): crypto, cryptodev

```
crypto: tegra - fix rctx->cryptlen calculation in tegra_gcm_do_one_req()

Perform rctx->cryptlen calculation in tegra_gcm_do_one_req() the same way
it is done in tegra_ccm_crypt_init(). The current formulae may lead to a
crash if a caller does not call tegra_gcm_setauthsize() and so ctx->authsize
remains zero. Then a decrypt operation with incorrect rctx->cryptlen will
lead to a write beyound rctx->dst_sg buffer.

As a follow-up cleanup delete struct tegra_aead_ctx->authsize field since
it appears to be completely unused. Also simplify tegra_ccm_setauthsize()
and tegra_gcm_setauthsize() functions respectively.

Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
Signed-off-by: Vladislav Dronov <vdronov@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
(cherry picked from commit 360f2974fcea49c61f6d6f81554741a9eeee7168)

```

Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
[^footer]: Created 2026-08-03 21:40 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://redhat.atlassian.net/secure/CreateIssueDetails!init.jspa?pid=11779&issuetype=10016&priority=10001&summary=backporter+webhook+issue&components=66291) [^footer]

Approved-by: Vladislav Dronov <vdronov@redhat.com>
Approved-by: Tony Camuso <tcamuso@redhat.com>
Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com>

Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
This commit is contained in:
CKI KWF Bot
2026-08-04 08:12:00 +00:00
+3 -19
View File
@@ -45,7 +45,6 @@ struct tegra_aes_reqctx {
struct tegra_aead_ctx { struct tegra_aead_ctx {
struct tegra_se *se; struct tegra_se *se;
unsigned int authsize;
u32 alg; u32 alg;
u32 key_id; u32 key_id;
u32 keylen; u32 keylen;
@@ -1290,7 +1289,7 @@ static int tegra_gcm_do_one_req(struct crypto_engine *engine, void *areq)
if (rctx->encrypt) if (rctx->encrypt)
rctx->cryptlen = req->cryptlen; rctx->cryptlen = req->cryptlen;
else else
rctx->cryptlen = req->cryptlen - ctx->authsize; rctx->cryptlen = req->cryptlen - rctx->authsize;
memcpy(rctx->iv, req->iv, GCM_AES_IV_SIZE); memcpy(rctx->iv, req->iv, GCM_AES_IV_SIZE);
rctx->iv[3] = (1 << 24); rctx->iv[3] = (1 << 24);
@@ -1394,8 +1393,6 @@ static int tegra_aead_cra_init(struct crypto_aead *tfm)
static int tegra_ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize) static int tegra_ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
{ {
struct tegra_aead_ctx *ctx = crypto_aead_ctx(tfm);
switch (authsize) { switch (authsize) {
case 4: case 4:
case 6: case 6:
@@ -1404,28 +1401,15 @@ static int tegra_ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize
case 12: case 12:
case 14: case 14:
case 16: case 16:
break; return 0;
default: default:
return -EINVAL; return -EINVAL;
} }
ctx->authsize = authsize;
return 0;
} }
static int tegra_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize) static int tegra_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
{ {
struct tegra_aead_ctx *ctx = crypto_aead_ctx(tfm); return crypto_gcm_check_authsize(authsize);
int ret;
ret = crypto_gcm_check_authsize(authsize);
if (ret)
return ret;
ctx->authsize = authsize;
return 0;
} }
static void tegra_aead_cra_exit(struct crypto_aead *tfm) static void tegra_aead_cra_exit(struct crypto_aead *tfm)