qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] CEV fixes for virtio-crypto
@ 2023-08-03  2:43 zhenwei pi
  2023-08-03  2:43 ` [PATCH 1/2] virtio-crypto: verify src&dst buffer length for sym request zhenwei pi
  2023-08-03  2:43 ` [PATCH 2/2] cryptodev: Handle unexpected request to avoid crash zhenwei pi
  0 siblings, 2 replies; 3+ messages in thread
From: zhenwei pi @ 2023-08-03  2:43 UTC (permalink / raw)
  To: mst, arei.gonglei
  Cc: qemu-devel, taoym, kangel, nop.leixiao, mcascell, zhenwei pi

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(+)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] virtio-crypto: verify src&dst buffer length for sym request
  2023-08-03  2:43 [PATCH 0/2] CEV fixes for virtio-crypto zhenwei pi
@ 2023-08-03  2:43 ` zhenwei pi
  2023-08-03  2:43 ` [PATCH 2/2] cryptodev: Handle unexpected request to avoid crash zhenwei pi
  1 sibling, 0 replies; 3+ messages in thread
From: zhenwei pi @ 2023-08-03  2:43 UTC (permalink / raw)
  To: mst, arei.gonglei
  Cc: qemu-devel, taoym, kangel, nop.leixiao, mcascell, zhenwei pi

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 <arei.gonglei@huawei.com>
Cc: Mauro Matteo Cascella <mcascell@redhat.com>
Cc: Yiming Tao <taoym@zju.edu.cn>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 hw/virtio/virtio-crypto.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 44faf5a522..13aec771e1 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -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");
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] cryptodev: Handle unexpected request to avoid crash
  2023-08-03  2:43 [PATCH 0/2] CEV fixes for virtio-crypto zhenwei pi
  2023-08-03  2:43 ` [PATCH 1/2] virtio-crypto: verify src&dst buffer length for sym request zhenwei pi
@ 2023-08-03  2:43 ` zhenwei pi
  1 sibling, 0 replies; 3+ messages in thread
From: zhenwei pi @ 2023-08-03  2:43 UTC (permalink / raw)
  To: mst, arei.gonglei
  Cc: qemu-devel, taoym, kangel, nop.leixiao, mcascell, 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 <arei.gonglei@huawei.com>
Cc: Mauro Matteo Cascella <mcascell@redhat.com>
Cc: Xiao Lei <nop.leixiao@gmail.com>
Cc: Yongkang Jia <kangel@zju.edu.cn>
Reported-by: Yiming Tao <taoym@zju.edu.cn>
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 backends/cryptodev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/backends/cryptodev.c b/backends/cryptodev.c
index 7d29517843..4d183f7237 100644
--- a/backends/cryptodev.c
+++ b/backends/cryptodev.c
@@ -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);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-03  2:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-03  2:43 [PATCH 0/2] CEV fixes for virtio-crypto zhenwei pi
2023-08-03  2:43 ` [PATCH 1/2] virtio-crypto: verify src&dst buffer length for sym request zhenwei pi
2023-08-03  2:43 ` [PATCH 2/2] cryptodev: Handle unexpected request to avoid crash zhenwei pi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).