A recently discovered vulnerability, identified as CVE-2022-26354, impacts the vhost-vsock device in QEMU (Quick Emulator). The flaw arises due to improper detachment of an invalid element from the virtqueue before its memory is freed. This oversight can result in memory leakage and other unintended consequences. QEMU versions 6.2. and earlier are affected by this vulnerability.

Background on QEMU and vhost-vsock

QEMU is an open-source machine emulator and virtualization platform commonly used for running virtual machines. The vhost-vsock device is a key component for efficient communications between the guest and the host. It enables virtualization platforms, including QEMU, to run multiple, isolated instances of guest operating systems on a single host machine.

Code Snippet Highlighting the Vulnerability

The vulnerability is found in the 'hw/virtio/vhost-vsock.c' source file of QEMU. In the following code snippet, the issue stems from the improper handling of errors in the handle_vq function:

static void handle_vq(Vsock *s, VhostUserVsock *vsock, VSockVirtqueue *q)
    // ...
    bool error_occurred = false;
    // ...

    if (error_occurred) {
        if (!detached_from_virtqueue) {
            virtqueue_detach_element(q->vq, &buf, );
            // Invalid element is not actually detached
            detached_from_virtqueue = true;

        // Memory is freed before detaching,
        // leading to memory leakage and other issues

The error occurs due to the virtqueue_detach_element function being called only when detached_from_virtqueue is false. In cases where an error occurs, the invalid element is not detached, and thus, the memory of the element is freed without being properly detached from the virtqueue.

Original References

The details of this vulnerability can be found in the official QEMU and National Vulnerability Database references:

1. QEMU Patch fixing the issue: [PATCH v4 01/11] vhost-vsock: move virtqueue detachment before out_free](https://lists.gnu.org/archive/html/qemu-devel/2022-01/msg03542.html)
2. National Vulnerability Database - CVE-2022-26354: https://nvd.nist.gov/vuln/detail/CVE-2022-26354

Exploit Details

As of now, there are no publicly known exploits taking advantage of this vulnerability. However, an attacker who successfully exploits this flaw could cause memory leakage, leading to degraded performance or a crash of the affected QEMU instance. In some cases, this could also lead to the potential exposure of sensitive information stored in memory.


To patch this vulnerability, users are advised to update QEMU to version 6.2.1 or later, which includes the fix for this issue. Alternatively, users can apply the patch mentioned in the original reference, which ensures proper detachment of elements from the virtqueue before freeing their memory.


CVE-2022-26354 is a critical vulnerability affecting QEMU's vhost-vsock device, which could lead to memory leakage and unintended results, potentially compromising the security and stability of affected virtualization environments. Updating to the latest version of QEMU or applying the appropriate patch can help mitigate this issue and ensure the continued safe operation of virtual machines.


Published on: 03/16/2022 15:15:00 UTC
Last modified on: 08/15/2022 11:19:00 UTC