From: Corentin Labbe <clabbe@baylibre.com>
To: herbert@gondor.apana.org.au, jernej.skrabec@gmail.com,
samuel@sholland.org, wens@csie.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-sunxi@lists.linux.dev, Corentin Labbe <clabbe@baylibre.com>
Subject: [PATCH 15/19] crypto: sun8i-ss: do not fallback if cryptlen is less than sg length
Date: Thu, 17 Mar 2022 20:56:01 +0000 [thread overview]
Message-ID: <20220317205605.3924836-16-clabbe@baylibre.com> (raw)
In-Reply-To: <20220317205605.3924836-1-clabbe@baylibre.com>
The sg length could be more than remaining data on it.
So check the length requirement against the minimum between those two
values.
Signed-off-by: Corentin Labbe <clabbe@baylibre.com>
---
.../allwinner/sun8i-ss/sun8i-ss-cipher.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
index 7f1940c6cc41..5bb950182026 100644
--- a/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
+++ b/drivers/crypto/allwinner/sun8i-ss/sun8i-ss-cipher.c
@@ -28,6 +28,7 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq)
struct scatterlist *in_sg = areq->src;
struct scatterlist *out_sg = areq->dst;
struct scatterlist *sg;
+ unsigned int todo, len;
if (areq->cryptlen == 0 || areq->cryptlen % 16) {
algt->stat_fb_len++;
@@ -40,13 +41,11 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq)
return true;
}
+ len = areq->cryptlen;
sg = areq->src;
while (sg) {
- if ((sg->length % 16) != 0) {
- algt->stat_fb_sglen++;
- return true;
- }
- if ((sg_dma_len(sg) % 16) != 0) {
+ todo = min(len, sg->length);
+ if ((todo % 16) != 0) {
algt->stat_fb_sglen++;
return true;
}
@@ -54,15 +53,14 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq)
algt->stat_fb_align++;
return true;
}
+ len -= todo;
sg = sg_next(sg);
}
+ len = areq->cryptlen;
sg = areq->dst;
while (sg) {
- if ((sg->length % 16) != 0) {
- algt->stat_fb_sglen++;
- return true;
- }
- if ((sg_dma_len(sg) % 16) != 0) {
+ todo = min(len, sg->length);
+ if ((todo % 16) != 0) {
algt->stat_fb_sglen++;
return true;
}
@@ -70,6 +68,7 @@ static bool sun8i_ss_need_fallback(struct skcipher_request *areq)
algt->stat_fb_align++;
return true;
}
+ len -= todo;
sg = sg_next(sg);
}
--
2.34.1
next prev parent reply other threads:[~2022-03-17 20:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-17 20:55 [PATCH 00/19] crypto: allwinner: lots of fixes Corentin Labbe
2022-03-17 20:55 ` [PATCH 01/19] crypto: sun8i-ce: Fix minor style issue Corentin Labbe
2022-03-17 20:55 ` [PATCH 02/19] crypto: sun8i-ce: do not allocate memory when handling requests Corentin Labbe
2022-03-17 20:55 ` [PATCH 03/19] crypto: sun4i-ss: do not allocate backup IV on requests Corentin Labbe
2022-03-17 20:55 ` [PATCH 04/19] crypto: sun8i-ss: rework handling of IV Corentin Labbe
2022-03-17 20:55 ` [PATCH 05/19] crypto: sun8i-ss: handle zero sized sg Corentin Labbe
2022-03-17 20:55 ` [PATCH 06/19] crypto: sun8i-ss: remove redundant test Corentin Labbe
2022-03-17 20:55 ` [PATCH 07/19] crypto: sun8i-ss: test error before assigning Corentin Labbe
2022-03-17 20:55 ` [PATCH 08/19] crypto: sun8i-ss: use sg_nents_for_len Corentin Labbe
2022-03-17 20:55 ` [PATCH 09/19] crypto: sun8i-ss: do not allocate memory when handling hash requests Corentin Labbe
2022-03-17 20:55 ` [PATCH 10/19] crypto: sun8i-ss: do not zeroize all pad Corentin Labbe
2022-03-17 20:55 ` [PATCH 11/19] crypto: sun8i-ss: handle requests if last block is not modulo 64 Corentin Labbe
2022-03-17 20:55 ` [PATCH 12/19] crypto: sun8i-ss: rework debugging Corentin Labbe
2022-03-17 20:55 ` [PATCH 13/19] crypto: sun8i-ss: Add function for handling hash padding Corentin Labbe
2022-03-17 20:56 ` [PATCH 14/19] crypto: sun8i-ss: add hmac(sha1) Corentin Labbe
2022-03-17 20:56 ` Corentin Labbe [this message]
2022-03-17 20:56 ` [PATCH 16/19] crypto: sun8i-ce: Add function for handling hash padding Corentin Labbe
2022-03-17 20:56 ` [PATCH 17/19] crypto: sun8i-ce: use sg_nents_for_len Corentin Labbe
2022-03-17 20:56 ` [PATCH 18/19] crypto: sun8i-ce: rework debugging Corentin Labbe
2022-03-17 20:56 ` [PATCH 19/19] crypto: sun8i-ce: do not fallback if cryptlen is less than sg length Corentin Labbe
2022-04-08 8:24 ` [PATCH 00/19] crypto: allwinner: lots of fixes Herbert Xu
2022-04-11 7:37 ` LABBE Corentin
2022-04-11 7:40 ` Herbert Xu
2022-04-11 8:37 ` LABBE Corentin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220317205605.3924836-16-clabbe@baylibre.com \
--to=clabbe@baylibre.com \
--cc=herbert@gondor.apana.org.au \
--cc=jernej.skrabec@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=samuel@sholland.org \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox