Greg Kroah-Hartman
2019-Dec-29 17:19 UTC
[PATCH 4.14 121/161] crypto: virtio - deal with unsupported input sizes
From: Ard Biesheuvel <ardb at kernel.org> [ Upstream commit 19c5da7d4a2662e85ea67d2d81df57e038fde3ab ] 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: dbaf0624ffa5 ("crypto: add virtio-crypto driver") Cc: "Michael S. Tsirkin" <mst at redhat.com> Cc: Jason Wang <jasowang at redhat.com> Cc: Gonglei <arei.gonglei at huawei.com> Cc: virtualization at lists.linux-foundation.org Signed-off-by: Ard Biesheuvel <ardb at kernel.org> Signed-off-by: Herbert Xu <herbert at gondor.apana.org.au> Signed-off-by: Sasha Levin <sashal at kernel.org> --- drivers/crypto/virtio/virtio_crypto_algs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/virtio/virtio_crypto_algs.c b/drivers/crypto/virtio/virtio_crypto_algs.c index 5035b0dc1e40..e2231a1a05a1 100644 --- a/drivers/crypto/virtio/virtio_crypto_algs.c +++ b/drivers/crypto/virtio/virtio_crypto_algs.c @@ -110,8 +110,6 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *alg) *alg = VIRTIO_CRYPTO_CIPHER_AES_CBC; break; default: - pr_err("virtio_crypto: Unsupported key length: %d\n", - key_len); return -EINVAL; } return 0; @@ -485,6 +483,11 @@ static int virtio_crypto_ablkcipher_encrypt(struct ablkcipher_request *req) /* Use the first data virtqueue as default */ struct data_queue *data_vq = &vcrypto->data_vq[0]; + if (!req->nbytes) + return 0; + if (req->nbytes % AES_BLOCK_SIZE) + return -EINVAL; + vc_req->dataq = data_vq; vc_req->alg_cb = virtio_crypto_dataq_sym_callback; vc_sym_req->ablkcipher_ctx = ctx; @@ -505,6 +508,11 @@ static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req) /* Use the first data virtqueue as default */ struct data_queue *data_vq = &vcrypto->data_vq[0]; + if (!req->nbytes) + return 0; + if (req->nbytes % AES_BLOCK_SIZE) + return -EINVAL; + vc_req->dataq = data_vq; vc_req->alg_cb = virtio_crypto_dataq_sym_callback; vc_sym_req->ablkcipher_ctx = ctx; -- 2.20.1
Seemingly Similar Threads
- [PATCH AUTOSEL 4.14 113/130] crypto: virtio - deal with unsupported input sizes
- [PATCH AUTOSEL 5.4 297/350] crypto: virtio - deal with unsupported input sizes
- [PATCH AUTOSEL 4.19 154/177] crypto: virtio - deal with unsupported input sizes
- [PATCH 4.19 167/219] crypto: virtio - deal with unsupported input sizes
- [PATCH 5.4 315/434] crypto: virtio - deal with unsupported input sizes