[PATCH v3 1/2] ARM: mm: fix use-after-free in __do_user_fault() under CONFIG_DEBUG_USER
Xie Yuanbin
xieyuanbin1 at huawei.com
Tue Jul 7 06:35:27 PDT 2026
On Tue, 7 Jul 2026 13:46:19 +0100, Lorenzo Stoakes wrote:
> On Mon, Jul 06, 2026 at 09:32:47PM +0800, Xie Yuanbin wrote:
>> I have read this article:
>> Link: https://docs.kernel.org/mm/process_addrs.html
>> `mmap_read_lock(&init_mm)` should be able to ensure that the kernel
>> address's page tables can be traversed. But I'm not quite sure if
>
> I added a section specifically about this -
>
> https://docs.kernel.org/mm/process_addrs.html#traversing-non-vma-page-tables
>
> But note:
>
> "Since, aside from vmalloc and memory hot plug, kernel page tables are not torn
> down all that often - this usually suffices, however any caller of this
> functionality must ensure that any additionally required locks are acquired in
> advance."
>
> With the latter part being particularly important - you really need to be sure
> you aren't going to be raced on page table teardown by anything.
>
> However:
>
> * You're safe from vmalloc trying to install a huge page table (only way
> it removes intermediate page tables) since !HAVE_ARCH_HUGE_VMAP.
>
> * And since arm32 !ARCH_ENABLE_MEMORY_HOTPLUG you're safe from that too
> :)
>
> (Really I think you should be using walk_page_range_debug() here ultimately but
> that's a future refactor).
>
> BUT see below:
>
>> `mmap_read_lock(¤t->mm)` provides protection for user-space non-VMA
>> addresses?
>
> OK so this _does_ need addressing, and I covered it in the document:
>
> We also permit a truly unusual case is the traversal of non-VMA ranges
> in userland ranges, as provided for by walk_page_range_debug().
>
> We must take great care in this case, as the munmap() implementation
> detaches VMAs under an mmap write lock before tearing down page tables
> under a downgraded mmap read lock.
>
> This means such an operation could race with this, and thus an mmap
> write lock is required.
>
> I.e. you need a write lock.
Thank you very much for your reply. Now I fully understand: to traverse
the page tables of non-VMA addr in user address space, the mmap write
lock is required.
But I still want like to ask a question:
> However:
>
> * You're safe from vmalloc trying to install a huge page table (only way
> it removes intermediate page tables) since !HAVE_ARCH_HUGE_VMAP.
>
> * And since arm32 !ARCH_ENABLE_MEMORY_HOTPLUG you're safe from that too
> :)
If (just hypothetically), the ARM32 architecture supports huge pages
and memory hotplug, what kind of lock do I need to safely traverse the
page tables of non-VMA addr in kernel space?
Thanks again.
More information about the linux-arm-kernel
mailing list