# CVE-2024-57976: btrfs: do proper folio cleanup when cow\_file\_range() failed

> 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.31% (percentile 16, 2026-11-26)
- **CWE:** CWE-459
- **Published:** 2025-02-27T02:07:04.307Z
- **Modified:** 2026-10-30T13:17:49.503Z

## Who should check

- Anyone running Linux \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 29418ebb8b4d4d090e403d395a6db7e8455331f7; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 10b3772292bf1be45604ba83fd9650eb94382e78; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 692cf71173bb41395c855acbbbe197d3aedfa5d4; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 06f364284794f149d2abc167c11d556cf20c954b
- Anyone running Linux 2.6.32

## Description

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

btrfs: do proper folio cleanup when cow\_file\_range() failed

\[BUG\]
When testing with COW fixup marked as BUG\_ON() (this is involved with the
new pin\_user\_pages\*() change, which should not result new out-of-band
dirty pages), I hit a crash triggered by the BUG\_ON() from hitting COW
fixup path.

This BUG\_ON() happens just after a failed btrfs\_run\_delalloc\_range():

  BTRFS error (device dm-2): failed to run delalloc range, root 348 ino 405 folio 65536 submit\_bitmap 6-15 start 90112 len 106496: -28
  ------------\[ cut here \]------------
  kernel BUG at fs/btrfs/extent\_io.c:1444!
  Internal error: Oops - BUG: 00000000f2000800 \[\#1\] SMP
  CPU: 0 UID: 0 PID: 434621 Comm: kworker/u24:8 Tainted: G           OE      6.12.0-rc7-custom+ \#86
  Hardware name: QEMU KVM Virtual Machine, BIOS unknown 2/2/2022
  Workqueue: events\_unbound btrfs\_async\_reclaim\_data\_space \[btrfs\]
  pc : extent\_writepage\_io+0x2d4/0x308 \[btrfs\]
  lr : extent\_writepage\_io+0x2d4/0x308 \[btrfs\]
  Call trace:
   extent\_writepage\_io+0x2d4/0x308 \[btrfs\]
   extent\_writepage+0x218/0x330 \[btrfs\]
   extent\_write\_cache\_pages+0x1d4/0x4b0 \[btrfs\]
   btrfs\_writepages+0x94/0x150 \[btrfs\]
   do\_writepages+0x74/0x190
   filemap\_fdatawrite\_wbc+0x88/0xc8
   start\_delalloc\_inodes+0x180/0x3b0 \[btrfs\]
   btrfs\_start\_delalloc\_roots+0x174/0x280 \[btrfs\]
   shrink\_delalloc+0x114/0x280 \[btrfs\]
   flush\_space+0x250/0x2f8 \[btrfs\]
   btrfs\_async\_reclaim\_data\_space+0x180/0x228 \[btrfs\]
   process\_one\_work+0x164/0x408
   worker\_thread+0x25c/0x388
   kthread+0x100/0x118
   ret\_from\_fork+0x10/0x20
  Code: aa1403e1 9402f3ef aa1403e0 9402f36f (d4210000)
  ---\[ end trace 0000000000000000 \]---

\[CAUSE\]
That failure is mostly from cow\_file\_range(), where we can hit -ENOSPC.

Although the -ENOSPC is already a bug related to our space reservation
code, let's just focus on the error handling.

For example, we have the following dirty range \[0, 64K) of an inode,
with 4K sector size and 4K page size:

   0        16K        32K       48K       64K
   \|///////////////////////////////////////\|
   \|\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\|

Where \|///\| means page are still dirty, and \|\#\#\#\| means the extent io
tree has EXTENT\_DELALLOC flag.

- Enter extent\_writepage() for page 0

- Enter btrfs\_run\_delalloc\_range() for range \[0, 64K)

- Enter cow\_file\_range() for range \[0, 64K)

- Function btrfs\_reserve\_extent() only reserved one 16K extent
  So we created extent map and ordered extent for range \[0, 16K)

   0        16K        32K       48K       64K
   \|////////\|//////////////////////////////\|
   \|\<- OE -\>\|\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\|

   And range \[0, 16K) has its delalloc flag cleared.
   But since we haven't yet submit any bio, involved 4 pages are still
   dirty.

- Function btrfs\_reserve\_extent() returns with -ENOSPC
  Now we have to run error cleanup, which will clear all
  EXTENT\_DELALLOC\* flags and clear the dirty flags for the remaining
  ranges:

   0        16K        32K       48K       64K
   \|////////\|                              \|
   \|        \|                              \|

  Note that range \[0, 16K) still has its pages dirty.

- Some time later, writeback is triggered again for the range \[0, 16K)
  since the page range still has dirty flags.

- btrfs\_run\_delalloc\_range() will do nothing because there is no
  EXTENT\_DELALLOC flag.

- extent\_writepage\_io() finds page 0 has no ordered flag
  Which falls into the COW fixup path, triggering the BUG\_ON().

Unfortunately this error handling bug dates back to the introduction of
btrfs.  Thankfully with the abuse of COW fixup, at least it won't crash
the kernel.

\[FIX\]
Instead of immediately unlocking the extent and folios, we keep the extent
and folios locked until either erroring out or the whole delalloc range
finished.

When the whole delalloc range finished without error, we just unlock the
whole range with PAGE\_SET\_ORDERED (and PAGE\_UNLOCK for !keep\_locked
cases)
---truncated---

## Affected and fixed versions

- Linux: \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 29418ebb8b4d4d090e403d395a6db7e8455331f7; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 10b3772292bf1be45604ba83fd9650eb94382e78; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 692cf71173bb41395c855acbbbe197d3aedfa5d4; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 06f364284794f149d2abc167c11d556cf20c954b (cvelist)
- Linux: 2.6.32 (cvelist)

## Mitigation

- Upgrade Linux to 06f364284794f149d2abc167c11d556cf20c954b or later.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2024-57976.md
Affected: Linux >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 29418ebb8b4d4d090e403d395a6db7e8455331f7; >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5; >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 10b3772292bf1be45604ba83fd9650eb94382e78; >= 8b62b72b26bcd72082c4a69…
Fixed in: Linux 29418ebb8b4d4d090e403d395a6db7e8455331f7, Linux 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5, Linux 10b3772292bf1be45604ba83fd9650eb94382e78, Linux 692cf71173bb41395c855acbbbe197d3aedfa5d4, Linux 06f364284794f149d2abc167c11d556cf20c954b

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-2024-57976 being exploited?

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

### How serious is CVE-2024-57976?

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

### Which versions are affected by CVE-2024-57976?

Linux \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 29418ebb8b4d4d090e403d395a6db7e8455331f7; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 10b3772292bf1be45604ba83fd9650eb94382e78; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 692cf71173bb41395c855acbbbe197d3aedfa5d4; \>= 8b62b72b26bcd72082c4a69d179dd906bcc22200, \< 06f364284794f149d2abc167c11d556cf20c954b; Linux 2.6.32.

### Is there a fix for CVE-2024-57976?

Yes. Fixed in Linux 29418ebb8b4d4d090e403d395a6db7e8455331f7, Linux 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5, Linux 10b3772292bf1be45604ba83fd9650eb94382e78, Linux 692cf71173bb41395c855acbbbe197d3aedfa5d4, Linux 06f364284794f149d2abc167c11d556cf20c954b. Upgrade Linux to 06f364284794f149d2abc167c11d556cf20c954b or later.

### How do I check if I'm affected by CVE-2024-57976?

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/10b3772292bf1be45604ba83fd9650eb94382e78>
- patch: <https://git.kernel.org/stable/c/692cf71173bb41395c855acbbbe197d3aedfa5d4>
- patch: <https://git.kernel.org/stable/c/06f364284794f149d2abc167c11d556cf20c954b>
- other: <https://git.kernel.org/stable/c/29418ebb8b4d4d090e403d395a6db7e8455331f7>
- other: <https://git.kernel.org/stable/c/4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5>

## 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-2024-57976>

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