userfaultfd: avoid huge_zero_page in UFFDIO_MOVE
Subsystems (2)
PATCH 1/1 userfaultfd: avoid huge_zero_page in UFFDIO_MOVE
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.
---
Applies cleanly over linux-next, mm-stable and mm-unstable branches
mm/userfaultfd.c | 6 ++++++ 1 file changed, 6 insertions(+)
mm/userfaultfd.c +6 -0
@@ -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) ||
Signature · 1 line
2.43.0.275.g3460e3d667-goog
Quoted 20 lines · Suren Baghdasaryan
While testing
UFFDIO_MOVEioctl, syzbot triggeredVM_BUG_ON_PAGEcaused by a call toPageAnonExclusive()with ahuge_zero_pageas a parameter.UFFDIO_MOVEdoes not yet handle zeropages and returns EBUSY when one is encountered. Add an earlyhuge_zero_pagecheck in the PMD move path to avoid this situation.Reported-by [email protected]Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Signed-off-by Suren Baghdasaryan <[email protected]>---
Applies cleanly over linux-next, mm-stable and mm-unstable branchesmm/userfaultfd.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/userfaultfd.c +0
-0
mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm, · line 1401
Quoted 9 lines
mm/userfaultfd.c +6
-0@@ -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.
Signature · 3 lines
Cheers, David / dhildenb
Quoted 26 lines · David Hildenbrand
Quoted 24 lines · Suren Baghdasaryan
While testing
UFFDIO_MOVEioctl, syzbot triggeredVM_BUG_ON_PAGEcaused by a call toPageAnonExclusive()with ahuge_zero_pageas a parameter.UFFDIO_MOVEdoes not yet handle zeropages and returns EBUSY when one is encountered. Add an earlyhuge_zero_pagecheck in the PMD move path to avoid this situation.Reported-by [email protected]Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Signed-off-by Suren Baghdasaryan <[email protected]>---
Applies cleanly over linux-next, mm-stable and mm-unstable branchesmm/userfaultfd.c | 6 ++++++ 1 file changed, 6 insertions(+)mm/userfaultfd.c +1
-0@@ -1393,6 +1393,12 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm, err = -ENOENT ;break ; } +/* Avoid moving zeropages for now */
Quoted 8 lines
mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, struct mm_struct *mm, · line 1401
Quoted 5 lines
mm/userfaultfd.c +5
-0+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.
Quoted 4 lines
Anyhow, this should handle the issue at hand.
Thanks!
Quoted 6 lines
--
Cheers,David / dhildenb