* [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() [not found] <20260926124145.2878520-1-donggeunyoo.kernel@gmail.com> @ 2026-09-26 12:41 ` Donggeun Yoo 2026-09-27 20:54 ` Andrew Morton 2026-10-02 8:18 ` Mike Rapoport 0 siblings, 2 replies; 4+ messages in thread From: Donggeun Yoo @ 2026-09-26 12:41 UTC (permalink / raw) To: akpm, rppt Cc: peterx, surenb, aarcange, david, ljs, liam, vbabka, mhocko, shuah, kirill, linux-mm, linux-kselftest, linux-kernel, donggeunyoo.kernel, stable UFFDIO_MOVE on a swapped-out page installs the source PTE at the destination unchanged, so a uffd bit set on a write-protected or RWP-protected source lands in a destination VMA that was never registered for either. Nothing clears it there, and userspace sees: - /proc/<pid>/pagemap reports the page as uffd-tracked (bit 57), both while it is swapped out and after it is faulted back in. - MADV_COLLAPSE fails with EINVAL on a range containing it, because the collapse scan bails on a swap entry with the uffd bit set. - With CONFIG_PAGE_TABLE_CHECK, faulting the page in warns. do_swap_page() carries the bit into the present PTE and, since the destination isn't WP-registered, also makes it writable: WARNING: mm/page_table_check.c:202 at __page_table_check_ptes_set+0x185/0x1e0 Call Trace: set_ptes+0x67/0xc0 do_swap_page+0x990/0xfe0 __handle_mm_fault+0x7d0/0xeb0 handle_mm_fault+0x9c/0x250 do_user_addr_fault+0x207/0x650 exc_page_fault+0x65/0x150 asm_exc_page_fault+0x26/0x30 Reaching it takes UFFDIO_MOVE out of a WP- or RWP-protected area into one that isn't, on a page that is swapped out at the time. It hasn't been seen in practice. A resident page doesn't carry the bit, because move_present_ptes() builds the destination PTE from dst_vma->vm_page_prot. Clear it on the moved swap entry as well, then re-arm it if the destination is RWP-registered. The WP case has been there since v6.8, where UFFDIO_MOVE was added. Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") Cc: <stable@vger.kernel.org> Assisted-by: LLM Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com> --- mm/userfaultfd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 74f04c323c50f..f39f109f17989 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1449,6 +1449,7 @@ static int move_swap_pte(struct mm_struct *mm, struct vm_area_struct *dst_vma, orig_src_pte = ptep_get_and_clear(mm, src_addr, src_pte); if (pgtable_supports_soft_dirty()) orig_src_pte = pte_swp_mksoft_dirty(orig_src_pte); + orig_src_pte = pte_swp_clear_uffd(orig_src_pte); /* Re-arm RWP on the moved swap entry if dst_vma is RWP-registered. */ if (userfaultfd_rwp(dst_vma)) orig_src_pte = pte_swp_mkuffd(orig_src_pte); -- 2.53.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() 2026-09-26 12:41 ` [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() Donggeun Yoo @ 2026-09-27 20:54 ` Andrew Morton 2026-09-28 7:33 ` David Hildenbrand (Arm) 2026-10-02 8:18 ` Mike Rapoport 1 sibling, 1 reply; 4+ messages in thread From: Andrew Morton @ 2026-09-27 20:54 UTC (permalink / raw) To: Donggeun Yoo Cc: rppt, peterx, surenb, aarcange, david, ljs, liam, vbabka, mhocko, shuah, kirill, linux-mm, linux-kselftest, linux-kernel, stable On Sat, 26 Sep 2026 21:41:44 +0900 Donggeun Yoo <donggeunyoo.kernel@gmail.com> wrote: > UFFDIO_MOVE on a swapped-out page installs the source PTE at the > destination unchanged, so a uffd bit set on a write-protected or > RWP-protected source lands in a destination VMA that was never > registered for either. Nothing clears it there, and userspace sees: > > - /proc/<pid>/pagemap reports the page as uffd-tracked (bit 57), both > while it is swapped out and after it is faulted back in. > - MADV_COLLAPSE fails with EINVAL on a range containing it, because the > collapse scan bails on a swap entry with the uffd bit set. > - With CONFIG_PAGE_TABLE_CHECK, faulting the page in warns. > do_swap_page() carries the bit into the present PTE and, since the > destination isn't WP-registered, also makes it writable: > > WARNING: mm/page_table_check.c:202 at __page_table_check_ptes_set+0x185/0x1e0 > Call Trace: > set_ptes+0x67/0xc0 > do_swap_page+0x990/0xfe0 > __handle_mm_fault+0x7d0/0xeb0 > handle_mm_fault+0x9c/0x250 > do_user_addr_fault+0x207/0x650 > exc_page_fault+0x65/0x150 > asm_exc_page_fault+0x26/0x30 > > Reaching it takes UFFDIO_MOVE out of a WP- or RWP-protected area into > one that isn't, on a page that is swapped out at the time. It hasn't > been seen in practice. > > A resident page doesn't carry the bit, because move_present_ptes() builds > the destination PTE from dst_vma->vm_page_prot. Clear it on the moved > swap entry as well, then re-arm it if the destination is RWP-registered. > > The WP case has been there since v6.8, where UFFDIO_MOVE was added. Thanks. This is triggerable by unprivileged userspace, so can reviewers please prioritize. > Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") > Cc: <stable@vger.kernel.org> This should be whizzed into 7.3-rcX pretty promptly. It's not really appropriate to give the selftest such treatment - I'm never really sure how to handle that. I guess I'll keep things as you presented them - both for current -rc, [1/2] gets backported, [2/2] does not. > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -1449,6 +1449,7 @@ static int move_swap_pte(struct mm_struct *mm, struct vm_area_struct *dst_vma, > orig_src_pte = ptep_get_and_clear(mm, src_addr, src_pte); > if (pgtable_supports_soft_dirty()) > orig_src_pte = pte_swp_mksoft_dirty(orig_src_pte); > + orig_src_pte = pte_swp_clear_uffd(orig_src_pte); > /* Re-arm RWP on the moved swap entry if dst_vma is RWP-registered. */ > if (userfaultfd_rwp(dst_vma)) > orig_src_pte = pte_swp_mkuffd(orig_src_pte); > -- > 2.53.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() 2026-09-27 20:54 ` Andrew Morton @ 2026-09-28 7:33 ` David Hildenbrand (Arm) 0 siblings, 0 replies; 4+ messages in thread From: David Hildenbrand (Arm) @ 2026-09-28 7:33 UTC (permalink / raw) To: Andrew Morton, Donggeun Yoo Cc: rppt, peterx, surenb, aarcange, ljs, liam, vbabka, mhocko, shuah, kirill, linux-mm, linux-kselftest, linux-kernel, stable On 9/27/26 22:54, Andrew Morton wrote: > On Sat, 26 Sep 2026 21:41:44 +0900 Donggeun Yoo <donggeunyoo.kernel@gmail.com> wrote: > >> UFFDIO_MOVE on a swapped-out page installs the source PTE at the >> destination unchanged, so a uffd bit set on a write-protected or >> RWP-protected source lands in a destination VMA that was never >> registered for either. Nothing clears it there, and userspace sees: >> >> - /proc/<pid>/pagemap reports the page as uffd-tracked (bit 57), both >> while it is swapped out and after it is faulted back in. >> - MADV_COLLAPSE fails with EINVAL on a range containing it, because the >> collapse scan bails on a swap entry with the uffd bit set. >> - With CONFIG_PAGE_TABLE_CHECK, faulting the page in warns. >> do_swap_page() carries the bit into the present PTE and, since the >> destination isn't WP-registered, also makes it writable: >> >> WARNING: mm/page_table_check.c:202 at __page_table_check_ptes_set+0x185/0x1e0 >> Call Trace: >> set_ptes+0x67/0xc0 >> do_swap_page+0x990/0xfe0 >> __handle_mm_fault+0x7d0/0xeb0 >> handle_mm_fault+0x9c/0x250 >> do_user_addr_fault+0x207/0x650 >> exc_page_fault+0x65/0x150 >> asm_exc_page_fault+0x26/0x30 >> >> Reaching it takes UFFDIO_MOVE out of a WP- or RWP-protected area into >> one that isn't, on a page that is swapped out at the time. It hasn't >> been seen in practice. >> >> A resident page doesn't carry the bit, because move_present_ptes() builds >> the destination PTE from dst_vma->vm_page_prot. Clear it on the moved >> swap entry as well, then re-arm it if the destination is RWP-registered. >> >> The WP case has been there since v6.8, where UFFDIO_MOVE was added. > > Thanks. This is triggerable by unprivileged userspace, so can > reviewers please prioritize. I assume most production kernels don't have CONFIG_PAGE_TABLE_CHECK enabled in the config. And if enabled, not active at runtime. I'd assume mostly only debug kernels have that config ever enabled. So it might be less problematic than it seems at first. (at least the WARNING bit) > >> Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") >> Cc: <stable@vger.kernel.org> > > This should be whizzed into 7.3-rcX pretty promptly. > > It's not really appropriate to give the selftest such treatment - I'm > never really sure how to handle that. I guess I'll keep things as you > presented them - both for current -rc, [1/2] gets backported, [2/2] > does not. Make sense. > >> --- a/mm/userfaultfd.c >> +++ b/mm/userfaultfd.c >> @@ -1449,6 +1449,7 @@ static int move_swap_pte(struct mm_struct *mm, struct vm_area_struct *dst_vma, >> orig_src_pte = ptep_get_and_clear(mm, src_addr, src_pte); >> if (pgtable_supports_soft_dirty()) >> orig_src_pte = pte_swp_mksoft_dirty(orig_src_pte); >> + orig_src_pte = pte_swp_clear_uffd(orig_src_pte); >> /* Re-arm RWP on the moved swap entry if dst_vma is RWP-registered. */ >> if (userfaultfd_rwp(dst_vma)) >> orig_src_pte = pte_swp_mkuffd(orig_src_pte); >> -- >> 2.53.0 Acked-by: David Hildenbrand (Arm) <david@kernel.org> -- Cheers, David ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() 2026-09-26 12:41 ` [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() Donggeun Yoo 2026-09-27 20:54 ` Andrew Morton @ 2026-10-02 8:18 ` Mike Rapoport 1 sibling, 0 replies; 4+ messages in thread From: Mike Rapoport @ 2026-10-02 8:18 UTC (permalink / raw) To: Donggeun Yoo Cc: akpm, peterx, surenb, aarcange, david, ljs, liam, vbabka, mhocko, shuah, kirill, linux-mm, linux-kselftest, linux-kernel, stable On Sat, Sep 26, 2026 at 09:41:44PM +0900, Donggeun Yoo wrote: > UFFDIO_MOVE on a swapped-out page installs the source PTE at the > destination unchanged, so a uffd bit set on a write-protected or > RWP-protected source lands in a destination VMA that was never > registered for either. Nothing clears it there, and userspace sees: > > - /proc/<pid>/pagemap reports the page as uffd-tracked (bit 57), both > while it is swapped out and after it is faulted back in. > - MADV_COLLAPSE fails with EINVAL on a range containing it, because the > collapse scan bails on a swap entry with the uffd bit set. > - With CONFIG_PAGE_TABLE_CHECK, faulting the page in warns. > do_swap_page() carries the bit into the present PTE and, since the > destination isn't WP-registered, also makes it writable: > > WARNING: mm/page_table_check.c:202 at __page_table_check_ptes_set+0x185/0x1e0 > Call Trace: > set_ptes+0x67/0xc0 > do_swap_page+0x990/0xfe0 > __handle_mm_fault+0x7d0/0xeb0 > handle_mm_fault+0x9c/0x250 > do_user_addr_fault+0x207/0x650 > exc_page_fault+0x65/0x150 > asm_exc_page_fault+0x26/0x30 > > Reaching it takes UFFDIO_MOVE out of a WP- or RWP-protected area into > one that isn't, on a page that is swapped out at the time. It hasn't > been seen in practice. > > A resident page doesn't carry the bit, because move_present_ptes() builds > the destination PTE from dst_vma->vm_page_prot. Clear it on the moved > swap entry as well, then re-arm it if the destination is RWP-registered. > > The WP case has been there since v6.8, where UFFDIO_MOVE was added. > > Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") > Cc: <stable@vger.kernel.org> > Assisted-by: LLM > Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org> > --- > mm/userfaultfd.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 74f04c323c50f..f39f109f17989 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -1449,6 +1449,7 @@ static int move_swap_pte(struct mm_struct *mm, struct vm_area_struct *dst_vma, > orig_src_pte = ptep_get_and_clear(mm, src_addr, src_pte); > if (pgtable_supports_soft_dirty()) > orig_src_pte = pte_swp_mksoft_dirty(orig_src_pte); > + orig_src_pte = pte_swp_clear_uffd(orig_src_pte); > /* Re-arm RWP on the moved swap entry if dst_vma is RWP-registered. */ > if (userfaultfd_rwp(dst_vma)) > orig_src_pte = pte_swp_mkuffd(orig_src_pte); > -- > 2.53.0 > -- Sincerely yours, Mike. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-02 8:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260926124145.2878520-1-donggeunyoo.kernel@gmail.com>
2026-09-26 12:41 ` [PATCH v3 1/2] userfaultfd: clear the inherited uffd bit in move_swap_pte() Donggeun Yoo
2026-09-27 20:54 ` Andrew Morton
2026-09-28 7:33 ` David Hildenbrand (Arm)
2026-10-02 8:18 ` Mike Rapoport
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox