CVE-2024-35784: btrfs: fix deadlock with fiemap and extent locking
In the Linux kernel, the following vulnerability has been resolved:
btrfs: fix deadlock with fiemap and extent locking
While working on the patchset to remove extent locking I got a lockdep
splat with fiemap and pagefaulting with my new extent lock replacement
lock.
This deadlock exists with our normal code, we just don't have lockdep
annotations with the extent locking so we've never noticed it.
Since we're copying the fiemap extent to user space on every iteration
we have the chance of pagefaulting. Because we hold the extent lock for
the entire range we could mkwrite into a range in the file that we have
mmap'ed. This would deadlock with the following stack trace
[<0>] lock_extent+0x28d/0x2f0
[<0>] btrfs_page_mkwrite+0x273/0x8a0
[<0>] do_page_mkwrite+0x50/0xb0
[<0>] do_fault+0xc1/0x7b0
[<0>] __handle_mm_fault+0x2fa/0x460
[<0>] handle_mm_fault+0xa4/0x330
[<0>] do_user_addr_fault+0x1f4/0x800
[<0>] exc_page_fault+0x7c/0x1e0
[<0>] asm_exc_page_fault+0x26/0x30
[<0>] rep_movs_alternative+0x33/0x70
[<0>] _copy_to_user+0x49/0x70
[<0>] fiemap_fill_next_extent+0xc8/0x120
[<0>] emit_fiemap_extent+0x4d/0xa0
[<0>] extent_fiemap+0x7f8/0xad0
[<0>] btrfs_fiemap+0x49/0x80
[<0>] __x64_sys_ioctl+0x3e1/0xb50
[<0>] do_syscall_64+0x94/0x1a0
[<0>] entry_SYSCALL_64_after_hwframe+0x6e/0x76
I wrote an fstest to reproduce this deadlock without my replacement lock
and verified that the deadlock exists with our existing locking.
To fix this simply don't take the extent lock for the entire duration of
the fiemap. This is safe in general because we keep track of where we
are when we're searching the tree, so if an ordered extent updates in
the middle of our fiemap call we'll still emit the correct extents
because we know what offset we were on before.
The only place we maintain the lock is searching delalloc. Since the
delalloc stuff can change during writeback we want to lock the extent
range so we have a consistent view of delalloc at the time we're
checking to see if we need to set the delalloc flag.
With this patch applied we no longer deadlock with my testcase.
Security readout for executives and security teams
Plain-English summary
CVE-2024-35784 is a Linux kernel Btrfs deadlock bug. A local file operation can hang when fiemap copies extent data to user space while page fault handling tries to take the same extent lock. The business impact is likely availability, not data theft, based on the provided sources.
Executive priority
Handle through normal kernel patch management, with elevated priority for Btrfs servers that run untrusted local users, containers, or shared workloads. No evidence in the bundle supports emergency internet-wide response.
Technical view
In Btrfs, fiemap held an extent lock across a range while iterating and copying results to user space. If that copy faults on an mmap'ed file range, btrfs_page_mkwrite can try to lock the same extent and deadlock. The fix narrows extent locking, retaining it only where delalloc consistency requires it.
Likely exposure
Exposure is most relevant on Linux systems using Btrfs with kernel versions before the referenced stable fixes or without equivalent vendor backports. Systems not using Btrfs are unlikely to be affected by this specific bug.
Exploitation context
The provided sources describe a reproducible deadlock test but do not cite public weaponization, remote exploitation, privilege escalation, or CISA KEV listing. Treat exploitation status as unconfirmed and focus on local availability risk.
Researcher notes
The key condition is interaction between fiemap, copy_to_user page faults, mmap write fault handling, and Btrfs extent locks. The fix changes locking scope rather than disabling fiemap or Btrfs behavior. CVSS and CWE data are not provided.
Mitigation direction
Apply Linux kernel updates containing the referenced Btrfs stable fixes.
Check distribution vendor advisories for equivalent backported fixes.
Prioritize Btrfs hosts with multi-user local access or untrusted workloads.
If patching is delayed, follow vendor guidance for temporary operational controls.
Validation and detection
Inventory Linux hosts using Btrfs filesystems.
Map running kernel packages to vendor fixed versions or backport notes.
Confirm whether the referenced stable commits are present in deployed kernels.
Monitor systems for unexplained Btrfs-related hangs until patched.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cve · low confidence lookup
CVE-2024-35784 mapping review
Open the CVE-to-ATT&CK bridge for reviewed, inferred, or future official mappings tied to this CVE.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.