* [PATCH v2] userfaultfd: prevent registration of special VMAs
@ 2026-06-18 9:50 Mike Rapoport
2026-06-18 11:06 ` David Hildenbrand (Arm)
0 siblings, 1 reply; 2+ messages in thread
From: Mike Rapoport @ 2026-06-18 9:50 UTC (permalink / raw)
To: Andrew Morton, Linus Torvalds
Cc: Alexander Viro, Christian Brauner, David Hildenbrand, Jan Kara,
Mike Rapoport, Oleg Nesterov, Peter Xu, vova tokarev,
linux-kernel, linux-mm, stable
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Vova Tokarev says:
userfaultfd allows registration on shadow stack VMAs. With userfaultfd
access, you can register on the shadow stack, discard a page ... and
inject a page with chosen return addresses via UFFDIO_COPY.
Update vma_can_userfault() to reject VM_SHADOW_STACK.
While on it, also reject VM_SPECIAL so that if a driver would implement
vm_uffd_ops, it wouldn't be possible to register special VMAs with
userfaultfd.
Since VM_SPECIAL includes VM_DONTEXPAND which is set but hugetlb,
exclude hugetlb VMAs from the check for VM_SPECIAL.
Reported-by: vova tokarev <vladimirelitokarev@gmail.com>
Fixes: 54007f818206 ("mm: Introduce VM_SHADOW_STACK for shadow stack memory")
Cc: <stable@vger.kernel.org>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
v2 changes:
* reject all VM_SPECIAL except hugetlb
v1: https://lore.kernel.org/all/20260617194059.2529406-1-rppt@kernel.org
mm/userfaultfd.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 246af12bf801..c3adedaaf7d5 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -2111,7 +2111,10 @@ static bool vma_can_userfault(struct vm_area_struct *vma, vm_flags_t vm_flags,
{
const struct vm_uffd_ops *ops = vma_uffd_ops(vma);
- if (vma->vm_flags & VM_DROPPABLE)
+ if (vma->vm_flags & (VM_DROPPABLE | VM_SHADOW_STACK))
+ return false;
+
+ if (!is_vm_hugetlb_page(vma) && (vma->vm_flags & VM_SPECIAL))
return false;
vm_flags &= __VM_UFFD_FLAGS;
base-commit: e3d8707358ea76b78bdec9928937bb9a797f2c8f
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] userfaultfd: prevent registration of special VMAs
2026-06-18 9:50 [PATCH v2] userfaultfd: prevent registration of special VMAs Mike Rapoport
@ 2026-06-18 11:06 ` David Hildenbrand (Arm)
0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand (Arm) @ 2026-06-18 11:06 UTC (permalink / raw)
To: Mike Rapoport, Andrew Morton, Linus Torvalds
Cc: Alexander Viro, Christian Brauner, Jan Kara, Oleg Nesterov,
Peter Xu, vova tokarev, linux-kernel, linux-mm, stable
On 6/18/26 11:50, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> Vova Tokarev says:
>
> userfaultfd allows registration on shadow stack VMAs. With userfaultfd
> access, you can register on the shadow stack, discard a page ... and
> inject a page with chosen return addresses via UFFDIO_COPY.
>
> Update vma_can_userfault() to reject VM_SHADOW_STACK.
>
> While on it, also reject VM_SPECIAL so that if a driver would implement
> vm_uffd_ops, it wouldn't be possible to register special VMAs with
> userfaultfd.
>
> Since VM_SPECIAL includes VM_DONTEXPAND which is set but hugetlb,
> exclude hugetlb VMAs from the check for VM_SPECIAL.
>
> Reported-by: vova tokarev <vladimirelitokarev@gmail.com>
> Fixes: 54007f818206 ("mm: Introduce VM_SHADOW_STACK for shadow stack memory")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
Thanks Mike
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
--
Cheers,
David
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-18 12:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-18 9:50 [PATCH v2] userfaultfd: prevent registration of special VMAs Mike Rapoport
2026-06-18 11:06 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox