* [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA
@ 2024-04-29 6:06 Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message Jia Jie Ho
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Jia Jie Ho @ 2024-04-29 6:06 UTC (permalink / raw
To: Herbert Xu, David S . Miller, linux-crypto, linux-kernel
This patch series fix a bug caused by freeing a stack buffer in RSA
module and skip some unneeded steps in StarFive crypto driver.
Jia Jie Ho (4):
crypto: starfive - Skip dma setup for zeroed message
crypto: starfive: Skip unneeded fallback allocation
crypto: starfive: Do not free stack buffer
crypto: starfive: Use fallback for unaligned dma access
drivers/crypto/starfive/jh7110-aes.c | 16 +++++++++++-----
drivers/crypto/starfive/jh7110-rsa.c | 11 ++++-------
2 files changed, 15 insertions(+), 12 deletions(-)
--
2.40.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message
2024-04-29 6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
@ 2024-04-29 6:06 ` Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 2/4] crypto: starfive: Skip unneeded fallback allocation Jia Jie Ho
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jia Jie Ho @ 2024-04-29 6:06 UTC (permalink / raw
To: Herbert Xu, David S . Miller, linux-crypto, linux-kernel
Skip dma setup and mapping for AES driver if plaintext is empty.
Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
---
drivers/crypto/starfive/jh7110-aes.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
index 72b7d46150d5..9d6e2f936f03 100644
--- a/drivers/crypto/starfive/jh7110-aes.c
+++ b/drivers/crypto/starfive/jh7110-aes.c
@@ -590,12 +590,16 @@ static int starfive_aes_do_one_req(struct crypto_engine *engine, void *areq)
if (ret)
return ret;
+ if (!cryp->total_in)
+ goto finish_req;
+
starfive_aes_dma_init(cryp);
ret = starfive_aes_map_sg(cryp, rctx->in_sg, rctx->out_sg);
if (ret)
return ret;
+finish_req:
starfive_aes_finish_req(ctx);
return 0;
--
2.40.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 2/4] crypto: starfive: Skip unneeded fallback allocation
2024-04-29 6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message Jia Jie Ho
@ 2024-04-29 6:06 ` Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 3/4] crypto: starfive: Do not free stack buffer Jia Jie Ho
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Jia Jie Ho @ 2024-04-29 6:06 UTC (permalink / raw
To: Herbert Xu, David S . Miller, linux-crypto, linux-kernel
Skip sw fallback allocation if RSA module failed to get device handle.
Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
---
drivers/crypto/starfive/jh7110-rsa.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/crypto/starfive/jh7110-rsa.c b/drivers/crypto/starfive/jh7110-rsa.c
index e642e948d747..4d7eb3d1e764 100644
--- a/drivers/crypto/starfive/jh7110-rsa.c
+++ b/drivers/crypto/starfive/jh7110-rsa.c
@@ -537,16 +537,14 @@ static int starfive_rsa_init_tfm(struct crypto_akcipher *tfm)
{
struct starfive_cryp_ctx *ctx = akcipher_tfm_ctx(tfm);
+ ctx->cryp = starfive_cryp_find_dev(ctx);
+ if (!ctx->cryp)
+ return -ENODEV;
+
ctx->akcipher_fbk = crypto_alloc_akcipher("rsa-generic", 0, 0);
if (IS_ERR(ctx->akcipher_fbk))
return PTR_ERR(ctx->akcipher_fbk);
- ctx->cryp = starfive_cryp_find_dev(ctx);
- if (!ctx->cryp) {
- crypto_free_akcipher(ctx->akcipher_fbk);
- return -ENODEV;
- }
-
akcipher_set_reqsize(tfm, sizeof(struct starfive_cryp_request_ctx) +
sizeof(struct crypto_akcipher) + 32);
--
2.40.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 3/4] crypto: starfive: Do not free stack buffer
2024-04-29 6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 2/4] crypto: starfive: Skip unneeded fallback allocation Jia Jie Ho
@ 2024-04-29 6:06 ` Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 4/4] crypto: starfive: Use fallback for unaligned dma access Jia Jie Ho
2024-05-10 9:18 ` [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Herbert Xu
4 siblings, 0 replies; 6+ messages in thread
From: Jia Jie Ho @ 2024-04-29 6:06 UTC (permalink / raw
To: Herbert Xu, David S . Miller, linux-crypto, linux-kernel
RSA text data uses variable length buffer allocated in software stack.
Calling kfree on it causes undefined behaviour in subsequent operations.
Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
---
drivers/crypto/starfive/jh7110-rsa.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/crypto/starfive/jh7110-rsa.c b/drivers/crypto/starfive/jh7110-rsa.c
index 4d7eb3d1e764..33093ba4b13a 100644
--- a/drivers/crypto/starfive/jh7110-rsa.c
+++ b/drivers/crypto/starfive/jh7110-rsa.c
@@ -276,7 +276,6 @@ static int starfive_rsa_enc_core(struct starfive_cryp_ctx *ctx, int enc)
err_rsa_crypt:
writel(STARFIVE_RSA_RESET, cryp->base + STARFIVE_PKA_CACR_OFFSET);
- kfree(rctx->rsa_data);
return ret;
}
--
2.40.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 4/4] crypto: starfive: Use fallback for unaligned dma access
2024-04-29 6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
` (2 preceding siblings ...)
2024-04-29 6:06 ` [PATCH -next 3/4] crypto: starfive: Do not free stack buffer Jia Jie Ho
@ 2024-04-29 6:06 ` Jia Jie Ho
2024-05-10 9:18 ` [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Herbert Xu
4 siblings, 0 replies; 6+ messages in thread
From: Jia Jie Ho @ 2024-04-29 6:06 UTC (permalink / raw
To: Herbert Xu, David S . Miller, linux-crypto, linux-kernel
Dma address mapping fails on unaligned scatterlist offset. Use sw
fallback for these cases.
Signed-off-by: Jia Jie Ho <jiajie.ho@starfivetech.com>
---
drivers/crypto/starfive/jh7110-aes.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/crypto/starfive/jh7110-aes.c b/drivers/crypto/starfive/jh7110-aes.c
index 9d6e2f936f03..86a1a1fa9f8f 100644
--- a/drivers/crypto/starfive/jh7110-aes.c
+++ b/drivers/crypto/starfive/jh7110-aes.c
@@ -314,7 +314,7 @@ static int starfive_aes_read_authtag(struct starfive_cryp_ctx *ctx)
cryp->total_in, cryp->authsize, 1);
} else {
if (crypto_memneq(cryp->tag_in, cryp->tag_out, cryp->authsize))
- return dev_err_probe(cryp->dev, -EBADMSG, "Failed tag verification\n");
+ return -EBADMSG;
}
return 0;
@@ -753,14 +753,16 @@ static bool starfive_aes_check_unaligned(struct starfive_cryp_dev *cryp,
int i;
for_each_sg(src, tsg, sg_nents(src), i)
- if (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
- !sg_is_last(tsg))
+ if (!IS_ALIGNED(tsg->offset, sizeof(u32)) ||
+ (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
+ !sg_is_last(tsg)))
return true;
if (src != dst)
for_each_sg(dst, tsg, sg_nents(dst), i)
- if (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
- !sg_is_last(tsg))
+ if (!IS_ALIGNED(tsg->offset, sizeof(u32)) ||
+ (!IS_ALIGNED(tsg->length, AES_BLOCK_SIZE) &&
+ !sg_is_last(tsg)))
return true;
return false;
--
2.40.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA
2024-04-29 6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
` (3 preceding siblings ...)
2024-04-29 6:06 ` [PATCH -next 4/4] crypto: starfive: Use fallback for unaligned dma access Jia Jie Ho
@ 2024-05-10 9:18 ` Herbert Xu
4 siblings, 0 replies; 6+ messages in thread
From: Herbert Xu @ 2024-05-10 9:18 UTC (permalink / raw
To: Jia Jie Ho; +Cc: David S . Miller, linux-crypto, linux-kernel
On Mon, Apr 29, 2024 at 02:06:36PM +0800, Jia Jie Ho wrote:
> This patch series fix a bug caused by freeing a stack buffer in RSA
> module and skip some unneeded steps in StarFive crypto driver.
>
> Jia Jie Ho (4):
> crypto: starfive - Skip dma setup for zeroed message
> crypto: starfive: Skip unneeded fallback allocation
> crypto: starfive: Do not free stack buffer
> crypto: starfive: Use fallback for unaligned dma access
>
> drivers/crypto/starfive/jh7110-aes.c | 16 +++++++++++-----
> drivers/crypto/starfive/jh7110-rsa.c | 11 ++++-------
> 2 files changed, 15 insertions(+), 12 deletions(-)
>
> --
> 2.40.1
All 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] 6+ messages in thread
end of thread, other threads:[~2024-05-10 9:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-29 6:06 [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 1/4] crypto: starfive - Skip dma setup for zeroed message Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 2/4] crypto: starfive: Skip unneeded fallback allocation Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 3/4] crypto: starfive: Do not free stack buffer Jia Jie Ho
2024-04-29 6:06 ` [PATCH -next 4/4] crypto: starfive: Use fallback for unaligned dma access Jia Jie Ho
2024-05-10 9:18 ` [PATCH -next 0/4] crypto: starfive - Minor fixes for AES and RSA Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).