btrfs: fix deadlock between concurrent dio writes when low on free data space
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
| No fix yet |
| Linux Linux |
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix deadlock between concurrent dio writes when low on free data space
When reserving data space for a direct IO write we can end up deadlocking if we have multiple tasks attempting a write to the same file range, there are multiple extents covered by that file range, we are low on available space for data and the writes don't expand the inode's i_size.
The deadlock can happen like this:
1) We have a file with an i_size of 1M, at offset 0 it has an extent with a size of 128K and at offset 128K it has another extent also with a size of 128K;
2) Task A does a direct IO write against file range [0, 256K), and because the write is within the i_size boundary, it takes the inode's lock (VFS level) in shared mode;
3) Task A locks the file range [0, 256K) at btrfs_dio_iomap_begin(), and then gets the extent map for the extent covering the range [0, 128K). At btrfs_get_blocks_direct_write(), it creates an ordered extent for that file range ([0, 128K));
4) Before returning from btrfs_dio_iomap_begin(), it unlocks the file range [0, 256K);
From the CVE record · Linux
The Linux kernel's btrfs direct I/O write path can deadlock when multiple tasks write to the same file range. This requires multiple extents in that range, low free data space, and writes that do not increase the file size. The resulting deadlock can prevent the writes from completing.
Engineers running Linux kernels with btrfs should check their versions against the vendor advisory; affected versions are not specified in the input.