CVE-2025-22115
Severity CVSS v4.0:
Pending analysis
Type:
CWE-362
Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
Publication date:
16/04/2025
Last modified:
03/11/2025
Description
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
btrfs: fix block group refcount race in btrfs_create_pending_block_groups()<br />
<br />
Block group creation is done in two phases, which results in a slightly<br />
unintuitive property: a block group can be allocated/deallocated from<br />
after btrfs_make_block_group() adds it to the space_info with<br />
btrfs_add_bg_to_space_info(), but before creation is completely completed<br />
in btrfs_create_pending_block_groups(). As a result, it is possible for a<br />
block group to go unused and have &#39;btrfs_mark_bg_unused&#39; called on it<br />
concurrently with &#39;btrfs_create_pending_block_groups&#39;. This causes a<br />
number of issues, which were fixed with the block group flag<br />
&#39;BLOCK_GROUP_FLAG_NEW&#39;.<br />
<br />
However, this fix is not quite complete. Since it does not use the<br />
unused_bg_lock, it is possible for the following race to occur:<br />
<br />
btrfs_create_pending_block_groups btrfs_mark_bg_unused<br />
if list_empty // false<br />
list_del_init<br />
clear_bit<br />
else if (test_bit) // true<br />
list_move_tail<br />
<br />
And we get into the exact same broken ref count and invalid new_bgs<br />
state for transaction cleanup that BLOCK_GROUP_FLAG_NEW was designed to<br />
prevent.<br />
<br />
The broken refcount aspect will result in a warning like:<br />
<br />
[1272.943527] refcount_t: underflow; use-after-free.<br />
[1272.943967] WARNING: CPU: 1 PID: 61 at lib/refcount.c:28 refcount_warn_saturate+0xba/0x110<br />
[1272.944731] Modules linked in: btrfs virtio_net xor zstd_compress raid6_pq null_blk [last unloaded: btrfs]<br />
[1272.945550] CPU: 1 UID: 0 PID: 61 Comm: kworker/u32:1 Kdump: loaded Tainted: G W 6.14.0-rc5+ #108<br />
[1272.946368] Tainted: [W]=WARN<br />
[1272.946585] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.16.3-1-1 04/01/2014<br />
[1272.947273] Workqueue: btrfs_discard btrfs_discard_workfn [btrfs]<br />
[1272.947788] RIP: 0010:refcount_warn_saturate+0xba/0x110<br />
[1272.949532] RSP: 0018:ffffbf1200247df0 EFLAGS: 00010282<br />
[1272.949901] RAX: 0000000000000000 RBX: ffffa14b00e3f800 RCX: 0000000000000000<br />
[1272.950437] RDX: 0000000000000000 RSI: ffffbf1200247c78 RDI: 00000000ffffdfff<br />
[1272.950986] RBP: ffffa14b00dc2860 R08: 00000000ffffdfff R09: ffffffff90526268<br />
[1272.951512] R10: ffffffff904762c0 R11: 0000000063666572 R12: ffffa14b00dc28c0<br />
[1272.952024] R13: 0000000000000000 R14: ffffa14b00dc2868 R15: 000001285dcd12c0<br />
[1272.952850] FS: 0000000000000000(0000) GS:ffffa14d33c40000(0000) knlGS:0000000000000000<br />
[1272.953458] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033<br />
[1272.953931] CR2: 00007f838cbda000 CR3: 000000010104e000 CR4: 00000000000006f0<br />
[1272.954474] Call Trace:<br />
[1272.954655] <br />
[1272.954812] ? refcount_warn_saturate+0xba/0x110<br />
[1272.955173] ? __warn.cold+0x93/0xd7<br />
[1272.955487] ? refcount_warn_saturate+0xba/0x110<br />
[1272.955816] ? report_bug+0xe7/0x120<br />
[1272.956103] ? handle_bug+0x53/0x90<br />
[1272.956424] ? exc_invalid_op+0x13/0x60<br />
[1272.956700] ? asm_exc_invalid_op+0x16/0x20<br />
[1272.957011] ? refcount_warn_saturate+0xba/0x110<br />
[1272.957399] btrfs_discard_cancel_work.cold+0x26/0x2b [btrfs]<br />
[1272.957853] btrfs_put_block_group.cold+0x5d/0x8e [btrfs]<br />
[1272.958289] btrfs_discard_workfn+0x194/0x380 [btrfs]<br />
[1272.958729] process_one_work+0x130/0x290<br />
[1272.959026] worker_thread+0x2ea/0x420<br />
[1272.959335] ? __pfx_worker_thread+0x10/0x10<br />
[1272.959644] kthread+0xd7/0x1c0<br />
[1272.959872] ? __pfx_kthread+0x10/0x10<br />
[1272.960172] ret_from_fork+0x30/0x50<br />
[1272.960474] ? __pfx_kthread+0x10/0x10<br />
[1272.960745] ret_from_fork_asm+0x1a/0x30<br />
[1272.961035] <br />
[1272.961238] ---[ end trace 0000000000000000 ]---<br />
<br />
Though we have seen them in the async discard workfn as well. It is<br />
most likely to happen after a relocation finishes which cancels discard,<br />
tears down the block group, etc.<br />
<br />
Fix this fully by taking the lock arou<br />
---truncated---
Impact
Base Score 3.x
4.70
Severity 3.x
MEDIUM
Vulnerable products and versions
| CPE | From | Up to |
|---|---|---|
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.1.47 (including) | 6.2 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.4.12 (including) | 6.5 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.5.1 (including) | 6.12.40 (excluding) |
| cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* | 6.13 (including) | 6.14.2 (excluding) |
| cpe:2.3:o:linux:linux_kernel:6.5:-:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:6.5:rc3:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:6.5:rc4:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:6.5:rc5:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:6.5:rc6:*:*:*:*:*:* | ||
| cpe:2.3:o:linux:linux_kernel:6.5:rc7:*:*:*:*:*:* |
To consult the complete list of CPE names with products and versions, see this page



