Skip to content
OpenAdvisories
High · 7.8 CVE-2024-46734 EUVD-2024-41995GHSA-pw8w-hq42-r2hw

btrfs: fix race between direct IO write and fsync when using same fd

Published Sep 18, 2024 · Updated Aug 5, 2026 · Assigned by Linux

Vendor: Linux Product: Linux Package: linux Package: linux-allwinner-5.19 Package: linux-aws-5.0 Package: linux-aws-5.11 Package: linux-aws-5.13 Package: linux-aws-5.19 Package: linux-aws-5.3 Package: linux-aws-5.8 Package: linux-aws-6.2 Package: linux-aws-6.5 Package: linux-azure Package: linux-azure-5.11 Package: linux-azure-5.13 Package: linux-azure-5.19 Package: linux-azure-5.3 Package: linux-azure-5.8 Package: linux-azure-6.2 Package: linux-azure-6.5 Package: linux-azure-edge Package: linux-azure-fde Package: linux-azure-fde-5.19 Package: linux-azure-fde-6.2 Package: linux-gcp Package: linux-gcp-5.11 Package: linux-gcp-5.13 Package: linux-gcp-5.19 Package: linux-gcp-5.3 Package: linux-gcp-5.8 Package: linux-gcp-6.2 Package: linux-gcp-6.5 Package: linux-gke Package: linux-gke-4.15 Package: linux-gke-5.15 Package: linux-gke-5.4 Package: linux-gkeop-5.4 Package: linux-hwe Package: linux-hwe-5.11 Package: linux-hwe-5.13 Package: linux-hwe-5.19 Package: linux-hwe-5.8 Package: linux-hwe-6.2 Package: linux-hwe-6.5 Package: linux-hwe-edge Package: linux-intel-5.13 Package: linux-intel-iot-realtime Package: linux-lowlatency-hwe-5.19 Package: linux-lowlatency-hwe-6.2 Package: linux-lowlatency-hwe-6.5 Package: linux-nvidia-6.2 Package: linux-oem Package: linux-oem-5.10 Package: linux-oem-5.13 Package: linux-oem-5.14 Package: linux-oem-5.17 Package: linux-oem-5.6 Package: linux-oem-6.0 Package: linux-oem-6.1 Package: linux-oem-6.5 Package: linux-oracle-5.0 Package: linux-oracle-5.11 Package: linux-oracle-5.13 Package: linux-oracle-5.3 Package: linux-oracle-5.8 Package: linux-oracle-6.5 Package: linux-raspi-realtime Package: linux-raspi2 Package: linux-realtime Package: linux-riscv Package: linux-riscv-5.11 Package: linux-riscv-5.19 Package: linux-riscv-5.8 Package: linux-riscv-6.5 Package: linux-starfive-5.19 Package: linux-starfive-6.2 Package: linux-starfive-6.5 Platform: Linux Ecosystem: Debian Ecosystem: Ubuntu

Description

In the Linux kernel, the following vulnerability has been resolved:

btrfs: fix race between direct IO write and fsync when using same fd

If we have 2 threads that are using the same file descriptor and one of
them is doing direct IO writes while the other is doing fsync, we have a
race where we can end up either:

1) Attempt a fsync without holding the inode's lock, triggering an
assertion failures when assertions are enabled;

2) Do an invalid memory access from the fsync task because the file private
points to memory allocated on stack by the direct IO task and it may be
used by the fsync task after the stack was destroyed.

The race happens like this:

1) A user space program opens a file descriptor with O_DIRECT;

2) The program spawns 2 threads using libpthread for example;

3) One of the threads uses the file descriptor to do direct IO writes,
while the other calls fsync using the same file descriptor.

4) Call task A the thread doing direct IO writes and task B the thread
doing fsyncs;

5) Task A does a direct IO write, and at btrfs_direct_write() sets the
file's private to an on stack allocated private with the member
'fsync_skip_inode_lock' set to true;

6) Task B enters btrfs_sync_file() and sees that there's a private
structure associated to the file which has 'fsync_skip_inode_lock' set
to true, so it skips locking the inode's VFS lock;

7) Task A completes the direct IO write, and resets the file's private to
NULL since it had no prior private and our private was stack allocated.
Then it unlocks the inode's VFS lock;

8) Task B enters btrfs_get_ordered_extents_for_logging(), then the
assertion that checks the inode's VFS lock is held fails, since task B
never locked it and task A has already unlocked it.

The stack trace produced is the following:

assertion failed: inode_is_locked(&inode->vfs_inode), in fs/btrfs/ordered-data.c:983
------------[ cut here ]------------
kernel BUG at fs/btrfs/ordered-data.c:983!
Oops: invalid opcode: 0000 [#1] PREEMPT SMP PTI
CPU: 9 PID: 5072 Comm: worker Tainted: G U OE 6.10.5-1-default #1 openSUSE Tumbleweed 69f48d427608e1c09e60ea24c6c55e2ca1b049e8
Hardware name: Acer Predator PH315-52/Covini_CFS, BIOS V1.12 07/28/2020
RIP: 0010:btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs]
Code: 50 d6 86 c0 e8 (...)
RSP: 0018:ffff9e4a03dcfc78 EFLAGS: 00010246
RAX: 0000000000000054 RBX: ffff9078a9868e98 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffff907dce4a7800 RDI: ffff907dce4a7800
RBP: ffff907805518800 R08: 0000000000000000 R09: ffff9e4a03dcfb38
R10: ffff9e4a03dcfb30 R11: 0000000000000003 R12: ffff907684ae7800
R13: 0000000000000001 R14: ffff90774646b600 R15: 0000000000000000
FS: 00007f04b96006c0(0000) GS:ffff907dce480000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f32acbfc000 CR3: 00000001fd4fa005 CR4: 00000000003726f0
Call Trace:
<TASK>
? __die_body.cold+0x14/0x24
? die+0x2e/0x50
? do_trap+0xca/0x110
? do_error_trap+0x6a/0x90
? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a]
? exc_invalid_op+0x50/0x70
? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a]
? asm_exc_invalid_op+0x1a/0x20
? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a]
? btrfs_get_ordered_extents_for_logging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a]
btrfs_sync_file+0x21a/0x4d0 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a]
? __seccomp_filter+0x31d/0x4f0
__x64_sys_fdatasync+0x4f/0x90
do_syscall_64+0x82/0x160
? do_futex+0xcb/0x190
? __x64_sys_futex+0x10e/0x1d0
? switch_fpu_return+0x4f/0xd0
? syscall_exit_to_user_mode+0x72/0x220
? do_syscall_64+0x8e/0x160
? syscall_exit_to_user_mod
---truncated---

Affected products

VendorProductAffectedFixed
Linux Linux 5.15.165 – < 5.15.167, 6.1.105 – < 6.1.110, 6.6.46 – < 6.6.51, 6.10.5 – < 6.10.10 5.15.167

Fixed in Linux distributions

Distributions backport fixes, so the version that fixes this vulnerability differs per release — upgrade to at least the version shown. From the distributions' security trackers and advisories.

ReleasePackageFixed inAdvisory
Debian 14 linux 6.10.11-1 —
Debian 13 linux 6.10.11-1 —
Debian 12 linux 6.1.112-1 DSA-5782-1
Debian 11 linux-6.1 6.1.119-1~deb11u1 DLA-4008-1
ReleasePackageFixed inAdvisory
Ubuntu 24.04 LTS linux-raspi-realtime No fix yet —
Ubuntu 22.04 LTS linux-riscv +31 No fix yet —
Ubuntu 20.04 LTS linux-gke +26 No fix yet —
Ubuntu 18.04 LTS linux-gcp +14 No fix yet —
Ubuntu 16.04 LTS linux-hwe-edge No fix yet —
ReleasePackageFixed inAdvisory
SLES 15 SP6 kernel-64kb +4 6.4.0-150600.23.25.1 SUSE-SU-2024:3561-1
SLES 15 SP6 kernel-azure +2 6.4.0-150600.8.14.1 SUSE-SU-2024:3551-1
SLES 15 SP6 kernel-coco +3 6.4.0-15061.6.coco15sp6.1 SUSE-SU-2024:3553-1
SLES 15 SP6 kernel-default-base 6.4.0-150600.23.25.1.150600.12.10.2 SUSE-SU-2024:3561-1
SLES 15 SP6 kernel-docs +1 6.4.0-150600.23.25.2 SUSE-SU-2024:3561-1
Show 3 more (older releases, extended support, other products)
ReleasePackageFixed inAdvisory
SLE Micro 6.0 kernel-default-base 6.4.0-17.1.1.51 SUSE-SU-2025:20073-1
SLE Micro 6.0 kernel-livepatch-MICRO-6-0_Update_3 +1 1-1.2 SUSE-SU-2025:20077-1, SUSE-SU-2025:20073-1
SLE Micro 6.0 kernel-rt +1 6.4.0-11.1 SUSE-SU-2025:20077-1
SLE Micro 6.0 kernel-source +2 6.4.0-20.1 SUSE-SU-2025:20073-1
SLE Live Patching 15 SP6 kernel-default 6.4.0-150600.23.25.1 SUSE-SU-2024:3561-1
SLE Live Patching 15 SP6 kernel-livepatch-SLE15-SP6-RT_Update_4 1-150600.1.3.1 SUSE-SU-2024:3564-1
SLE Live Patching 15 SP6 kernel-livepatch-SLE15-SP6_Update_5 1-150600.13.3.1 SUSE-SU-2024:3561-1
SUSE Real Time Module 15 SP6 kernel-rt +3 6.4.0-150600.10.14.1 SUSE-SU-2024:3564-1
ReleasePackageFixed inAdvisory
openSUSE Leap 15.6 dtb-aarch64 +8 6.4.0-150600.23.25.1 SUSE-SU-2024:3561-1
openSUSE Leap 15.6 kernel-azure +2 6.4.0-150600.8.14.1 SUSE-SU-2024:3551-1
openSUSE Leap 15.6 kernel-default-base 6.4.0-150600.23.25.1.150600.12.10.2 SUSE-SU-2024:3561-1
openSUSE Leap 15.6 kernel-docs +1 6.4.0-150600.23.25.2 SUSE-SU-2024:3561-1
openSUSE Leap 15.6 kernel-rt +3 6.4.0-150600.10.14.1 SUSE-SU-2024:3564-1

Amazon Linux

ReleasePackageFixed inAdvisory
Amazon Linux 2023 kernel-livepatch-6.1.111-120.187 1.0-0.amzn2023 ALAS2023-2024-744, ALAS2023-2024-724
Amazon Linux 2023 perf +14 6.1.111-120.187.amzn2023 ALAS2023-2024-744, ALAS2023-2024-724

Oracle Linux

ReleasePackageFixed inAdvisory
Oracle Linux 8 bpftool +13 5.15.0-302.167.6.el9uek ELSA-2024-12815

Advisories 12

References