userfaultfd: fix a crash in UFFDIO_MOVE when PMD is a migration entry
Subsystems (3)
PATCH v4 1/1 userfaultfd: fix a crash in UFFDIO_MOVE when PMD is a migration entry
When UFFDIO_MOVE encounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry is swp_entry_t. Add the missing check and let split_huge_pmd() handle migration entries.
---
Changes since v3 [1]
- Updated the title and changelog, per Peter Xu
- Added Reviewed-by: per Peter Xu
[1] https://lore.kernel.org/all/[email protected]/
mm/userfaultfd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
mm/userfaultfd.c +10 -7
@@ -1826,13 +1826,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,/* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd (dst_addr, src_addr, src_start + len) || !pmd_none (dst_pmdval)) { -struct folio *folio =pmd_folio (*src_pmd); - -if (!folio || (!is_huge_zero_folio (folio) && - !PageAnonExclusive (&folio->page))) { -spin_unlock (ptl); - err = -EBUSY ; -break ; +/* Can be a migration entry */ +if (pmd_present (*src_pmd)) { +struct folio *folio =pmd_folio (*src_pmd); + +if (!folio || (!is_huge_zero_folio (folio) && + !PageAnonExclusive (&folio->page))) { +spin_unlock (ptl); + err = -EBUSY ; +break ; + } }spin_unlock (ptl);
base-commit: 8e7e0c6d09502e44aa7a8fce0821e042a6ec03d1
Signature · 1 line
2.50.1.565.gc32cd1483b-goog
Quoted 30 lines · Suren Baghdasaryan
When
UFFDIO_MOVEencounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry isswp_entry_t. Add the missing check and letsplit_huge_pmd()handle migration entries.Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Reported-by [email protected]Signed-off-by Suren Baghdasaryan <[email protected]>Reviewed-by Peter Xu <[email protected]>---
Changes since v3 [1]
- Updated the title and changelog, per Peter Xu
- Added Reviewed-by: per Peter Xu[1] https://lore.kernel.org/all/[email protected]/
mm/userfaultfd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)mm/userfaultfd.c +0
-2@@ -1826,13 +1826,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,/* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd (dst_addr, src_addr, src_start + len) || !pmd_none (dst_pmdval)) { -struct folio *folio =pmd_folio (*src_pmd); -
mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start, · line 1833
Quoted 10 lines
mm/userfaultfd.c +5
-5-if (!folio || (!is_huge_zero_folio (folio) && - !PageAnonExclusive (&folio->page))) { -spin_unlock (ptl); - err = -EBUSY ; -break ; +/* Can be a migration entry */ +if (pmd_present (*src_pmd)) { +struct folio *folio =pmd_folio (*src_pmd); + + if (!folio
How could you get !folio here? That only makes sense when calling vm_normal_folio_pmd(), no?
Signature · 3 lines
Cheers, David / dhildenb
Quoted 38 lines · David Hildenbrand
Quoted 36 lines · Suren Baghdasaryan
When
UFFDIO_MOVEencounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry isswp_entry_t. Add the missing check and letsplit_huge_pmd()handle migration entries.Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Reported-by [email protected]Signed-off-by Suren Baghdasaryan <[email protected]>Reviewed-by Peter Xu <[email protected]>---
Changes since v3 [1]
- Updated the title and changelog, per Peter Xu
- Added Reviewed-by: per Peter Xu[1] https://lore.kernel.org/all/[email protected]/
mm/userfaultfd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)mm/userfaultfd.c +1
-7@@ -1826,13 +1826,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,/* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd (dst_addr, src_addr, src_start + len) || !pmd_none (dst_pmdval)) { -struct folio *folio =pmd_folio (*src_pmd); - -if (!folio || (!is_huge_zero_folio (folio) && - !PageAnonExclusive (&folio->page))) { -spin_unlock (ptl); - err = -EBUSY ; -break ; +/* Can be a migration entry */
Quoted 8 lines
mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
Quoted 4 lines
mm/userfaultfd.c +4
-0+if (pmd_present (*src_pmd)) { +struct folio *folio =pmd_folio (*src_pmd); + + if (!folioHow could you get !folio here? That only makes sense when calling
vm_normal_folio_pmd(), no?
Yes, I think you are right, this check is not needed. I can fold it into this fix or post a separate cleanup patch. I'm guessing a separate patch would be better?
Quoted 7 lines
--
Cheers,David / dhildenb
Quoted 48 lines · Suren Baghdasaryan
Quoted 38 lines · David Hildenbrand
Quoted 36 lines · Suren Baghdasaryan
When
UFFDIO_MOVEencounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry isswp_entry_t. Add the missing check and letsplit_huge_pmd()handle migration entries.Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Reported-by [email protected]Signed-off-by Suren Baghdasaryan <[email protected]>Reviewed-by Peter Xu <[email protected]>---
Changes since v3 [1]
- Updated the title and changelog, per Peter Xu
- Added Reviewed-by: per Peter Xu[1] https://lore.kernel.org/all/[email protected]/
mm/userfaultfd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)mm/userfaultfd.c +1
-7@@ -1826,13 +1826,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,/* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd (dst_addr, src_addr, src_start + len) || !pmd_none (dst_pmdval)) { -struct folio *folio =pmd_folio (*src_pmd); - -if (!folio || (!is_huge_zero_folio (folio) && - !PageAnonExclusive (&folio->page))) { -spin_unlock (ptl); - err = -EBUSY ; -break ; +/* Can be a migration entry */ Quoted 8 lines
mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
Quoted 4 lines
mm/userfaultfd.c +4
-0+if (pmd_present (*src_pmd)) { +struct folio *folio =pmd_folio (*src_pmd); + + if (!folioHow could you get !folio here? That only makes sense when calling
vm_normal_folio_pmd(), no?
Quoted 3 lines
Yes, I think you are right, this check is not needed. I can fold it into this fix or post a separate cleanup patch. I'm guessing a separate patch would be better?
I think you can just post a fixup inline here and ask Andrew to squash it. He will shout if he wants a completely new version :)
Signature · 3 lines
Cheers, David / dhildenb
Quoted 50 lines · David Hildenbrand
Quoted 48 lines · Suren Baghdasaryan
Quoted 46 lines · David Hildenbrand
Quoted 30 lines · Suren Baghdasaryan
When
UFFDIO_MOVEencounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry isswp_entry_t. Add the missing check and letsplit_huge_pmd()handle migration entries.Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Reported-by [email protected]Signed-off-by Suren Baghdasaryan <[email protected]>Reviewed-by Peter Xu <[email protected]>---
Changes since v3 [1]
- Updated the title and changelog, per Peter Xu
- Added Reviewed-by: per Peter Xu[1] https://lore.kernel.org/all/[email protected]/
mm/userfaultfd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)mm/userfaultfd.c +0
-2@@ -1826,13 +1826,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,/* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd (dst_addr, src_addr, src_start + len) || !pmd_none (dst_pmdval)) { -struct folio *folio =pmd_folio (*src_pmd); -mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start, · line 1833
Quoted 10 lines
mm/userfaultfd.c +5
-5-if (!folio || (!is_huge_zero_folio (folio) && - !PageAnonExclusive (&folio->page))) { -spin_unlock (ptl); - err = -EBUSY ; -break ; +/* Can be a migration entry */ +if (pmd_present (*src_pmd)) { +struct folio *folio =pmd_folio (*src_pmd); + + if (!folioHow could you get !folio here? That only makes sense when calling
vm_normal_folio_pmd(), no?
Quoted 6 lines
Quoted 3 lines
Yes, I think you are right, this check is not needed. I can fold it into this fix or post a separate cleanup patch. I'm guessing a separate patch would be better?
I think you can just post a fixup inline here and ask Andrew to squash it. He will shout if he wants a completely new version :)
I wouldn't do that to him! :)
Let me quickly send an updated version instead.
Quoted 6 lines
--
Cheers,David / dhildenb
Quoted 56 lines · Suren Baghdasaryan
Quoted 54 lines · David Hildenbrand
Quoted 51 lines · Suren Baghdasaryan
Quoted 38 lines · David Hildenbrand
Quoted 36 lines · Suren Baghdasaryan
When
UFFDIO_MOVEencounters a migration PMD entry, it proceeds with obtaining a folio and accessing it even though the entry isswp_entry_t. Add the missing check and letsplit_huge_pmd()handle migration entries.Fixes adef440691ba ("userfaultfd: UFFDIO_MOVE uABI")Reported-by [email protected]Signed-off-by Suren Baghdasaryan <[email protected]>Reviewed-by Peter Xu <[email protected]>---
Changes since v3 [1]
- Updated the title and changelog, per Peter Xu
- Added Reviewed-by: per Peter Xu[1] https://lore.kernel.org/all/[email protected]/
mm/userfaultfd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)mm/userfaultfd.c +1
-7@@ -1826,13 +1826,16 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,/* Check if we can move the pmd without splitting it. */ if (move_splits_huge_pmd (dst_addr, src_addr, src_start + len) || !pmd_none (dst_pmdval)) { -struct folio *folio =pmd_folio (*src_pmd); - -if (!folio || (!is_huge_zero_folio (folio) && - !PageAnonExclusive (&folio->page))) { -spin_unlock (ptl); - err = -EBUSY ; -break ; +/* Can be a migration entry */ Quoted 8 lines
mm/userfaultfd.c ssize_t move_pages(struct userfaultfd_ctx *ctx, unsigned long dst_start,
Quoted 4 lines
mm/userfaultfd.c +4
-0+if (pmd_present (*src_pmd)) { +struct folio *folio =pmd_folio (*src_pmd); + + if (!folioHow could you get !folio here? That only makes sense when calling
vm_normal_folio_pmd(), no?Yes, I think you are right, this check is not needed. I can fold it into this fix or post a separate cleanup patch. I'm guessing a separate patch would be better?
Quoted 5 lines
Quoted 2 lines
I think you can just post a fixup inline here and ask Andrew to squash it. He will shout if he wants a completely new version :)
I wouldn't do that to him! :)
Let me quickly send an updated version instead.
Update posted at
https://lore.kernel.org/all/[email protected]/
Quoted 7 lines
Quoted 7 lines
--
Cheers,David / dhildenb