crypto: tegra - fix rctx->cryptlen in tegra_gcm_do_one_req()
Subsystems (3)
PATCH 1/1 crypto: tegra - fix rctx->cryptlen 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.
--- drivers/crypto/tegra/tegra-se-aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/tegra/tegra-se-aes.c +1 -1
@@ -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 );
Signature · 1 line
2.55.0
Ahem, missed the fixes: tag, could you please append:
Herbert Xu
maintainerQuoted 10 lines · Vladislav Dronov
Perform
rctx->cryptlencalculation integra_gcm_do_one_req()the same way it is done integra_ccm_crypt_init(). The current formulae may lead to a crash if a caller does not calltegra_gcm_setauthsize()and soctx->authsizeremains zero. Then a decrypt operation with incorrectrctx->cryptlenwill lead to a write beyoundrctx->dst_sgbuffer.Signed-off-by Vladislav Dronov <[email protected]>--- 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,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
PATCH v2 1/1 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.
--- drivers/crypto/tegra/tegra-se-aes.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
drivers/crypto/tegra/tegra-se-aes.c +3 -19
@@ -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 authsizecase 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)
Signature · 1 line
2.47.3
Herbert Xu
maintainerRe: [PATCH v2] crypto: tegra - fix rctx->cryptlen calculation in tegra_gcm_do_one_req()
Quoted 10 lines · Vladislav Dronov
Perform
rctx->cryptlencalculation integra_gcm_do_one_req()the same way it is done integra_ccm_crypt_init(). The current formulae may lead to a crash if a caller does not calltegra_gcm_setauthsize()and soctx->authsizeremains zero. Then a decrypt operation with incorrectrctx->cryptlenwill lead to a write beyoundrctx->dst_sgbuffer.As a follow-up cleanup delete struct
tegra_aead_ctx->authsizefield since it appears to be completely unused. Also simplifytegra_ccm_setauthsize()andtegra_gcm_setauthsize()functions respectively.
Quoted 5 lines
Fixes 0880bb3b00c8 ("crypto: tegra - Add Tegra Security Engine driver")Signed-off-by Vladislav Dronov <[email protected]>--- drivers/crypto/tegra/tegra-se-aes.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-)
Patch applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt