# CVE-2025-68359: btrfs: fix double free of qgroup record after failure to add delayed ref head

> A double free vulnerability in the Linux kernel's btrfs filesystem allows attackers to potentially execute arbitrary code or escalate privileges.

- **Severity:** Critical 9.8 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 24 Dec 2025
- **Updated:** 21 Oct 2026
- **Also known as:** BELL-CVE-2025-68359, DEBIAN-CVE-2025-68359, GHSA-wmvq-g95c-rpvj, ROOT-OS-DEBIAN-13-CVE-2025-68359, UBUNTU-CVE-2025-68359

## What is CVE-2025-68359?

CVE-2025-68359 is a critical use after free vulnerability in Linux, published on 24 Dec 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

In the Linux kernel, the following vulnerability has been resolved:

btrfs: fix double free of qgroup record after failure to add delayed ref head

In the previous code it was possible to incur into a double kfree()
scenario when calling add_delayed_ref_head(). This could happen if the
record was reported to already exist in the
btrfs_qgroup_trace_extent_nolock() call, but then there was an error
later on add_delayed_ref_head(). In this case, since
add_delayed_ref_head() returned an error, the caller went to free the
record. Since add_delayed_ref_head() couldn't set this kfree'd pointer
to NULL, then kfree() would have acted on a non-NULL 'record' object
which was pointing to memory already freed by the callee.

The problem comes from the fact that the responsibility to kfree the
object is on both the caller and the callee at the same time. Hence, the
fix for this is to shift the ownership of the 'qrecord' object out of
the add_delayed_ref_head(). That is, we will never attempt to kfree()
the given object inside of this function, and will expect the caller to
act on the 'qrecord' object on its own. The only exception where the
'qrecord' object cannot be kfree'd is if it was inserted into the
tracing logic, for which we already have the 'qrecord_inserted_ret'
boolean to account for this. Hence, the caller has to kfree the object
only if add_delayed_ref_head() reports not to have inserted it on the
tracing logic.

As a side-effect of the above, we must guarantee that
'qrecord_inserted_ret' is properly initialized at the start of the
function, not at the end, and then set when an actual insert
happens. This way we avoid 'qrecord_inserted_ret' having an invalid
value on an early exit.

The documentation from the add_delayed_ref_head() has also been updated
to reflect on the exact ownership of the 'qrecord' object.

## Which versions are affected by CVE-2025-68359?


## How do I fix CVE-2025-68359?

Apply the vendor's patch.

## Is CVE-2025-68359 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2025-68359 and fix it if it is affected.

What it is: CVE-2025-68359 is a critical use after free vulnerability in Linux, published on 24 Dec 2025. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2025-68359 in the wild and no public exploit code.

Affected product: 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-2025-68359/ (Markdown: https://insights.sbomify.com/CVE-2025-68359/index.md)
```

## Sources

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

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