bpf: Fix mmap_lock deadlock in VMA iterators using per-VMA locks #10633
+132
−123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BPF VMA iterators and bpf_find_vma() hold mmap_lock, which deadlocks when BPF programs call bpf_copy_from_user_task() on the same task (recursive lock acquisition).
Holding per-VMA locks during BPF execution also deadlocks due to circular locking: kernel has mmap_lock → vm_lock dependency (vma_expand), our code creates vm_lock → mmap_lock (callback → bpf_copy_from_user_task).
Solution: Use per-VMA locks to validate VMAs are stable, then release vm_lock BEFORE returning to BPF or calling callbacks. VMA structures remain RCU-protected during BPF execution.
Trade-off: VMA fields may be stale between lock release and BPF access. This is acceptable for tracing/profiling use cases.