* [PATCH] crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req()
@ 2026-07-19 17:13 Vladislav Dronov
2026-07-19 17:46 ` Vladislav Dronov
2026-07-20 1:20 ` Herbert Xu
0 siblings, 2 replies; 5+ messages in thread
From: Vladislav Dronov @ 2026-07-19 17:13 UTC (permalink / raw)
To: Akhil R, Herbert Xu, David S. Miller, Thierry Reding,
Jonathan Hunter
Cc: linux-crypto, linux-tegra, linux-kernel, vdronov
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.
Signed-off-by: Vladislav Dronov <vdronov@redhat.com>
---
drivers/crypto/tegra/tegra-se-aes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/crypto/tegra/tegra-se-aes.c b/drivers/crypto/tegra/tegra-se-aes.c
index 9094c03e991f..920864751ac7 100644
--- a/drivers/crypto/tegra/tegra-se-aes.c
+++ b/drivers/crypto/tegra/tegra-se-aes.c
@@ -1290,7 +1290,7 @@ static int tegra_gcm_do_one_req(struct crypto_engine *engine, void *areq)
if (rctx->encrypt)
rctx->cryptlen = req->cryptlen;
else
- rctx->cryptlen = req->cryptlen - ctx->authsize;
+ rctx->cryptlen = req->cryptlen - rctx->authsize;
memcpy(rctx->iv, req->iv, GCM_AES_IV_SIZE);
rctx->iv[3] = (1 << 24);
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req()
2026-07-19 17:13 [PATCH] crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req() Vladislav Dronov
@ 2026-07-19 17:46 ` Vladislav Dronov
2026-07-20 1:20 ` Herbert Xu
1 sibling, 0 replies; 5+ messages in thread
From: Vladislav Dronov @ 2026-07-19 17:46 UTC (permalink / raw)
To: Akhil R, Herbert Xu, David S. Miller, Thierry Reding,
Jonathan Hunter
Cc: linux-crypto, linux-tegra, linux-kernel, vdronov
Ahem, missed the fixes: tag, could you please append:
Fixes: 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req()
2026-07-19 17:13 [PATCH] crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req() Vladislav Dronov
2026-07-19 17:46 ` Vladislav Dronov
@ 2026-07-20 1:20 ` Herbert Xu
2026-07-20 22:33 ` [PATCH v2] crypto: tegra - fix rctx->cryptlen calculation " Vladislav Dronov
1 sibling, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2026-07-20 1:20 UTC (permalink / raw)
To: Vladislav Dronov
Cc: Akhil R, David S. Miller, Thierry Reding, Jonathan Hunter,
linux-crypto, linux-tegra, linux-kernel
On Sun, Jul 19, 2026 at 07:13:02PM +0200, Vladislav Dronov wrote:
> 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.
>
> Signed-off-by: Vladislav Dronov <vdronov@redhat.com>
> ---
> drivers/crypto/tegra/tegra-se-aes.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Thanks Vladis.
Please also do a follow-up cleanup that deletes ctx->authsize since
it appears to be completely unused.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] crypto: tegra - fix rctx->cryptlen calculation in tegra_gcm_do_one_req()
2026-07-20 1:20 ` Herbert Xu
@ 2026-07-20 22:33 ` Vladislav Dronov
2026-07-30 7:40 ` Herbert Xu
0 siblings, 1 reply; 5+ messages in thread
From: Vladislav Dronov @ 2026-07-20 22:33 UTC (permalink / raw)
To: Akhil R, Herbert Xu, David S. Miller, Thierry Reding,
Jonathan Hunter
Cc: linux-crypto, linux-tegra, linux-kernel, vdronov
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>
---
drivers/crypto/tegra/tegra-se-aes.c | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/drivers/crypto/tegra/tegra-se-aes.c b/drivers/crypto/tegra/tegra-se-aes.c
index 9094c03e991f6..0fd1d70358996 100644
--- a/drivers/crypto/tegra/tegra-se-aes.c
+++ b/drivers/crypto/tegra/tegra-se-aes.c
@@ -45,7 +45,6 @@ struct tegra_aes_reqctx {
struct tegra_aead_ctx {
struct tegra_se *se;
- unsigned int authsize;
u32 alg;
u32 key_id;
u32 keylen;
@@ -1290,7 +1289,7 @@ static int tegra_gcm_do_one_req(struct crypto_engine *engine, void *areq)
if (rctx->encrypt)
rctx->cryptlen = req->cryptlen;
else
- rctx->cryptlen = req->cryptlen - ctx->authsize;
+ rctx->cryptlen = req->cryptlen - rctx->authsize;
memcpy(rctx->iv, req->iv, GCM_AES_IV_SIZE);
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)
{
- struct tegra_aead_ctx *ctx = crypto_aead_ctx(tfm);
-
switch (authsize) {
case 4:
case 6:
@@ -1404,28 +1401,15 @@ static int tegra_ccm_setauthsize(struct crypto_aead *tfm, unsigned int authsize
case 12:
case 14:
case 16:
- break;
+ return 0;
default:
return -EINVAL;
}
-
- ctx->authsize = authsize;
-
- return 0;
}
static int tegra_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
{
- struct tegra_aead_ctx *ctx = crypto_aead_ctx(tfm);
- int ret;
-
- ret = crypto_gcm_check_authsize(authsize);
- if (ret)
- return ret;
-
- ctx->authsize = authsize;
-
- return 0;
+ return crypto_gcm_check_authsize(authsize);
}
static void tegra_aead_cra_exit(struct crypto_aead *tfm)
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2] crypto: tegra - fix rctx->cryptlen calculation in tegra_gcm_do_one_req()
2026-07-20 22:33 ` [PATCH v2] crypto: tegra - fix rctx->cryptlen calculation " Vladislav Dronov
@ 2026-07-30 7:40 ` Herbert Xu
0 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2026-07-30 7:40 UTC (permalink / raw)
To: Vladislav Dronov
Cc: Akhil R, David S. Miller, Thierry Reding, Jonathan Hunter,
linux-crypto, linux-tegra, linux-kernel
On Tue, Jul 21, 2026 at 12:33:31AM +0200, Vladislav Dronov wrote:
> 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>
> ---
> drivers/crypto/tegra/tegra-se-aes.c | 22 +++-------------------
> 1 file changed, 3 insertions(+), 19 deletions(-)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-30 7:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-19 17:13 [PATCH] crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req() Vladislav Dronov
2026-07-19 17:46 ` Vladislav Dronov
2026-07-20 1:20 ` Herbert Xu
2026-07-20 22:33 ` [PATCH v2] crypto: tegra - fix rctx->cryptlen calculation " Vladislav Dronov
2026-07-30 7:40 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox