CVE-2024-57976 btrfs: do proper folio cleanup when cow_file_range() failed
- Published
- Updated
- Exploit status
- No public exploit known
- Technology
- Linux KernelUbuntuDebian
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---
Upgrade path
12 packages: 5 fixed, 7 with no fix yet.
| Package | Affected | Fixed in | Status |
|---|---|---|---|
| azure linux kernel(Azure Linux 3.0) | All versions | No fix listed | No fix yet |
| cbl-mariner kernel(CBL-Mariner 2.0) | All versions | No fix listed | No fix yet |
| Microsoft cbl2 kernel 5.15.202.1-1 | All versions | No fix listed | No fix yet |
| ubuntu/linux(Ubuntu 22.04) | All versions | No fix listed | No fix yet |
| ubuntu/linux-kvm(Ubuntu 22.04) | All versions | No fix listed | No fix yet |
| ubuntu/linux-raspi(Ubuntu 22.04) | All versions | No fix listed | No fix yet |
| ubuntu/linux-raspi(Ubuntu 24.04) | All versions | No fix listed | No fix yet |
| debian/linux(Debian 12) | < 6.1.192-1; = 6.1.27-1; = 6.1.37-1; = 6.1.38-1 +55 more | 6.1.192-1 | Fixed |
| debian/linux(Debian 13) | < 6.12.37-1 | 6.12.37-1 | Fixed |
| debian/linux(Debian 14) | < 6.12.37-1 | 6.12.37-1 | Fixed |
| Linux kernel | < 6.1.191; < 6.6.160; < 6.12.36; < 6.13.2 +8 more | 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5, 6.1.191, 6.6.160, 6.12.36, 6.13.2, 6.14, 06f364284794f149d2abc167c11d556cf20c954b, 10b3772292bf1be45604ba83fd9650eb94382e78, 692cf71173bb41395c855acbbbe197d3aedfa5d4, 29418ebb8b4d4d090e403d395a6db7e8455331f7 | Fixed |
| ubuntu/linux(Ubuntu 24.04) | < 6.8.0-151.151 | 6.8.0-151.151 | Fixed |
Affected products
| Product | Affected versions | Fixed in |
|---|---|---|
| azure linux kernel(Azure Linux:3.0) | All versions | No fix listed |
| cbl-mariner kernel(CBL-Mariner:2.0) | All versions | No fix listed |
| Microsoft cbl2 kernel 5.15.202.1-1 | All versions | No fix listed |
| Linux kernel | >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 29418ebb8b4d4d090e403d395a6db7e8455331f7 | 29418ebb8b4d4d090e403d395a6db7e8455331f7 |
| Linux kernel | >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5 | 4ace6fb49c8be23b005828763d8b0d0bb0f3b0c5 |
| Linux kernel | >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 10b3772292bf1be45604ba83fd9650eb94382e78 | 10b3772292bf1be45604ba83fd9650eb94382e78 |
| Linux kernel | >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 692cf71173bb41395c855acbbbe197d3aedfa5d4 | 692cf71173bb41395c855acbbbe197d3aedfa5d4 |
| Linux kernel | >= 8b62b72b26bcd72082c4a69d179dd906bcc22200, < 06f364284794f149d2abc167c11d556cf20c954b | 06f364284794f149d2abc167c11d556cf20c954b |
| Linux kernel | = 2.6.32 | No fix listed |
| Linux kernel | < 6.1.191 | 6.1.191 |
| Linux kernel | < 6.6.160 | 6.6.160 |
| Linux kernel | < 6.12.36 | 6.12.36 |
| Linux kernel | < 6.13.2 | 6.13.2 |
| Linux kernel | < 6.14 | 6.14 |
| Linux kernel | >= 6.13, < 6.13.2 | 6.13.2 |
| debian/linux(Debian:12) | < 6.1.192-1 | 6.1.192-1 |
| debian/linux(Debian:12) | = 6.1.106-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.106-2 | No fix listed |
| debian/linux(Debian:12) | = 6.1.106-3 | No fix listed |
| debian/linux(Debian:12) | = 6.1.112-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.115-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.119-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.123-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.124-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.128-1 | No fix listed |
Show 56 more
| Product | Affected versions | Fixed in |
|---|---|---|
| debian/linux(Debian:12) | = 6.1.129-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.133-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.135-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.137-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.139-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.140-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.147-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.148-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.153-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.158-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.159-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.162-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.164-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.170-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.170-2 | No fix listed |
| debian/linux(Debian:12) | = 6.1.170-3 | No fix listed |
| debian/linux(Debian:12) | = 6.1.172-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.174-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.176-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.177-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.180-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.187-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.190-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.27-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.37-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.38-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.38-2 | No fix listed |
| debian/linux(Debian:12) | = 6.1.38-2~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.38-3 | No fix listed |
| debian/linux(Debian:12) | = 6.1.38-4 | No fix listed |
| debian/linux(Debian:12) | = 6.1.38-4~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.52-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.55-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.55-1~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.64-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.66-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.67-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.69-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.69-1~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.76-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.76-1~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.82-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.85-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.90-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.90-1~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.94-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.94-1~bpo11+1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.98-1 | No fix listed |
| debian/linux(Debian:12) | = 6.1.99-1 | No fix listed |
| debian/linux(Debian:13) | < 6.12.37-1 | 6.12.37-1 |
| debian/linux(Debian:14) | < 6.12.37-1 | 6.12.37-1 |
| ubuntu/linux(Ubuntu:22.04) | All versions | No fix listed |
| ubuntu/linux-kvm(Ubuntu:22.04) | All versions | No fix listed |
| ubuntu/linux-raspi(Ubuntu:22.04) | All versions | No fix listed |
| ubuntu/linux(Ubuntu:24.04) | < 6.8.0-151.151 | 6.8.0-151.151 |
| ubuntu/linux-raspi(Ubuntu:24.04) | All versions | No fix listed |
References
- MSRC Security Update Guide vendor-advisory
- Release Notes vendor-advisory
- Debian Security Tracker CVE-2024-57976 vendor-advisory
- Ubuntu CVE tracker vendor-advisory
- www.cve.org
- git.kernel.org
- git.kernel.org
- git.kernel.org patch
- git.kernel.org patch
- git.kernel.org patch
- USN-9175-1: Linux kernel (Oracle) vulnerabilities vendor-advisory
- USN-9173-1: Linux kernel vulnerabilities vendor-advisory
- USN-9174-1: Linux kernel (GCP FIPS) vulnerabilities vendor-advisory
- ENISA EUVD EUVD-2025-5277 third-party-advisory
- USN-9183-1: Linux kernel (FIPS) vulnerabilities vendor-advisory
- USN-9173-2: Linux kernel vulnerabilities vendor-advisory
- USN-9192-1: Linux kernel (NVIDIA) vulnerabilities vendor-advisory
- USN-9191-1: Linux kernel (Azure) vulnerabilities vendor-advisory
- USN-9173-3: Linux kernel (NVIDIA) vulnerabilities vendor-advisory
- USN-9174-2: Linux kernel (Low Latency NVIDIA) vulnerabilities vendor-advisory