Categories
CVE-2022-49547

btrfs: fix deadlock between concurrent dio writes when low on free data space

Summary

btrfs: fix deadlock between concurrent dio writes when low on free data space

Original description

The description as published by the source.

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);

  5. Task A executes btrfs_dio_iomap_begin() again, this time for the file
    range [128K, 256K), and locks the file range [128K, 256K);

  6. Task B starts a direct IO write against file range [0, 256K) as well.
    It also locks the inode in shared mode, as it's within the i_size limit,
    and then tries to lock file range [0, 256K). It is able to l…

Source: OSV.dev (Open Source Vulnerabilities) NVD OSV

Affected packages

Linux Kernel
[{"type":"ECOSYSTEM","events":[{"introduced":"5.17.0"},{"fixed":"5.18.3"}]}]

Fix status by distribution

Fixed packages published by each distribution for this CVE

References

We use cookies for analytics and ad measurement. This setting applies to all Game co., Ltd. sites. Details