Some skcipher algo has no IV buffer such as ecb(aes) also, here add checking with ivsize. Signed-off-by: Bibo Mao --- .../virtio/virtio_crypto_skcipher_algs.c | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c b/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c index 3d47e7c30c6b..a5e6993da2ef 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--) @@ -437,7 +441,8 @@ __virtio_crypto_skcipher_do_req(struct virtio_crypto_sym_request *vc_sym_req, return 0; free_iv: - memzero_explicit(iv, ivsize); + if (ivsize) + memzero_explicit(iv, ivsize); free: memzero_explicit(req_data, sizeof(*req_data)); kfree(sgs); @@ -543,11 +548,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