# GHSA-3qx8-rv27-j6gp: Undefined behaviour in `kvm_ioctls::ioctls::vm::VmFd::create_device`

> Undefined behavior in KVM device creation causes incorrect file descriptor handling, potentially leading to logic errors or crashes in virtualization applications.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 5 Dec 2024
- **Also known as:** RUSTSEC-2024-0428

## What is GHSA-3qx8-rv27-j6gp?

GHSA-3qx8-rv27-j6gp is a vulnerability in kvm-ioctls, published on 5 Dec 2024. 

### Official description

An issue was identified in the `VmFd::create_device function`, leading to undefined behavior and miscompilations on rustc 1.82.0 and newer due to the function's violation of Rust's pointer safety rules.

The function downcasted a mutable reference to its `struct kvm_create_device` argument to an immutable pointer, and then proceeded to pass this pointer to a mutating system call. Rustc 1.82.0 and newer elides subsequent reads of this structure's fields, meaning code will not see the value written by the kernel into the `fd` member. Instead, the code will observe the value that this field was initialized to prior to calling `VmFd::create_device` (usually, 0).

The issue started in kvm-ioctls 0.1.0 and was fixed in 0.19.1 by correctly using
a mutable pointer.

## Which versions are affected by GHSA-3qx8-rv27-j6gp?

3 open source packages ship an affected version, including kvm-ioctls.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `kvm-ioctls` | crates.io | All versions | 0.19.1 |
| `kvm-ioctls` | crates.io | All versions | 0.19.1 |
| `kvm-ioctls` | crates.io | From 0.0.0-0 | 0.19.1 |

## How do I fix GHSA-3qx8-rv27-j6gp?

Upgrade kvm-ioctls to 0.19.1 or later.

## Is GHSA-3qx8-rv27-j6gp being exploited?

There is no known exploitation of GHSA-3qx8-rv27-j6gp in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-3qx8-rv27-j6gp and fix it if it is affected.

What it is: GHSA-3qx8-rv27-j6gp is a vulnerability in kvm-ioctls, published on 5 Dec 2024. 
Exploitation: There is no known exploitation of GHSA-3qx8-rv27-j6gp in the wild and no public exploit code.

Affected packages and fixed versions:
- kvm-ioctls (crates.io): affected all versions; fixed in 0.19.1
- kvm-ioctls (crates.io): affected all versions; fixed in 0.19.1
- kvm-ioctls (crates.io): affected from 0.0.0-0; fixed in 0.19.1

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/GHSA-3qx8-rv27-j6gp/ (Markdown: https://insights.sbomify.com/GHSA-3qx8-rv27-j6gp/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-3qx8-rv27-j6gp

---
From sbomify Insights: https://insights.sbomify.com/GHSA-3qx8-rv27-j6gp/
Summaries are generated and may contain mistakes; the official description above is the record.
