# CVE-2023-53187: btrfs: fix use-after-free of new block group that became unused

> 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.24% (percentile 9, 2026-11-26)
- **CWE:** CWE-416
- **Published:** 2025-09-15T14:04:40.019Z
- **Modified:** 2026-08-05T09:13:01.097Z

## Who should check

- Anyone running Linux \>= 01eca70ef8cf499d0cb6d1bbd691558e7792cf17, \< 6297644db23f77c02ae7961cc542d162629ae2c4; \>= 5d19abcffd8404078dfa7d7118cec357b5e7bc58, \< 7569c4294ba6ff9f194635b14876198f8a687c4a; \>= a9f189716cf15913c453299d72f69c51a9b0f86b, \< 0657b20c5a76c938612f8409735a8830d257866e; edf3b5aadb2515c808200b904baa5b70a727f0ac; \>= 5.15.128, \< 5.16
- Anyone running Linux (versions: see the vendor advisory)

## Description

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

btrfs: fix use-after-free of new block group that became unused

If a task creates a new block group and that block group becomes unused
before we finish its creation, at btrfs\_create\_pending\_block\_groups(),
then when btrfs\_mark\_bg\_unused() is called against the block group, we
assume that the block group is currently in the list of block groups to
reclaim, and we move it out of the list of new block groups and into the
list of unused block groups. This has two consequences:

1) We move it out of the list of new block groups associated to the
   current transaction. So the block group creation is not finished and
   if we attempt to delete the bg because it's unused, we will not find
   the block group item in the extent tree (or the new block group tree),
   its device extent items in the device tree etc, resulting in the
   deletion to fail due to the missing items;

2) We don't increment the reference count on the block group when we
   move it to the list of unused block groups, because we assumed the
   block group was on the list of block groups to reclaim, and in that
   case it already has the correct reference count. However the block
   group was on the list of new block groups, in which case no extra
   reference was taken because it's local to the current task. This
   later results in doing an extra reference count decrement when
   removing the block group from the unused list, eventually leading the
   reference count to 0.

This second case was caught when running generic/297 from fstests, which
produced the following assertion failure and stack trace:

  \[589.559\] assertion failed: refcount\_read(&block\_group-\>refs) == 1, in fs/btrfs/block-group.c:4299
  \[589.559\] ------------\[ cut here \]------------
  \[589.559\] kernel BUG at fs/btrfs/block-group.c:4299!
  \[589.560\] invalid opcode: 0000 \[\#1\] PREEMPT SMP PTI
  \[589.560\] CPU: 8 PID: 2819134 Comm: umount Tainted: G        W          6.4.0-rc6-btrfs-next-134+ \#1
  \[589.560\] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.2-0-gea1b7a073390-prebuilt.qemu.org 04/01/2014
  \[589.560\] RIP: 0010:btrfs\_free\_block\_groups+0x449/0x4a0 \[btrfs\]
  \[589.561\] Code: 68 62 da c0 (...)
  \[589.561\] RSP: 0018:ffffa55a8c3b3d98 EFLAGS: 00010246
  \[589.561\] RAX: 0000000000000058 RBX: ffff8f030d7f2000 RCX: 0000000000000000
  \[589.562\] RDX: 0000000000000000 RSI: ffffffff953f0878 RDI: 00000000ffffffff
  \[589.562\] RBP: ffff8f030d7f2088 R08: 0000000000000000 R09: ffffa55a8c3b3c50
  \[589.562\] R10: 0000000000000001 R11: 0000000000000001 R12: ffff8f05850b4c00
  \[589.562\] R13: ffff8f030d7f2090 R14: ffff8f05850b4cd8 R15: dead000000000100
  \[589.563\] FS:  00007f497fd2e840(0000) GS:ffff8f09dfc00000(0000) knlGS:0000000000000000
  \[589.563\] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  \[589.563\] CR2: 00007f497ff8ec10 CR3: 0000000271472006 CR4: 0000000000370ee0
  \[589.563\] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
  \[589.564\] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
  \[589.564\] Call Trace:
  \[589.564\]  \<TASK\>
  \[589.565\]  ? \_\_die\_body+0x1b/0x60
  \[589.565\]  ? die+0x39/0x60
  \[589.565\]  ? do\_trap+0xeb/0x110
  \[589.565\]  ? btrfs\_free\_block\_groups+0x449/0x4a0 \[btrfs\]
  \[589.566\]  ? do\_error\_trap+0x6a/0x90
  \[589.566\]  ? btrfs\_free\_block\_groups+0x449/0x4a0 \[btrfs\]
  \[589.566\]  ? exc\_invalid\_op+0x4e/0x70
  \[589.566\]  ? btrfs\_free\_block\_groups+0x449/0x4a0 \[btrfs\]
  \[589.567\]  ? asm\_exc\_invalid\_op+0x16/0x20
  \[589.567\]  ? btrfs\_free\_block\_groups+0x449/0x4a0 \[btrfs\]
  \[589.567\]  ? btrfs\_free\_block\_groups+0x449/0x4a0 \[btrfs\]
  \[589.567\]  close\_ctree+0x35d/0x560 \[btrfs\]
  \[589.568\]  ? fsnotify\_sb\_delete+0x13e/0x1d0
  \[589.568\]  ? dispose\_list+0x3a/0x50
  \[589.568\]  ? evict\_inodes+0x151/0x1a0
  \[589.568\]  generic\_shutdown\_super+0x73/0x1a0
  \[589.569\]  kill\_anon\_super+0x14/0x30
  \[589.569\]  btrfs\_kill\_super+0x12/0x20 \[btrfs\]
  \[589.569\]  deactivate\_locked
---truncated---

## Affected and fixed versions

- Linux: \>= 01eca70ef8cf499d0cb6d1bbd691558e7792cf17, \< 6297644db23f77c02ae7961cc542d162629ae2c4; \>= 5d19abcffd8404078dfa7d7118cec357b5e7bc58, \< 7569c4294ba6ff9f194635b14876198f8a687c4a; \>= a9f189716cf15913c453299d72f69c51a9b0f86b, \< 0657b20c5a76c938612f8409735a8830d257866e; edf3b5aadb2515c808200b904baa5b70a727f0ac; \>= 5.15.128, \< 5.16 (cvelist)
- Linux: see vendor advisory (cvelist)

## Mitigation

- Upgrade Linux to 5.16 or later.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2023-53187.md
Affected: Linux >= 01eca70ef8cf499d0cb6d1bbd691558e7792cf17, < 6297644db23f77c02ae7961cc542d162629ae2c4; >= 5d19abcffd8404078dfa7d7118cec357b5e7bc58, < 7569c4294ba6ff9f194635b14876198f8a687c4a; >= a9f189716cf15913c453299d72f69c51a9b0f86b, < 0657b20c5a76c938612f8409735a8830d257866e; edf3b5aadb2515c808200b904b…
Fixed in: Linux 6297644db23f77c02ae7961cc542d162629ae2c4, Linux 7569c4294ba6ff9f194635b14876198f8a687c4a, Linux 0657b20c5a76c938612f8409735a8830d257866e, Linux 5.16

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-2023-53187 being exploited?

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

### How serious is CVE-2023-53187?

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

### Which versions are affected by CVE-2023-53187?

Linux \>= 01eca70ef8cf499d0cb6d1bbd691558e7792cf17, \< 6297644db23f77c02ae7961cc542d162629ae2c4; \>= 5d19abcffd8404078dfa7d7118cec357b5e7bc58, \< 7569c4294ba6ff9f194635b14876198f8a687c4a; \>= a9f189716cf15913c453299d72f69c51a9b0f86b, \< 0657b20c5a76c938612f8409735a8830d257866e; edf3b5aadb2515c808200b904baa5b70a727f0ac; \>= 5.15.128, \< 5.16; Linux.

### Is there a fix for CVE-2023-53187?

Yes. Fixed in Linux 6297644db23f77c02ae7961cc542d162629ae2c4, Linux 7569c4294ba6ff9f194635b14876198f8a687c4a, Linux 0657b20c5a76c938612f8409735a8830d257866e, Linux 5.16. Upgrade Linux to 5.16 or later.

### How do I check if I'm affected by CVE-2023-53187?

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/6297644db23f77c02ae7961cc542d162629ae2c4>
- patch: <https://git.kernel.org/stable/c/7569c4294ba6ff9f194635b14876198f8a687c4a>
- patch: <https://git.kernel.org/stable/c/0657b20c5a76c938612f8409735a8830d257866e>

## 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-2023-53187>

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