Acknowledged
Created: Jun 18, 2025
Updated: Sep 4, 2026
Resolved Date: Jun 19, 2025
Found In Version: 10.25.33.1
Severity: Standard
Applicable for: Wind River Linux LTS 25
Component/s: Kernel
In the Linux kernel, the following vulnerability has been resolved:EOL][EOL]btrfs: fix space cache corruption and potential double allocations[EOL][EOL]When testing space_cache v2 on a large set of machines, we encountered a[EOL]few symptoms:[EOL][EOL]1. "unable to add free space :-17" (EEXIST) errors.[EOL]2. Missing free space info items, sometimes caught with a "missing free[EOL] space info for X" error.[EOL]3. Double-accounted space: ranges that were allocated in the extent tree[EOL] and also marked as free in the free space tree, ranges that were[EOL] marked as allocated twice in the extent tree, or ranges that were[EOL] marked as free twice in the free space tree. If the latter made it[EOL] onto disk, the next reboot would hit the BUG_ON() in[EOL] add_new_free_space().[EOL]4. On some hosts with no on-disk corruption or error messages, the[EOL] in-memory space cache (dumped with drgn) disagreed with the free[EOL] space tree.[EOL][EOL]All of these symptoms have the same underlying cause: a race between[EOL]caching the free space for a block group and returning free space to the[EOL]in-memory space cache for pinned extents causes us to double-add a free[EOL]range to the space cache. This race exists when free space is cached[EOL]from the free space tree (space_cache=v2) or the extent tree[EOL](nospace_cache, or space_cache=v1 if the cache needs to be regenerated).[EOL]struct btrfs_block_group::last_byte_to_unpin and struct[EOL]btrfs_block_group::progress are supposed to protect against this race,[EOL]but commit d0c2f4fa555e ("btrfs: make concurrent fsyncs wait less when[EOL]waiting for a transaction commit") subtly broke this by allowing[EOL]multiple transactions to be unpinning extents at the same time.[EOL][EOL]Specifically, the race is as follows:[EOL][EOL]1. An extent is deleted from an uncached block group in transaction A.[EOL]2. btrfs_commit_transaction() is called for transaction A.[EOL]3. btrfs_run_delayed_refs() -> __btrfs_free_extent() runs the delayed[EOL] ref for the deleted extent.[EOL]4. __btrfs_free_extent() -> do_free_extent_accounting() ->[EOL] add_to_free_space_tree() adds the deleted extent back to the free[EOL] space tree.[EOL]5. do_free_extent_accounting() -> btrfs_update_block_group() ->[EOL] btrfs_cache_block_group() queues up the block group to get cached.[EOL] block_group->progress is set to block_group->start.[EOL]6. btrfs_commit_transaction() for transaction A calls[EOL] switch_commit_roots(). It sets block_group->last_byte_to_unpin to[EOL] block_group->progress, which is block_group->start because the block[EOL] group hasn't been cached yet.[EOL]7. The caching thread gets to our block group. Since the commit roots[EOL] were already switched, load_free_space_tree() sees the deleted extent[EOL] as free and adds it to the space cache. It finishes caching and sets[EOL] block_group->progress to U64_MAX.[EOL]8. btrfs_commit_transaction() advances transaction A to[EOL] TRANS_STATE_SUPER_COMMITTED.[EOL]9. fsync calls btrfs_commit_transaction() for transaction B. Since[EOL] transaction A is already in TRANS_STATE_SUPER_COMMITTED and the[EOL] commit is for fsync, it advances.[EOL]10. btrfs_commit_transaction() for transaction B calls[EOL] switch_commit_roots(). This time, the block group has already been[EOL] cached, so it sets block_group->last_byte_to_unpin to U64_MAX.[EOL]11. btrfs_commit_transaction() for transaction A calls[EOL] btrfs_finish_extent_commit(), which calls unpin_extent_range() for[EOL] the deleted extent. It sees last_byte_to_unpin set to U64_MAX (by[EOL] transaction B!), so it adds the deleted extent to the space cache[EOL] again![EOL][EOL]This explains all of our symptoms above:[EOL][EOL]* If the sequence of events is exactly as described above, when the free[EOL] space is re-added in step 11, it will fail with EEXIST.[EOL]* If another thread reallocates the deleted extent in between steps 7[EOL] and 11, then step 11 will silently re-add that space to the space[EOL] cache as free even though it is actually allocated. Then, if that[EOL] space is allocated *again*, the free space tree will be corrupted[EOL] (namely, the wrong item will be deleted).[EOL]* If we don't catch this free space tree corr[EOL]---truncated---
CREATE(Triage):(User=lchen-cn) [CVE-2022-49999 (https://nvd.nist.gov/vuln/detail/CVE-2022-49999)