CVE-2024-26726

Source
https://cve.org/CVERecord?id=CVE-2024-26726
Import Source
https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2024-26726.json
JSON Data
https://api.osv.dev/v1/vulns/CVE-2024-26726
Downstream
Related
Published
2024-04-03T14:55:24.983Z
Modified
2026-03-14T12:27:40.829209Z
Summary
btrfs: don't drop extent_map for free space inode on write error
Details

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

btrfs: don't drop extent_map for free space inode on write error

While running the CI for an unrelated change I hit the following panic with generic/648 on btrfsholesspacecache.

assertion failed: blockstart != EXTENTMAPHOLE, in fs/btrfs/extentio.c:1385 ------------[ cut here ]------------ kernel BUG at fs/btrfs/extent_io.c:1385! invalid opcode: 0000 [#1] PREEMPT SMP NOPTI CPU: 1 PID: 2695096 Comm: fsstress Kdump: loaded Tainted: G W 6.8.0-rc2+ #1 RIP: 0010:__extentwritepageio.constprop.0+0x4c1/0x5c0 Call Trace: <TASK> extentwritecachepages+0x2ac/0x8f0 extentwritepages+0x87/0x110 dowritepages+0xd5/0x1f0 filemapfdatawrite_wbc+0x63/0x90 __filemapfdatawriterange+0x5c/0x80 btrfsfdatawriterange+0x1f/0x50 btrfswriteoutcache+0x507/0x560 btrfswritedirtyblockgroups+0x32a/0x420 commitcowonlyroots+0x21b/0x290 btrfscommittransaction+0x813/0x1360 btrfssync_file+0x51a/0x640 __x64sysfdatasync+0x52/0x90 dosyscall64+0x9c/0x190 entrySYSCALL64afterhwframe+0x6e/0x76

This happens because we fail to write out the free space cache in one instance, come back around and attempt to write it again. However on the second pass through we go to call btrfsgetextent() on the inode to get the extent mapping. Because this is a new block group, and with the free space inode we always search the commit root to avoid deadlocking with the tree, we find nothing and return a EXTENTMAPHOLE for the requested range.

This happens because the first time we try to write the space cache out we hit an error, and on an error we drop the extent mapping. This is normal for normal files, but the free space cache inode is special. We always expect the extent map to be correct. Thus the second time through we end up with a bogus extent map.

Since we're deprecating this feature, the most straightforward way to fix this is to simply skip dropping the extent map range for this failed range.

I shortened the test by using error injection to stress the area to make it easier to reproduce. With this patch in place we no longer panic with my error injection test.

Database specific
{
    "cna_assigner": "Linux",
    "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2024/26xxx/CVE-2024-26726.json"
}
References

Affected packages

Git / git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

Affected ranges

Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
77cef2ec5484564eca6bd12a2b4a1e88fd766fbc
Fixed
143842584c1237ebc248b2547c29d16bbe400a92
Fixed
02f2b95b00bf57d20320ee168b30fb7f3db8e555
Fixed
7bddf18f474f166c19f91b2baf67bf7c5eda03f7
Fixed
a4b7741c8302e28073bfc6dd1c2e73598e5e535e
Fixed
5571e41ec6e56e35f34ae9f5b3a335ef510e0ade

Database specific

source
"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2024-26726.json"