Commit 19c5da7d authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Herbert Xu

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: dbaf0624 ("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: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 500e6807
...@@ -105,8 +105,6 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *alg) ...@@ -105,8 +105,6 @@ virtio_crypto_alg_validate_key(int key_len, uint32_t *alg)
*alg = VIRTIO_CRYPTO_CIPHER_AES_CBC; *alg = VIRTIO_CRYPTO_CIPHER_AES_CBC;
break; break;
default: default:
pr_err("virtio_crypto: Unsupported key length: %d\n",
key_len);
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
...@@ -489,6 +487,11 @@ static int virtio_crypto_ablkcipher_encrypt(struct ablkcipher_request *req) ...@@ -489,6 +487,11 @@ static int virtio_crypto_ablkcipher_encrypt(struct ablkcipher_request *req)
/* Use the first data virtqueue as default */ /* Use the first data virtqueue as default */
struct data_queue *data_vq = &vcrypto->data_vq[0]; 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->dataq = data_vq;
vc_req->alg_cb = virtio_crypto_dataq_sym_callback; vc_req->alg_cb = virtio_crypto_dataq_sym_callback;
vc_sym_req->ablkcipher_ctx = ctx; vc_sym_req->ablkcipher_ctx = ctx;
...@@ -509,6 +512,11 @@ static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req) ...@@ -509,6 +512,11 @@ static int virtio_crypto_ablkcipher_decrypt(struct ablkcipher_request *req)
/* Use the first data virtqueue as default */ /* Use the first data virtqueue as default */
struct data_queue *data_vq = &vcrypto->data_vq[0]; 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->dataq = data_vq;
vc_req->alg_cb = virtio_crypto_dataq_sym_callback; vc_req->alg_cb = virtio_crypto_dataq_sym_callback;
vc_sym_req->ablkcipher_ctx = ctx; vc_sym_req->ablkcipher_ctx = ctx;
......
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