bpf: Fix use-after-free on mm_struct in bpf_find_vma()#12421
bpf: Fix use-after-free on mm_struct in bpf_find_vma()#12421kernel-patches-daemon-bpf[bot] wants to merge 1 commit into
Conversation
|
Upstream branch: c15261b |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 4666109877 via email |
3a26044 to
818f7b1
Compare
|
Upstream branch: 140fa23 |
ed28ea9 to
2012955
Compare
818f7b1 to
d9ed865
Compare
|
Upstream branch: 2e8ad1f |
1 similar comment
|
Upstream branch: 2e8ad1f |
2012955 to
faf2eb2
Compare
d9ed865 to
1b36123
Compare
bpf_find_vma() reads task->mm and calls mmap_read_trylock(mm) without holding a reference on the mm. On a foreign task, a concurrent exit_mm() can free the mm_struct between the lockless read and the trylock, resulting in a use-after-free. mm_struct is not SLAB_TYPESAFE_BY_RCU. For the current task, task->mm is stable. For a foreign task, pin the mm under task->alloc_lock and release it with mmput_async(), mirroring commit d8e27d2 ("bpf: fix mm lifecycle in open-coded task_vma iterator"). Use spin_trylock() instead of get_task_mm() so BPF context does not block on alloc_lock. Reject irqs-disabled contexts and !CONFIG_MMU on the foreign-task path because dropping the mm reference is not safe there. Race: CPU0 (BPF program) CPU1 (exiting task) ============================ ========================== bpf_find_vma(foreign_task): mm = task->mm exit_mm(): task->mm = NULL mmput(mm) -> frees mm_struct mmap_read_trylock(mm) // UAF on mm Fixes: 7c7e3d3 ("bpf: Introduce helper bpf_find_vma") Signed-off-by: Sanghyun Park <sanghyun.park.cnu@gmail.com>
|
Upstream branch: 30dee2c |
faf2eb2 to
aecf6a3
Compare
Pull request for series with
subject: bpf: Fix use-after-free on mm_struct in bpf_find_vma()
version: 4
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1108917