]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
crypto: virtio - deal with unsupported input sizes
authorArd Biesheuvel <ardb@kernel.org>
Sat, 9 Nov 2019 17:09:27 +0000 (18:09 +0100)
committerSeth Forshee <seth.forshee@canonical.com>
Mon, 6 Jan 2020 14:16:45 +0000 (08:16 -0600)
BugLink: https://bugs.launchpad.net/bugs/1858428
[ 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@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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
drivers/crypto/virtio/virtio_crypto_algs.c

index 42d19205166b085e25bee8fd7a1cde5f0a52d941..673fb29fda53cf9dcc6fddf3b5bd2b66b478af18 100644 (file)
@@ -105,8 +105,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;
@@ -484,6 +482,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;
@@ -504,6 +507,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;