CVE-2024-46734: btrfs: fix race between direct IO write and fsync when using same fd

Published Sep 18, 2024
·
Updated

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

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 btrfsdirectwrite() sets the file's private to an on stack allocated private with the member 'fsyncskipinodelock' set to true;

6) Task B enters btrfssyncfile() and sees that there's a private structure associated to the file which has 'fsyncskipinodelock' 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 btrfsgetorderedextentsforlogging(), 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: inodeislocked(&inode->vfsinode), 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/CoviniCFS, BIOS V1.12 07/28/2020 RIP: 0010:btrfsgetorderedextentsforlogging.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> ? diebody.cold+0x14/0x24 ? die+0x2e/0x50 ? dotrap+0xca/0x110 ? doerrortrap+0x6a/0x90 ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? excinvalidop+0x50/0x70 ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? asmexcinvalidop+0x1a/0x20 ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] btrfssyncfile+0x21a/0x4d0 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? seccompfilter+0x31d/0x4f0 x64sysfdatasync+0x4f/0x90 dosyscall64+0x82/0x160 ? dofutex+0xcb/0x190 ? x64sysfutex+0x10e/0x1d0 ? switchfpureturn+0x4f/0xd0 ? syscallexittousermode+0x72/0x220 ? dosyscall64+0x8e/0x160 ? syscallexittousermod ---truncated---

Affected Software

11 affected componentsFixes available
Linux Kernel
Linux Linux kernel>=5.15.165<5.15.167
Linux Linux kernel>=6.1.105<6.1.110
Linux Linux kernel>=6.6.46<6.6.51
Linux Linux kernel>=6.10.5<6.10.10
Linux Linux kernel=6.11-rc2
Linux Linux kernel=6.11-rc3
Linux Linux kernel=6.11-rc4
Linux Linux kernel=6.11-rc5
Linux Linux kernel=6.11-rc6
debian/linux
6.1.176-16.1.190-16.12.107-16.12.113-17.2.12-17.2.13-1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade debian/linux to a version that resolves this vulnerability.

    Fixed in 6.1.176-1Fixed in 6.1.190-1Fixed in 6.12.107-1Fixed in 6.12.113-1Fixed in 7.2.12-1Fixed in 7.2.13-1

Event History

Sep 18, 2024
CVE Published
via MITRE·07:11 AM
Data Sourced
via MITRE·07:11 AM
DescriptionSeverity
Data Sourced
via NVD·08:15 AM
RemedyDescriptionSeverityWeaknessAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Peer vulnerabilities

Found alongside the following vulnerabilities.

Frequently Asked Questions

1

What is the severity of CVE-2024-46734?

CVE-2024-46734 has a medium severity rating due to potential data inconsistencies when using direct IO writes and fsync on the same file descriptor.

2

How do I fix CVE-2024-46734?

To fix CVE-2024-46734, ensure that you update to the patched version of the Linux kernel that addresses this specific vulnerability.

3

Which versions of the Linux kernel are affected by CVE-2024-46734?

CVE-2024-46734 affects various versions of the Linux kernel that utilize the btrfs file system.

4

What are the risks of not addressing CVE-2024-46734?

Not addressing CVE-2024-46734 may lead to data corruption or loss due to race conditions between direct IO operations and fsync calls.

5

Is CVE-2024-46734 a known exploit?

As of now, there are no known exploits in the wild specifically targeting CVE-2024-46734.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203