]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
userfaultfd: refuse to __mfill_atomic_pte() for unsupported VMAs
authorMike Rapoport (Microsoft) <rppt@kernel.org>
Wed, 27 May 2026 18:47:50 +0000 (21:47 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 1 Jun 2026 04:50:25 +0000 (21:50 -0700)
__mfill_atomic_pte() unconditionally dereferences ops because there is an
assumption that VMAs that can undergo mfill_* operations are vetted on
registration and must have valid vm_uffd_ops.

Add a guard against potential bugs and make sure __mfill_atomic_pte()
bails out if ops is NULL.

Link: https://lore.kernel.org/20260527184751.4147364-3-rppt@kernel.org
Fixes: ad9ac3081332 ("userfaultfd: introduce vm_uffd_ops->alloc_folio()")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Suggested-by: Lorenzo Stoakes <ljs@kernel.org>
Reviewed-by: Lorenzo Stoakes <ljs@kernel.org>
Reviewed-by: David CARLIER <devnexen@gmail.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Michael Bommarito <michael.bommarito@gmail.com>
Cc: Peter Xu <peterx@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/userfaultfd.c

index e5d2fb3ce2c1aa07ee7da3b1030ca45a0666f8c5..2872c71bbf369f1cce763e0fbf0e1d4cd1b8275d 100644 (file)
@@ -552,6 +552,11 @@ static int __mfill_atomic_pte(struct mfill_state *state,
        struct folio *folio;
        int ret;
 
+       if (!ops) {
+               VM_WARN_ONCE(1, "UFFDIO_COPY for unsupported VMA");
+               return -EOPNOTSUPP;
+       }
+
        folio = ops->alloc_folio(state->vma, state->dst_addr);
        if (!folio)
                return -ENOMEM;