# CVE-2025-22115: btrfs: fix block group refcount race in btrfs\_create\_pending\_block\_groups()

> 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.22% (percentile 7, 2026-11-26)
- **CWE:** CWE-362
- **Published:** 2025-04-16T14:13:01.293Z
- **Modified:** 2026-10-30T13:17:57.040Z

## Who should check

- Anyone running Linux \>= 6297644db23f77c02ae7961cc542d162629ae2c4, \< 3232bdf8a135877345c25bf4c0d892334a4c03f7; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< ee56da95f8962b86fec4ef93f866e64c8d025a58; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 9d383a6fc59271aaaf07a33b23b2eac5b9268b7a; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 2d8e5168d48a91e7a802d3003e72afb4304bebfa; 7569c4294ba6ff9f194635b14876198f8a687c4a; \>= 6.1.47, \< 6.1.191; \>= 6.4.12, \< 6.5
- Anyone running Linux 6.5

## Description

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

btrfs: fix block group refcount race in btrfs\_create\_pending\_block\_groups()

Block group creation is done in two phases, which results in a slightly
unintuitive property: a block group can be allocated/deallocated from
after btrfs\_make\_block\_group() adds it to the space\_info with
btrfs\_add\_bg\_to\_space\_info(), but before creation is completely completed
in btrfs\_create\_pending\_block\_groups(). As a result, it is possible for a
block group to go unused and have 'btrfs\_mark\_bg\_unused' called on it
concurrently with 'btrfs\_create\_pending\_block\_groups'. This causes a
number of issues, which were fixed with the block group flag
'BLOCK\_GROUP\_FLAG\_NEW'.

However, this fix is not quite complete. Since it does not use the
unused\_bg\_lock, it is possible for the following race to occur:

btrfs\_create\_pending\_block\_groups            btrfs\_mark\_bg\_unused
                                           if list\_empty // false
        list\_del\_init
        clear\_bit
                                           else if (test\_bit) // true
                                                list\_move\_tail

And we get into the exact same broken ref count and invalid new\_bgs
state for transaction cleanup that BLOCK\_GROUP\_FLAG\_NEW was designed to
prevent.

The broken refcount aspect will result in a warning like:

  \[1272.943527\] refcount\_t: underflow; use-after-free.
  \[1272.943967\] WARNING: CPU: 1 PID: 61 at lib/refcount.c:28 refcount\_warn\_saturate+0xba/0x110
  \[1272.944731\] Modules linked in: btrfs virtio\_net xor zstd\_compress raid6\_pq null\_blk \[last unloaded: btrfs\]
  \[1272.945550\] CPU: 1 UID: 0 PID: 61 Comm: kworker/u32:1 Kdump: loaded Tainted: G        W          6.14.0-rc5+ \#108
  \[1272.946368\] Tainted: \[W\]=WARN
  \[1272.946585\] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.16.3-1-1 04/01/2014
  \[1272.947273\] Workqueue: btrfs\_discard btrfs\_discard\_workfn \[btrfs\]
  \[1272.947788\] RIP: 0010:refcount\_warn\_saturate+0xba/0x110
  \[1272.949532\] RSP: 0018:ffffbf1200247df0 EFLAGS: 00010282
  \[1272.949901\] RAX: 0000000000000000 RBX: ffffa14b00e3f800 RCX: 0000000000000000
  \[1272.950437\] RDX: 0000000000000000 RSI: ffffbf1200247c78 RDI: 00000000ffffdfff
  \[1272.950986\] RBP: ffffa14b00dc2860 R08: 00000000ffffdfff R09: ffffffff90526268
  \[1272.951512\] R10: ffffffff904762c0 R11: 0000000063666572 R12: ffffa14b00dc28c0
  \[1272.952024\] R13: 0000000000000000 R14: ffffa14b00dc2868 R15: 000001285dcd12c0
  \[1272.952850\] FS:  0000000000000000(0000) GS:ffffa14d33c40000(0000) knlGS:0000000000000000
  \[1272.953458\] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  \[1272.953931\] CR2: 00007f838cbda000 CR3: 000000010104e000 CR4: 00000000000006f0
  \[1272.954474\] Call Trace:
  \[1272.954655\]  \<TASK\>
  \[1272.954812\]  ? refcount\_warn\_saturate+0xba/0x110
  \[1272.955173\]  ? \_\_warn.cold+0x93/0xd7
  \[1272.955487\]  ? refcount\_warn\_saturate+0xba/0x110
  \[1272.955816\]  ? report\_bug+0xe7/0x120
  \[1272.956103\]  ? handle\_bug+0x53/0x90
  \[1272.956424\]  ? exc\_invalid\_op+0x13/0x60
  \[1272.956700\]  ? asm\_exc\_invalid\_op+0x16/0x20
  \[1272.957011\]  ? refcount\_warn\_saturate+0xba/0x110
  \[1272.957399\]  btrfs\_discard\_cancel\_work.cold+0x26/0x2b \[btrfs\]
  \[1272.957853\]  btrfs\_put\_block\_group.cold+0x5d/0x8e \[btrfs\]
  \[1272.958289\]  btrfs\_discard\_workfn+0x194/0x380 \[btrfs\]
  \[1272.958729\]  process\_one\_work+0x130/0x290
  \[1272.959026\]  worker\_thread+0x2ea/0x420
  \[1272.959335\]  ? \_\_pfx\_worker\_thread+0x10/0x10
  \[1272.959644\]  kthread+0xd7/0x1c0
  \[1272.959872\]  ? \_\_pfx\_kthread+0x10/0x10
  \[1272.960172\]  ret\_from\_fork+0x30/0x50
  \[1272.960474\]  ? \_\_pfx\_kthread+0x10/0x10
  \[1272.960745\]  ret\_from\_fork\_asm+0x1a/0x30
  \[1272.961035\]  \</TASK\>
  \[1272.961238\] ---\[ end trace 0000000000000000 \]---

Though we have seen them in the async discard workfn as well. It is
most likely to happen after a relocation finishes which cancels discard,
tears down the block group, etc.

Fix this fully by taking the lock arou
---truncated---

## Affected and fixed versions

- Linux: \>= 6297644db23f77c02ae7961cc542d162629ae2c4, \< 3232bdf8a135877345c25bf4c0d892334a4c03f7; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< ee56da95f8962b86fec4ef93f866e64c8d025a58; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 9d383a6fc59271aaaf07a33b23b2eac5b9268b7a; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 2d8e5168d48a91e7a802d3003e72afb4304bebfa; 7569c4294ba6ff9f194635b14876198f8a687c4a; \>= 6.1.47, \< 6.1.191; \>= 6.4.12, \< 6.5 (cvelist)
- Linux: 6.5 (cvelist)

## Mitigation

- Upgrade Linux to 6.5 or later.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2025-22115.md
Affected: Linux >= 6297644db23f77c02ae7961cc542d162629ae2c4, < 3232bdf8a135877345c25bf4c0d892334a4c03f7; >= 0657b20c5a76c938612f8409735a8830d257866e, < 77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96; >= 0657b20c5a76c938612f8409735a8830d257866e, < ee56da95f8962b86fec4ef93f866e64c8d025a58; >= 0657b20c5a76c938612f840…
Fixed in: Linux 3232bdf8a135877345c25bf4c0d892334a4c03f7, Linux 77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96, Linux 9d383a6fc59271aaaf07a33b23b2eac5b9268b7a, Linux 2d8e5168d48a91e7a802d3003e72afb4304bebfa, Linux 6.1.191, Linux 6.5

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-2025-22115 being exploited?

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

### How serious is CVE-2025-22115?

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

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

Linux \>= 6297644db23f77c02ae7961cc542d162629ae2c4, \< 3232bdf8a135877345c25bf4c0d892334a4c03f7; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< ee56da95f8962b86fec4ef93f866e64c8d025a58; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 9d383a6fc59271aaaf07a33b23b2eac5b9268b7a; \>= 0657b20c5a76c938612f8409735a8830d257866e, \< 2d8e5168d48a91e7a802d3003e72afb4304bebfa; 7569c4294ba6ff9f194635b14876198f8a687c4a; \>= 6.1.47, \< 6.1.191; \>= 6.4.12, \< 6.5; Linux 6.5.

### Is there a fix for CVE-2025-22115?

Yes. Fixed in Linux 3232bdf8a135877345c25bf4c0d892334a4c03f7, Linux 77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96, Linux 9d383a6fc59271aaaf07a33b23b2eac5b9268b7a, Linux 2d8e5168d48a91e7a802d3003e72afb4304bebfa, Linux 6.1.191, Linux 6.5. Upgrade Linux to 6.5 or later.

### How do I check if I'm affected by CVE-2025-22115?

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/ee56da95f8962b86fec4ef93f866e64c8d025a58>
- patch: <https://git.kernel.org/stable/c/9d383a6fc59271aaaf07a33b23b2eac5b9268b7a>
- patch: <https://git.kernel.org/stable/c/2d8e5168d48a91e7a802d3003e72afb4304bebfa>
- other: <https://git.kernel.org/stable/c/3232bdf8a135877345c25bf4c0d892334a4c03f7>
- other: <https://git.kernel.org/stable/c/77fd40b7ed0c3acf989a0f2a07b15a0a59ea8f96>

## 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-2025-22115>

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