Skip to contentSkip to conversation

CEV fixes for virtio-crypto

PATCH New zhenwei pi 1 participant 3 messages Aug 3, 2023

lore
Share & tools
lore

zhenwei pi

author
#0 lore raw

cover CEV fixes for virtio-crypto

Hi Michael, Lei,

Yiming Tao, Yongkang Jia, Xiao Lei(from Zhejiang University) reported issuses and CVEs in the past days.

This series fixes a CVE and a BUG for virtio-crypto/cryptodev.

Zhenwei Pi (2):
virtio-crypto: verify src&dst buffer length for sym request
cryptodev: Handle unexpected request to avoid crash

 backends/cryptodev.c      | 10 ++++++++++
 hw/virtio/virtio-crypto.c |  5 +++++
 2 files changed, 15 insertions(+)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/2 virtio-crypto: verify src&dst buffer length for sym request

For symmetric algorithms, the length of ciphertext must be as same as the plaintext.
The missing verification of the src_len and the dst_len in virtio_crypto_sym_op_helper() may lead buffer overflow/divulged.

This patch is originally written by Yiming Tao for QEMU-SECURITY, resend it(a few changes of error message) in qemu-devel.

Fixes CVE-2023-3180
Fixes 04b9b37edda("virtio-crypto: add data queue processing handler")
Cc Gonglei <[email protected]>
Cc Mauro Matteo Cascella <[email protected]>
Cc Yiming Tao <[email protected]>
---
 hw/virtio/virtio-crypto.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/virtio/virtio-crypto.c +5 -0
index 44faf5a522..13aec771e1 100644
@@ -634,6 +634,11 @@ virtio_crypto_sym_op_helper(VirtIODevice *vdev,
         return NULL;
     }
 
+    if (unlikely(src_len != dst_len)) {
+        virtio_error(vdev, "sym request src len is different from dst len");
+        return NULL;
+    }
+
     max_len = (uint64_t)iv_len + aad_len + src_len + dst_len + hash_result_len;
     if (unlikely(max_len > vcrypto->conf.max_size)) {
         virtio_error(vdev, "virtio-crypto too big length");
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/2 cryptodev: Handle unexpected request to avoid crash

In reply to zhenwei pi

Generally guest side should discover which services the device is able to offer, then do requests on device.

However it's also possible to break this rule in a guest. Handle unexpected request here to avoid NULL pointer dereference.

Fixes e7a775fd ('cryptodev: Account statistics')
Cc Gonglei <[email protected]>
Cc Mauro Matteo Cascella <[email protected]>
Cc Xiao Lei <[email protected]>
Cc Yongkang Jia <[email protected]>
---
 backends/cryptodev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
backends/cryptodev.c +10 -0
index 7d29517843..4d183f7237 100644
@@ -191,6 +191,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend,
     if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) {
         CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info;
         len = asym_op_info->src_len;
+
+        if (unlikely(!backend->asym_stat)) {
+            error_report("cryptodev: Unexpected asym operation");
+            return -VIRTIO_CRYPTO_NOTSUPP;
+        }
         switch (op_info->op_code) {
         case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT:
             CryptodevAsymStatIncEncrypt(backend, len);
@@ -210,6 +215,11 @@ static int cryptodev_backend_account(CryptoDevBackend *backend,
     } else if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) {
         CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info;
         len = sym_op_info->src_len;
+
+        if (unlikely(!backend->sym_stat)) {
+            error_report("cryptodev: Unexpected sym operation");
+            return -VIRTIO_CRYPTO_NOTSUPP;
+        }
         switch (op_info->op_code) {
         case VIRTIO_CRYPTO_CIPHER_ENCRYPT:
             CryptodevSymStatIncEncrypt(backend, len);
Signature · 1 line
2.34.1