* [PATCH] crypto: starfive - Pad adata with zeroes
@ 2023-11-16 2:17 Jia Jie Ho
2023-11-16 4:35 ` Herbert Xu
0 siblings, 1 reply; 4+ messages in thread
From: Jia Jie Ho @ 2023-11-16 2:17 UTC (permalink / raw)
To: Herbert Xu, David S . Miller; +Cc: linux-crypto, linux-kernel
Ensure padding for adata is filled with zeroes. Additional bytes for
padding affects the ccm tag output even though input ad len has been
provided to the hardware.
Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
---
drivers/crypto/starfive/jh7110-aes.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
index 9378e6682f0e..e0fe599f8192 100644
--- a/drivers/crypto/starfive/jh7110-aes.c
+++ b/drivers/crypto/starfive/jh7110-aes.c
@@ -500,7 +500,7 @@ static int starfive_aes_prepare_req(struct skcipher_request *req,
scatterwalk_start(&cryp->out_walk, rctx->out_sg);
if (cryp->assoclen) {
- rctx->adata = kzalloc(ALIGN(cryp->assoclen, AES_BLOCK_SIZE), GFP_KERNEL);
+ rctx->adata = kzalloc(cryp->assoclen + AES_BLOCK_SIZE, GFP_KERNEL);
if (!rctx->adata)
return dev_err_probe(cryp->dev, -ENOMEM,
"Failed to alloc memory for adata");
@@ -569,7 +569,7 @@ static int starfive_aes_aead_do_one_req(struct crypto_engine *engine, void *areq
struct starfive_cryp_ctx *ctx =
crypto_aead_ctx(crypto_aead_reqtfm(req));
struct starfive_cryp_dev *cryp = ctx->cryp;
- struct starfive_cryp_request_ctx *rctx = ctx->rctx;
+ struct starfive_cryp_request_ctx *rctx;
u32 block[AES_BLOCK_32];
u32 stat;
int err;
@@ -579,6 +579,8 @@ static int starfive_aes_aead_do_one_req(struct crypto_engine *engine, void *areq
if (err)
return err;
+ rctx = ctx->rctx;
+
if (!cryp->assoclen)
goto write_text;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] crypto: starfive - Pad adata with zeroes
2023-11-16 2:17 [PATCH] crypto: starfive - Pad adata with zeroes Jia Jie Ho
@ 2023-11-16 4:35 ` Herbert Xu
2023-11-16 5:39 ` Jia Jie Ho
0 siblings, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2023-11-16 4:35 UTC (permalink / raw)
To: Jia Jie Ho; +Cc: David S . Miller, linux-crypto, linux-kernel
On Thu, Nov 16, 2023 at 10:17:52AM +0800, Jia Jie Ho wrote:
>
> diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
> index 9378e6682f0e..e0fe599f8192 100644
> --- a/drivers/crypto/starfive/jh7110-aes.c
> +++ b/drivers/crypto/starfive/jh7110-aes.c
> @@ -500,7 +500,7 @@ static int starfive_aes_prepare_req(struct skcipher_request *req,
> scatterwalk_start(&cryp->out_walk, rctx->out_sg);
>
> if (cryp->assoclen) {
> - rctx->adata = kzalloc(ALIGN(cryp->assoclen, AES_BLOCK_SIZE), GFP_KERNEL);
> + rctx->adata = kzalloc(cryp->assoclen + AES_BLOCK_SIZE, GFP_KERNEL);
Please explain why you're changing the allocation size here.
This needs to go into the patch description.
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] 4+ messages in thread* Re: [PATCH] crypto: starfive - Pad adata with zeroes
2023-11-16 4:35 ` Herbert Xu
@ 2023-11-16 5:39 ` Jia Jie Ho
2023-11-17 3:57 ` Herbert Xu
0 siblings, 1 reply; 4+ messages in thread
From: Jia Jie Ho @ 2023-11-16 5:39 UTC (permalink / raw)
To: Herbert Xu; +Cc: David S . Miller, linux-crypto, linux-kernel
On 16/11/2023 12:35 pm, Herbert Xu wrote:
> On Thu, Nov 16, 2023 at 10:17:52AM +0800, Jia Jie Ho wrote:
>>
>> diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
>> index 9378e6682f0e..e0fe599f8192 100644
>> --- a/drivers/crypto/starfive/jh7110-aes.c
>> +++ b/drivers/crypto/starfive/jh7110-aes.c
>> @@ -500,7 +500,7 @@ static int starfive_aes_prepare_req(struct skcipher_request *req,
>> scatterwalk_start(&cryp->out_walk, rctx->out_sg);
>>
>> if (cryp->assoclen) {
>> - rctx->adata = kzalloc(ALIGN(cryp->assoclen, AES_BLOCK_SIZE), GFP_KERNEL);
>> + rctx->adata = kzalloc(cryp->assoclen + AES_BLOCK_SIZE, GFP_KERNEL);
>
> Please explain why you're changing the allocation size here.
>
Hi Herbert,
The hardware requires aad padded with zeroes up to 15 bytes in some cases.
This extra size and zeroing is meant for the padding and prevents driver
accessing uninitialized memory region.
> This needs to go into the patch description.
>
I'll update the v2 commit message if you're good with this implementation.
Thanks for reviewing this.
Jia Jie
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-17 3:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 2:17 [PATCH] crypto: starfive - Pad adata with zeroes Jia Jie Ho
2023-11-16 4:35 ` Herbert Xu
2023-11-16 5:39 ` Jia Jie Ho
2023-11-17 3:57 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox