btrfs: fix racy bitfield write in btrfs_clear_space_info_full()
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
≥ 957780eb2788d8c218d539e19a85653f51a96dc1 · < 742b90eaf394f0018352c0e10dc89763b2dd5267| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix racy bitfield write in btrfs_clear_space_info_full()
From the memory-barriers.txt document regarding memory barrier ordering guarantees:
(*) These guarantees do not apply to bitfields, because compilers often generate code to modify these using non-atomic read-modify-write sequences. Do not attempt to use bitfields to synchronize parallel algorithms.
(*) Even in cases where bitfields are protected by locks, all fields in a given bitfield must be protected by one lock. If two fields in a given bitfield are protected by different locks, the compiler's non-atomic read-modify-write sequences can cause an update to one field to corrupt the value of an adjacent field.
btrfs_space_info has a bitfield sharing an underlying word consisting of the fields full, chunk_alloc, and flush:
struct btrfs_space_info { struct btrfs_fs_info * fs_info; /* 0 8 */ struct btrfs_space_info * parent; /* 8 8 */ ... int clamp; /* 172 4 */ unsigned int full:1; /* 176: 0 4 */ unsigned int chunk_alloc:1; /* 176: 1 4 */ unsigned int flush:1; /* 176: 2 4 */ ...
Therefore, to be safe from parallel read-modify-writes losing a write to one of the bitfield members protected by a lock, all writes to all the bitfields must use the lock. They almost universally do, except for btrfs_clear_space_info_full() which iterates over the space_infos and writes out found->full = 0 without a lock.
From the CVE record · Linux
A racy bitfield write in the Linux kernel’s Btrfs space management can overwrite a concurrent update. When transaction completion and asynchronous data reclaim run at the same time, the reclaim worker can exit while the flush flag remains set, breaking the reclaim-state invariant. The input does not describe an attacker path, authentication requirement, or user interaction.
Engineers running Linux systems that use Btrfs should check their kernel versions; affected versions are not specified in the input.