From: zhenwei pi Date: Thu, 3 Aug 2023 02:43:13 +0000 (+0800) Subject: virtio-crypto: verify src&dst buffer length for sym request X-Git-Tag: qemu-xen-4.18.0-rc5~19 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=49f1e02bac166821c712534aaa775f50e1afe17f;p=qemu-xen.git 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 Cc: Mauro Matteo Cascella Cc: Yiming Tao Signed-off-by: zhenwei pi Message-Id: <20230803024314.29962-2-pizhenwei@bytedance.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin (cherry picked from commit 9d38a8434721a6479fe03fb5afb150ca793d3980) Signed-off-by: Michael Tokarev --- diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c index a1d122b9aa..ccaa704530 100644 --- a/hw/virtio/virtio-crypto.c +++ b/hw/virtio/virtio-crypto.c @@ -635,6 +635,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");