All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] userfaultfd: avoid huge_zero_page in UFFDIO_MOVE
@ 2024-01-12  1:39 Suren Baghdasaryan
  2024-01-12  8:57 ` David Hildenbrand
  0 siblings, 1 reply; 3+ messages in thread
From: Suren Baghdasaryan @ 2024-01-12  1:39 UTC (permalink / raw)
  To: akpm
  Cc: sfr, david, peterx, aarcange, linux-kernel, linux-mm,
	Suren Baghdasaryan, syzbot+705209281e36404998f6

While testing UFFDIO_MOVE ioctl, syzbot triggered VM_BUG_ON_PAGE caused
by a call to PageAnonExclusive() with a huge_zero_page as a parameter.
UFFDIO_MOVE does not yet handle zeropages and returns EBUSY when one is
encountered. Add an early huge_zero_page check in the PMD move path
to avoid this situation.

Reported-by: syzbot+705209281e36404998f6@syzkaller.appspotmail.com
Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
Applies cleanly over linux-next, mm-stable and mm-unstable branches

 mm/userfaultfd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
index 216ab4c8621f..20e3b0d9cf7e 100644
--- a/mm/userfaultfd.c
+++ b/mm/userfaultfd.c
@@ -1393,6 +1393,12 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm,
 				err = -ENOENT;
 				break;
 			}
+			/* Avoid moving zeropages for now */
+			if (is_huge_zero_pmd(*src_pmd)) {
+				spin_unlock(ptl);
+				err = -EBUSY;
+				break;
+			}
 
 			/* Check if we can move the pmd without splitting it. */
 			if (move_splits_huge_pmd(dst_addr, src_addr, src_start + len) ||
-- 
2.43.0.275.g3460e3d667-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] userfaultfd: avoid huge_zero_page in UFFDIO_MOVE
  2024-01-12  1:39 [PATCH 1/1] userfaultfd: avoid huge_zero_page in UFFDIO_MOVE Suren Baghdasaryan
@ 2024-01-12  8:57 ` David Hildenbrand
  2024-01-12 17:31   ` Suren Baghdasaryan
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2024-01-12  8:57 UTC (permalink / raw)
  To: Suren Baghdasaryan, akpm
  Cc: sfr, peterx, aarcange, linux-kernel, linux-mm,
	syzbot+705209281e36404998f6

On 12.01.24 02:39, Suren Baghdasaryan wrote:
> While testing UFFDIO_MOVE ioctl, syzbot triggered VM_BUG_ON_PAGE caused
> by a call to PageAnonExclusive() with a huge_zero_page as a parameter.
> UFFDIO_MOVE does not yet handle zeropages and returns EBUSY when one is
> encountered. Add an early huge_zero_page check in the PMD move path
> to avoid this situation.
> 
> Reported-by: syzbot+705209281e36404998f6@syzkaller.appspotmail.com
> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> ---
> Applies cleanly over linux-next, mm-stable and mm-unstable branches
> 
>   mm/userfaultfd.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index 216ab4c8621f..20e3b0d9cf7e 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -1393,6 +1393,12 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm,
>   				err = -ENOENT;
>   				break;
>   			}
> +			/* Avoid moving zeropages for now */
> +			if (is_huge_zero_pmd(*src_pmd)) {
> +				spin_unlock(ptl);
> +				err = -EBUSY;
> +				break;
> +			}

As an alternative (and more future proof?) just reject anything that is 
not an anon folio as well?

Anyhow, this should handle the issue at hand.

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] userfaultfd: avoid huge_zero_page in UFFDIO_MOVE
  2024-01-12  8:57 ` David Hildenbrand
@ 2024-01-12 17:31   ` Suren Baghdasaryan
  0 siblings, 0 replies; 3+ messages in thread
From: Suren Baghdasaryan @ 2024-01-12 17:31 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: akpm, sfr, peterx, aarcange, linux-kernel, linux-mm,
	syzbot+705209281e36404998f6

On Fri, Jan 12, 2024 at 12:57 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 12.01.24 02:39, Suren Baghdasaryan wrote:
> > While testing UFFDIO_MOVE ioctl, syzbot triggered VM_BUG_ON_PAGE caused
> > by a call to PageAnonExclusive() with a huge_zero_page as a parameter.
> > UFFDIO_MOVE does not yet handle zeropages and returns EBUSY when one is
> > encountered. Add an early huge_zero_page check in the PMD move path
> > to avoid this situation.
> >
> > Reported-by: syzbot+705209281e36404998f6@syzkaller.appspotmail.com
> > Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > ---
> > Applies cleanly over linux-next, mm-stable and mm-unstable branches
> >
> >   mm/userfaultfd.c | 6 ++++++
> >   1 file changed, 6 insertions(+)
> >
> > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> > index 216ab4c8621f..20e3b0d9cf7e 100644
> > --- a/mm/userfaultfd.c
> > +++ b/mm/userfaultfd.c
> > @@ -1393,6 +1393,12 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm,
> >                               err = -ENOENT;
> >                               break;
> >                       }
> > +                     /* Avoid moving zeropages for now */
> > +                     if (is_huge_zero_pmd(*src_pmd)) {
> > +                             spin_unlock(ptl);
> > +                             err = -EBUSY;
> > +                             break;
> > +                     }
>
> As an alternative (and more future proof?) just reject anything that is
> not an anon folio as well?

Yes, but I'm going to remove this check shortly, once zeropage
movement patch is ready.

>
> Anyhow, this should handle the issue at hand.
>
> Acked-by: David Hildenbrand <david@redhat.com>

Thanks!

>
> --
> Cheers,
>
> David / dhildenb
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-12 17:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-12  1:39 [PATCH 1/1] userfaultfd: avoid huge_zero_page in UFFDIO_MOVE Suren Baghdasaryan
2024-01-12  8:57 ` David Hildenbrand
2024-01-12 17:31   ` Suren Baghdasaryan

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.