Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: dbaf0624ffa5 ("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>

authored by

Ard Biesheuvel and committed by
Herbert Xu
19c5da7d 500e6807

+10 -2
+10 -2
drivers/crypto/virtio/virtio_crypto_algs.c
··· 105 105 *alg = VIRTIO_CRYPTO_CIPHER_AES_CBC; 106 106 break; 107 107 default: 108 - pr_err("virtio_crypto: Unsupported key length: %d\n", 109 - key_len); 110 108 return -EINVAL; 111 109 } 112 110 return 0; ··· 487 489 /* Use the first data virtqueue as default */ 488 490 struct data_queue *data_vq = &vcrypto->data_vq[0]; 489 491 492 + if (!req->nbytes) 493 + return 0; 494 + if (req->nbytes % AES_BLOCK_SIZE) 495 + return -EINVAL; 496 + 490 497 vc_req->dataq = data_vq; 491 498 vc_req->alg_cb = virtio_crypto_dataq_sym_callback; 492 499 vc_sym_req->ablkcipher_ctx = ctx; ··· 511 508 struct virtio_crypto *vcrypto = ctx->vcrypto; 512 509 /* Use the first data virtqueue as default */ 513 510 struct data_queue *data_vq = &vcrypto->data_vq[0]; 511 + 512 + if (!req->nbytes) 513 + return 0; 514 + if (req->nbytes % AES_BLOCK_SIZE) 515 + return -EINVAL; 514 516 515 517 vc_req->dataq = data_vq; 516 518 vc_req->alg_cb = virtio_crypto_dataq_sym_callback;