Skip to content

Commit 19c5da7

Browse files
ardbiesheuvelherbertx
authored andcommitted
crypto: virtio - deal with unsupported input sizes
Return -EINVAL for input sizes that are not a multiple of the AES block size, since they are not supported by our CBC chaining mode. While at it, remove the pr_err() that reports unsupported key sizes being used: we shouldn't spam the kernel log with that. Fixes: dbaf062 ("crypto: add virtio-crypto driver") Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Jason Wang <jasowang@redhat.com> Cc: Gonglei <arei.gonglei@huawei.com> Cc: virtualization@lists.linux-foundation.org Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 500e680 commit 19c5da7

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎drivers/crypto/virtio/virtio_crypto_algs.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *alg)
105105
*alg = VIRTIO_CRYPTO_CIPHER_AES_CBC;
106106
break;
107107
default:
108-
pr_err("virtio_crypto: Unsupported key length: %d\n",
109-
key_len);
110108
return -EINVAL;
111109
}
112110
return 0;
@@ -489,6 +487,11 @@ static int virtio_crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
489487
/* Use the first data virtqueue as default */
490488
struct data_queue *data_vq = &vcrypto->data_vq[0];
491489

490+
if (!req->nbytes)
491+
return 0;
492+
if (req->nbytes % AES_BLOCK_SIZE)
493+
return -EINVAL;
494+
492495
vc_req->dataq = data_vq;
493496
vc_req->alg_cb = virtio_crypto_dataq_sym_callback;
494497
vc_sym_req->ablkcipher_ctx = ctx;
@@ -509,6 +512,11 @@ static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
509512
/* Use the first data virtqueue as default */
510513
struct data_queue *data_vq = &vcrypto->data_vq[0];
511514

515+
if (!req->nbytes)
516+
return 0;
517+
if (req->nbytes % AES_BLOCK_SIZE)
518+
return -EINVAL;
519+
512520
vc_req->dataq = data_vq;
513521
vc_req->alg_cb = virtio_crypto_dataq_sym_callback;
514522
vc_sym_req->ablkcipher_ctx = ctx;

0 commit comments

Comments
 (0)