# CVE-2021-3975: Use after free in libvirt

> An unprivileged client can crash the libvirt daemon via a use-after-free flaw in monitor handling during guest shutdown.

- **Severity:** Medium 6.5 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 23 Aug 2022
- **Updated:** 3 Aug 2024
- **Also known as:** CLSA-2022-1654537477, CLSA-2022-1654537694, DEBIAN-CVE-2021-3975, GHSA-pg89-46xq-98vv, OESA-2022-1891, RHBA-2021:4684, UBUNTU-CVE-2021-3975

## What is CVE-2021-3975?

CVE-2021-3975 is a medium-severity use after free vulnerability in Canonical Ubuntu Linux, published on 23 Aug 2022. Any signed-in user can exploit it over the network, with no action from the victim.

### Official description

A use-after-free flaw was found in libvirt. The qemuMonitorUnregister() function in qemuProcessHandleMonitorEOF is called using multiple threads without being adequately protected by a monitor lock. This flaw could be triggered by the virConnectGetAllDomainStats API when the guest is shutting down. An unprivileged client with a read-only connection could use this flaw to perform a denial of service attack by causing the libvirt daemon to crash.

Weakness: CWE-416 (Use After Free)

## Which versions are affected by CVE-2021-3975?

It affects 14 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `SLOF` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:20210217-1.module+el8.5.0+10946+35bb3930 |
| `hivex` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.3.18-22.module+el8.5.0+12087+2208d04c |
| `hivex-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.3.18-22.module+el8.5.0+12087+2208d04c |
| `hivex-debugsource` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.3.18-22.module+el8.5.0+12087+2208d04c |
| `hivex-devel` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.3.18-22.module+el8.5.0+12087+2208d04c |
| `libguestfs` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-bash-completion` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-debugsource` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-devel` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-gfs2` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-gobject` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-gobject-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-gobject-devel` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-inspect-icons` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-java` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-java-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-java-devel` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-javadoc` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-man-pages-ja` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-man-pages-uk` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-rescue` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-rsync` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-tools` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-tools-c` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-tools-c-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libguestfs-winsupport` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:8.2-2.module+el8.5.0+12739+164806c8 |
| `libguestfs-xfs` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 1:1.44.0-3.module+el8.5.0+10681+17a9b157 |
| `libiscsi` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.18.0-8.module+el8.4.0+8855+a9e237a9 |
| `libiscsi-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.18.0-8.module+el8.4.0+8855+a9e237a9 |
| `libiscsi-debugsource` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.18.0-8.module+el8.4.0+8855+a9e237a9 |
| `libiscsi-devel` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.18.0-8.module+el8.4.0+8855+a9e237a9 |
| `libiscsi-utils` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.18.0-8.module+el8.4.0+8855+a9e237a9 |
| `libiscsi-utils-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.18.0-8.module+el8.4.0+8855+a9e237a9 |
| `libnbd` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.6.0-4.module+el8.5.0+11638+3d8f9850 |
| `libnbd-bash-completion` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.6.0-4.module+el8.5.0+11638+3d8f9850 |
| `libnbd-debuginfo` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.6.0-4.module+el8.5.0+11638+3d8f9850 |
| `libnbd-debugsource` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.6.0-4.module+el8.5.0+11638+3d8f9850 |
| `libnbd-devel` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:1.6.0-4.module+el8.5.0+11638+3d8f9850 |
| `libtpms` | Red Hat:advanced_virtualization:8.5::el8 | All versions | 0:0.7.4-6.20201106git2452a24dab.module+el8.5.0+12487+f2fa92b4 |

Products: Canonical Ubuntu Linux, Debian Debian Linux, Fedoraproject Fedora, Netapp Ontap Select Deploy Administration Utility, Redhat Codeready Linux Builder, Redhat Enterprise Linux, Redhat Enterprise Linux Eus, Redhat Enterprise Linux for Ibm Z Systems, Redhat Enterprise Linux for Ibm Z Systems Eus, Redhat Enterprise Linux for Power Little Endian, Redhat Enterprise Linux for Power Little Endian Eus, Redhat Enterprise Linux Server for Power Little Endian Update Services for Sap Solutions, Redhat Enterprise Linux Server Tus, Redhat Libvirt.

## How do I fix CVE-2021-3975?

Apply the vendor's patch.

## Is CVE-2021-3975 being exploited?

There is no known exploitation of CVE-2021-3975 in the wild and no public exploit code.

Public exploit code:

- Aritifacts of docker env of CVE-2021-3975 (github_poc): https://github.com/yan5ui/ENV-CVE-2021-3975

## Other vulnerabilities in Canonical Ubuntu Linux

- [CVE-2020-11651](https://insights.sbomify.com/CVE-2020-11651/): SaltStack Salt Authentication Bypass (critical 9.8, exploited in the wild)
- [CVE-2020-7247](https://insights.sbomify.com/CVE-2020-7247/): OpenSMTPD Remote Code Execution (critical 9.8, exploited in the wild)
- [CVE-2019-16928](https://insights.sbomify.com/CVE-2019-16928/): Exim Out-of-bounds Write (critical 9.8, exploited in the wild)
- [CVE-2018-6789](https://insights.sbomify.com/CVE-2018-6789/): Exim Buffer Overflow (critical 9.8, exploited in the wild)
- [CVE-2015-2590](https://insights.sbomify.com/CVE-2015-2590/): Oracle Java SE and Java SE Embedded Remote Code Execution (critical 9.8, exploited in the wild)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-3975 and fix it if it is affected.

What it is: CVE-2021-3975 is a medium-severity use after free vulnerability in Canonical Ubuntu Linux, published on 23 Aug 2022. Any signed-in user can exploit it over the network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-3975 in the wild and no public exploit code.

Affected product: Canonical Ubuntu Linux. No package-level version data is available, so check the vendor advisory linked from the reference page.

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2021-3975/ (Markdown: https://insights.sbomify.com/CVE-2021-3975/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-3975
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-3975
- OSV: https://osv.dev/vulnerability/CVE-2021-3975

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-3975/
Summaries are generated and may contain mistakes; the official description above is the record.
