Some skcipher algo has no IV buffer such as ecb(aes) also, here add checking with ivsize.
Signed-off-by: Bibo Mao <[email protected]> --- .../virtio/virtio_crypto_skcipher_algs.c | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c index c911b7ba8f13..b4b79121c37c 100644 --- a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c @@ -345,7 +345,9 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req, src_nents, dst_nents); /* Why 3? outhdr + iv + inhdr */ - sg_total = src_nents + dst_nents + 3; + sg_total = src_nents + dst_nents + 2; + if (ivsize) + sg_total += 1; sgs = kcalloc_node(sg_total, sizeof(*sgs), GFP_KERNEL, dev_to_node(&vcrypto->vdev->dev)); if (!sgs) @@ -402,15 +404,17 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req, * Avoid to do DMA from the stack, switch to using * dynamically-allocated for the IV */ - iv = vc_sym_req->iv; - memcpy(iv, req->iv, ivsize); - if (!vc_sym_req->encrypt) - scatterwalk_map_and_copy(req->iv, req->src, - req->cryptlen - ivsize, - ivsize, 0); - - sg_init_one(&iv_sg, iv, ivsize); - sgs[num_out++] = &iv_sg; + if (ivsize) { + iv = vc_sym_req->iv; + memcpy(iv, req->iv, ivsize); + if (!vc_sym_req->encrypt) + scatterwalk_map_and_copy(req->iv, req->src, + req->cryptlen - ivsize, + ivsize, 0); + + sg_init_one(&iv_sg, iv, ivsize); + sgs[num_out++] = &iv_sg; + } /* Source data */ for (sg = req->src; src_nents; sg = sg_next(sg), src_nents--) @@ -542,11 +546,13 @@ static void virtio_crypto_skcipher_finalize_req( struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); unsigned int ivsize = crypto_skcipher_ivsize(tfm); - if (vc_sym_req->encrypt) - scatterwalk_map_and_copy(req->iv, req->dst, - req->cryptlen - ivsize, - ivsize, 0); - memzero_explicit(vc_sym_req->iv, ivsize); + if (ivsize) { + if (vc_sym_req->encrypt) + scatterwalk_map_and_copy(req->iv, req->dst, + req->cryptlen - ivsize, + ivsize, 0); + memzero_explicit(vc_sym_req->iv, ivsize); + } virtcrypto_clear_request(&vc_sym_req->base); crypto_finalize_skcipher_request(vc_sym_req->base.dataq->engine, -- 2.39.3
