Re: [PATCH 1/2] uprobes: skip mappings not managed by core mm

From: David Hildenbrand (Arm)

Date: Tue Dec 01 2026 - 04:36:27 EST


On 12/1/26 01:42, Masami Hiramatsu (Google) wrote:
> On Sat, 28 Nov 2026 23:15:10 +0100, David Hildenbrand (Arm) <david@xxxxxxxxxx> wrote:
>> Uprobe writes breakpoints and updates the reference counters of SDT
>> markers through GUP, which refuses VM_IO and VM_PFNMAP mappings, and which
>> cannot access the parts of VM_MIXEDMAP mappings that are not backed by
>> "struct page".
>>
>> However, valid_vma() and valid_ref_ctr_vma() never excluded such
>> mappings. For example, cramfs XIP file mappings use either
>> remap_pfn_range() or VM_MIXEDMAP mappings. For such file mappings,
>> enabling a uprobe fails with -EFAULT, and disabling a uprobe that was
>> enabled before such a mapping appeared fails with -EFAULT as well,
>> leaking the uprobe.
>>
>> Further, since commit 83e3dc9a5d4d ("uprobes: simplify
>> find_active_uprobe_rcu() VMA checks"), the uprobe lookups no longer check
>> the VMA flags, assuming that a trap instruction in a VMA implies that we
>> installed a breakpoint there. But we never install breakpoints into
>> some VMAs, such as MAP_SHARED mappings. If the file itself contains a
>> trap instruction at the offset of a uprobe, executing it in such a VMA
>> will find the uprobe, and instead of delivering SIGTRAP, we let the task
>> loop on that trap instruction forever.
>>
>> Let's fix it by only considering VMAs managed by core mm, using
>> vma_is_mm_managed().
>>
>> Move the existing VMA flag checks in valid_vma() into a new helper
>> valid_vma_flags(), and call vma_is_mm_managed() from there.
>>
>> Then, check valid_vma() also in find_active_uprobe_rcu(), and
>> valid_vma_flags() in find_active_uprobe_speculative(), essentially
>> reverting 83e3dc9a5d4d.
>>
>> In valid_ref_ctr_vma(), only call vma_is_mm_managed(): using
>> valid_vma_flags() would be wrong as we don't need exec permissions.
>>
>> vma_is_mm_managed() refuses VM_PFNMAP and VM_MIXEDMAP mappings, which
>> covers VM_IO mappings as well for anything we would probe. For example,
>> remap_pfn_range() sets VM_IO together with VM_PFNMAP.
>>
>> This has low urgency and is likely not stable-worthy.
>>
>> Fixes: 2b1444983508 ("uprobes, mm, x86: Add the ability to install and remove uprobes breakpoints")
>> Fixes: 83e3dc9a5d4d ("uprobes: simplify find_active_uprobe_rcu() VMA checks")
>> Cc: Andrii Nakryiko <andrii@xxxxxxxxxx>
>> Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
>> Reported-by: Chris Mason <mason@xxxxxxxxxx>
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>
> Looks good to me.
>
> Acked-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

Thanks, I'll queue this once I have some more review on #2.

--
Cheers,

David