vma_can_userfault() masks off non-userfaultfd VM flags from vm_flags.
The vm_flags & VM_DROPPABLE test will then always be false, incorrectly
allowing VM_DROPPABLE regions to be registered with userfaultfd.
Additionally, vm_flags is not guaranteed to correspond to the actual
VMA's flags. Fix this test by checking the VMA's flags directly.
Link: https://lore.kernel.org/linux-mm/5a875a3a-2243-4eab-856f-bc53ccfec3ea@redhat.com/
Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
---
include/linux/userfaultfd_k.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
index 75342022d144..f3b3d2c9dd5e 100644
--- a/include/linux/userfaultfd_k.h
+++ b/include/linux/userfaultfd_k.h
@@ -218,7 +218,7 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma,
{
vm_flags &= __VM_UFFD_FLAGS;
- if (vm_flags & VM_DROPPABLE)
+ if (vma->vm_flags & VM_DROPPABLE)
return false;
if ((vm_flags & VM_UFFD_MINOR) &&
--
2.39.5
On Sat, 07 Jun 2025 02:40:00 -0400 Tal Zussman <tz2294@columbia.edu> wrote: > vma_can_userfault() masks off non-userfaultfd VM flags from vm_flags. > The vm_flags & VM_DROPPABLE test will then always be false, incorrectly > allowing VM_DROPPABLE regions to be registered with userfaultfd. > > Additionally, vm_flags is not guaranteed to correspond to the actual > VMA's flags. Fix this test by checking the VMA's flags directly. Wondering if we should backport this. afaict we don't know the userspace impact of this because nobody has tried it!
On Sat, Jun 07, 2025 at 03:04:38PM -0700, Andrew Morton wrote: > On Sat, 07 Jun 2025 02:40:00 -0400 Tal Zussman <tz2294@columbia.edu> wrote: > > > vma_can_userfault() masks off non-userfaultfd VM flags from vm_flags. > > The vm_flags & VM_DROPPABLE test will then always be false, incorrectly > > allowing VM_DROPPABLE regions to be registered with userfaultfd. > > > > Additionally, vm_flags is not guaranteed to correspond to the actual > > VMA's flags. Fix this test by checking the VMA's flags directly. > > Wondering if we should backport this. afaict we don't know the > userspace impact of this because nobody has tried it! Yes that's fair question. Per my limited understanding of MAP_DROPPABLE (even if as a generic flag), I'd be surprised if someone tries to enable userfaultfd on it, being succeeded or not.. or requiring that to properly fail on any stable branches. AFAIU that's the only possible effect we can expect from a backport. IMHO for this case we can avoid backporting until anyone requested with an explicit use case. Thanks, -- Peter Xu
On Sat, Jun 07, 2025 at 02:40:00AM -0400, Tal Zussman wrote:
> vma_can_userfault() masks off non-userfaultfd VM flags from vm_flags.
> The vm_flags & VM_DROPPABLE test will then always be false, incorrectly
> allowing VM_DROPPABLE regions to be registered with userfaultfd.
>
> Additionally, vm_flags is not guaranteed to correspond to the actual
> VMA's flags. Fix this test by checking the VMA's flags directly.
>
> Link: https://lore.kernel.org/linux-mm/5a875a3a-2243-4eab-856f-bc53ccfec3ea@redhat.com/
> Fixes: 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings")
> Acked-by: David Hildenbrand <david@redhat.com>
> Acked-by: Peter Xu <peterx@redhat.com>
> Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Nice catch and thanks for fixing this.
Acked-by: Jason A. Donenfeld <Jason@zx2c4.com>
© 2016 - 2025 Red Hat, Inc.