# CVE-2022-49999: btrfs: fix space cache corruption and potential double allocations

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 7.8
- **CVSS:** 7.8 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.30% (percentile 15, 2026-11-26)
- **CWE:** CWE-787
- **Published:** 2025-06-18T11:00:58.916Z
- **Modified:** 2026-08-05T08:57:07.652Z

## Who should check

- Anyone running Linux \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< 92dc4c1a8e58bcc7a183a4c86b055c24cc88d967; \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< a2e54eb64229f07f917b05d0c323604fda9b89f7; \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< ced8ecf026fd8084cf175530ff85c76d6085d715
- Anyone running Linux 5.12

## Description

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

btrfs: fix space cache corruption and potential double allocations

When testing space\_cache v2 on a large set of machines, we encountered a
few symptoms:

1. "unable to add free space :-17" (EEXIST) errors.
2. Missing free space info items, sometimes caught with a "missing free
   space info for X" error.
3. Double-accounted space: ranges that were allocated in the extent tree
   and also marked as free in the free space tree, ranges that were
   marked as allocated twice in the extent tree, or ranges that were
   marked as free twice in the free space tree. If the latter made it
   onto disk, the next reboot would hit the BUG\_ON() in
   add\_new\_free\_space().
4. On some hosts with no on-disk corruption or error messages, the
   in-memory space cache (dumped with drgn) disagreed with the free
   space tree.

All of these symptoms have the same underlying cause: a race between
caching the free space for a block group and returning free space to the
in-memory space cache for pinned extents causes us to double-add a free
range to the space cache. This race exists when free space is cached
from the free space tree (space\_cache=v2) or the extent tree
(nospace\_cache, or space\_cache=v1 if the cache needs to be regenerated).
struct btrfs\_block\_group::last\_byte\_to\_unpin and struct
btrfs\_block\_group::progress are supposed to protect against this race,
but commit d0c2f4fa555e ("btrfs: make concurrent fsyncs wait less when
waiting for a transaction commit") subtly broke this by allowing
multiple transactions to be unpinning extents at the same time.

Specifically, the race is as follows:

1. An extent is deleted from an uncached block group in transaction A.
2. btrfs\_commit\_transaction() is called for transaction A.
3. btrfs\_run\_delayed\_refs() -\> \_\_btrfs\_free\_extent() runs the delayed
   ref for the deleted extent.
4. \_\_btrfs\_free\_extent() -\> do\_free\_extent\_accounting() -\>
   add\_to\_free\_space\_tree() adds the deleted extent back to the free
   space tree.
5. do\_free\_extent\_accounting() -\> btrfs\_update\_block\_group() -\>
   btrfs\_cache\_block\_group() queues up the block group to get cached.
   block\_group-\>progress is set to block\_group-\>start.
6. btrfs\_commit\_transaction() for transaction A calls
   switch\_commit\_roots(). It sets block\_group-\>last\_byte\_to\_unpin to
   block\_group-\>progress, which is block\_group-\>start because the block
   group hasn't been cached yet.
7. The caching thread gets to our block group. Since the commit roots
   were already switched, load\_free\_space\_tree() sees the deleted extent
   as free and adds it to the space cache. It finishes caching and sets
   block\_group-\>progress to U64\_MAX.
8. btrfs\_commit\_transaction() advances transaction A to
   TRANS\_STATE\_SUPER\_COMMITTED.
9. fsync calls btrfs\_commit\_transaction() for transaction B. Since
   transaction A is already in TRANS\_STATE\_SUPER\_COMMITTED and the
   commit is for fsync, it advances.
10. btrfs\_commit\_transaction() for transaction B calls
    switch\_commit\_roots(). This time, the block group has already been
    cached, so it sets block\_group-\>last\_byte\_to\_unpin to U64\_MAX.
11. btrfs\_commit\_transaction() for transaction A calls
    btrfs\_finish\_extent\_commit(), which calls unpin\_extent\_range() for
    the deleted extent. It sees last\_byte\_to\_unpin set to U64\_MAX (by
    transaction B!), so it adds the deleted extent to the space cache
    again!

This explains all of our symptoms above:

\* If the sequence of events is exactly as described above, when the free
  space is re-added in step 11, it will fail with EEXIST.
\* If another thread reallocates the deleted extent in between steps 7
  and 11, then step 11 will silently re-add that space to the space
  cache as free even though it is actually allocated. Then, if that
  space is allocated \*again\*, the free space tree will be corrupted
  (namely, the wrong item will be deleted).
\* If we don't catch this free space tree corr
---truncated---

## Affected and fixed versions

- Linux: \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< 92dc4c1a8e58bcc7a183a4c86b055c24cc88d967; \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< a2e54eb64229f07f917b05d0c323604fda9b89f7; \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< ced8ecf026fd8084cf175530ff85c76d6085d715 (cvelist)
- Linux: 5.12 (cvelist)

## Mitigation

- No fix listed yet: follow the vendor advisory.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2022-49999. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2022-49999.md
Affected: Linux >= d0c2f4fa555e70324ec2a129b822ab58f172cc62, < 92dc4c1a8e58bcc7a183a4c86b055c24cc88d967; >= d0c2f4fa555e70324ec2a129b822ab58f172cc62, < a2e54eb64229f07f917b05d0c323604fda9b89f7; >= d0c2f4fa555e70324ec2a129b822ab58f172cc62, < ced8ecf026fd8084cf175530ff85c76d6085d715; Linux 5.12
Fixed in: Linux 92dc4c1a8e58bcc7a183a4c86b055c24cc88d967

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2022-49999 being exploited?

There is no confirmed exploitation: CVE-2022-49999 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.30% chance of exploitation in the next 30 days (as of 2026-11-26).

### How serious is CVE-2022-49999?

High: CVSS 7.8 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).

### Which versions are affected by CVE-2022-49999?

Linux \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< 92dc4c1a8e58bcc7a183a4c86b055c24cc88d967; \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< a2e54eb64229f07f917b05d0c323604fda9b89f7; \>= d0c2f4fa555e70324ec2a129b822ab58f172cc62, \< ced8ecf026fd8084cf175530ff85c76d6085d715; Linux 5.12.

### Is there a fix for CVE-2022-49999?

Yes. Fixed in Linux 92dc4c1a8e58bcc7a183a4c86b055c24cc88d967. No fix listed yet: follow the vendor advisory.

### How do I check if I'm affected by CVE-2022-49999?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/92dc4c1a8e58bcc7a183a4c86b055c24cc88d967>
- patch: <https://git.kernel.org/stable/c/a2e54eb64229f07f917b05d0c323604fda9b89f7>
- patch: <https://git.kernel.org/stable/c/ced8ecf026fd8084cf175530ff85c76d6085d715>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2022-49999>

HTML: <https://flawdb.com/CVE-2022-49999> · JSON: <https://flawdb.com/api/v1/entries/CVE-2022-49999>
