Commit 42a01af3 authored by Corentin Labbe's avatar Corentin Labbe Committed by Herbert Xu

crypto: sun8i-ce - do not fallback if cryptlen is less than sg length

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: default avatarCorentin Labbe <clabbe@baylibre.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent aff388f7
...@@ -27,6 +27,7 @@ static int sun8i_ce_cipher_need_fallback(struct skcipher_request *areq) ...@@ -27,6 +27,7 @@ static int sun8i_ce_cipher_need_fallback(struct skcipher_request *areq)
struct scatterlist *sg; struct scatterlist *sg;
struct skcipher_alg *alg = crypto_skcipher_alg(tfm); struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
struct sun8i_ce_alg_template *algt; struct sun8i_ce_alg_template *algt;
unsigned int todo, len;
algt = container_of(alg, struct sun8i_ce_alg_template, alg.skcipher); algt = container_of(alg, struct sun8i_ce_alg_template, alg.skcipher);
...@@ -51,28 +52,35 @@ static int sun8i_ce_cipher_need_fallback(struct skcipher_request *areq) ...@@ -51,28 +52,35 @@ static int sun8i_ce_cipher_need_fallback(struct skcipher_request *areq)
return true; return true;
} }
len = areq->cryptlen;
sg = areq->src; sg = areq->src;
while (sg) { while (sg) {
if (!IS_ALIGNED(sg->offset, sizeof(u32))) { if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
algt->stat_fb_srcali++; algt->stat_fb_srcali++;
return true; return true;
} }
if (sg->length % 4) { todo = min(len, sg->length);
if (todo % 4) {
algt->stat_fb_srclen++; algt->stat_fb_srclen++;
return true; return true;
} }
len -= todo;
sg = sg_next(sg); sg = sg_next(sg);
} }
len = areq->cryptlen;
sg = areq->dst; sg = areq->dst;
while (sg) { while (sg) {
if (!IS_ALIGNED(sg->offset, sizeof(u32))) { if (!IS_ALIGNED(sg->offset, sizeof(u32))) {
algt->stat_fb_dstali++; algt->stat_fb_dstali++;
return true; return true;
} }
if (sg->length % 4) { todo = min(len, sg->length);
if (todo % 4) {
algt->stat_fb_dstlen++; algt->stat_fb_dstlen++;
return true; return true;
} }
len -= todo;
sg = sg_next(sg); sg = sg_next(sg);
} }
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment