From: Lorenzo Stoakes <ljs@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linuxfoundation.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
David Hildenbrand <david@kernel.org>, Jan Kara <jack@suse.cz>,
Oleg Nesterov <oleg@redhat.com>, Peter Xu <peterx@redhat.com>,
vova tokarev <vladimirelitokarev@gmail.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] userfaultfd: prevent registration of special VMAs
Date: Fri, 3 Jul 2026 14:54:41 +0100 [thread overview]
Message-ID: <ake8LUosdwCdleHe@lucifer> (raw)
In-Reply-To: <20260618095017.2553004-1-rppt@kernel.org>
On Thu, Jun 18, 2026 at 12:50:17PM +0300, 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>
LGTM, so:
Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>
I'm working on a series to take care of the issues discussed at [0].
[0]:https://lore.kernel.org/all/20260618183442.BBCD71F000E9@smtp.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
>
>
Cheers, Lorenzo
prev parent reply other threads:[~2026-07-03 13:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 9:50 [PATCH v2] userfaultfd: prevent registration of special VMAs Mike Rapoport
2026-06-18 11:06 ` David Hildenbrand (Arm)
2026-07-03 13:54 ` Lorenzo Stoakes [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ake8LUosdwCdleHe@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=david@kernel.org \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=oleg@redhat.com \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linuxfoundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=vladimirelitokarev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.