From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796391922; b=2FQ22WewTU0dctsKU0SjGjKwsZUtvqFYwEJiacHoMYwniwGp9N5UHWx6qyJfyAAXwukH UGuzlG/vyJ+ajqDXyxfO6JEcaDnTElv7dXwuz7xOEmMGjJ2vdYwPHCqpJdT9Fbydwyp7A aC9F4ZpdhNFS0CiZXp2rmFnvwaYsufpxz5oOj74fAHVcG+Wvy2nJlGoKpgQIryQ1Z2zh0 nUUZsdW+7BxsacQmjyY+ILQryrOF0WRzkNXaWeXkukIBhYFCMXrxAFGdlZT4MV6LAaWtF 8Fi/KUIo+ihhk33+Dx3FGiSMEiUXDGLRedwlcl/KEcrNPoEff3QVeCwjY6ACGi29kWg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796391922; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=6rKMG153XN8ml8UGQXjLmSYQS5kdGlZU0Eni8PkeNvc=; b=glqNXiTqf1RpeetHyEWLpwVumpj6NuML1lmdGxZHUg1n3tiMYGRA36t1jP8chSoPClv8 X08nAgwOQWvxpmsPNMvgXLdJ3djRKyO83d/WB0os6XY9Shg92/qPKnIzBZ/3EXrzMPbAF syRr4N9Ricuxu/teGeigFALejDbXHlHM4HI3y1K9PvNxaq3RoZztVL5s80HHNW4DJQGGy f0COw2HR1cO8Qm1Bit7N6nGmSQEQFlu2RLNRbDJ+i8QusiX21sAhCOWtYdD3zbgUGsSsX mfYhz/ImuxlAeCqmf9ON8I5czbDxispoVBttBUKz1pm+TBhBKI+FrNe//RaVf4I/Btw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZFFFlU6T; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC86606A322 for ; Fri, 4 Dec 2026 13:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZFFFlU6T Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD79D1F000C2; Fri, 4 Dec 2026 13:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796391921; bh=6rKMG153XN8ml8UGQXjLmSYQS5kdGlZU0Eni8PkeNvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ZFFFlU6T3gvfjiGoYbGKviVIzcdK9bgv8GKG8n50InJwy2HlDinX1uc0Q1bAzksVp RTgNxhmic/vdTpFTSxw1+cmaq7ubw5SC/FjlvNb70FIqIgB0BcozyzGy7vcYQq8/Ln bFqH1Sc9bh93PFXIIGLpX8F2VhXzRdl7nKxKfhe/SVdZB/2xLqRK3KjuCKP3Qhov/m a8Dl87jcVjmsf1CRnxf5+3nMnDPD3XeA5thGOkKMuBMcCUHyoKQb1keAPonKVhK1l5 5cbcU5mD8S8xA2Z1/W4q9ifyDoGm+S9SIIWnEv3rb719LnQhVicicn5j2thUuiRYPv 8D8p4hoj8XTYQ== From: Sasha Levin To: stable@vger.kernel.org Cc: Donggeun Yoo , Andrew Morton , "David Hildenbrand (Arm)" , "Mike Rapoport (Microsoft)" , Peter Xu , Suren Baghdasaryan , Andrea Arcangeli , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Michal Hocko , Shuah Khan , Kiryl Shutsemau , Sasha Levin Subject: [PATCH 6.12.y] userfaultfd: clear the inherited uffd bit in move_swap_pte() Date: Fri, 4 Dec 2026 08:45:18 -0500 Message-ID: <20261204134452.3189783-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120334-tummy-pushup-6056@gregkh> References: <2026120334-tummy-pushup-6056@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Donggeun Yoo [ Upstream commit 50abb4245e1ecdd679aef504543bdbc055dc9247 ] 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//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. Link: https://lore.kernel.org/20261003103030.63380-1-donggeunyoo.kernel@gmail.com Link: https://lore.kernel.org/20261003103030.63380-2-donggeunyoo.kernel@gmail.com Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") Signed-off-by: Donggeun Yoo Signed-off-by: Andrew Morton Acked-by: David Hildenbrand (Arm) Acked-by: Mike Rapoport (Microsoft) Assisted-by: LLM Cc: Peter Xu Cc: Suren Baghdasaryan Cc: Andrea Arcangeli Cc: Lorenzo Stoakes Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Michal Hocko Cc: Shuah Khan Cc: Kiryl Shutsemau Cc: mm/userfaultfd.c | 1 + 1 file changed, 1 insertion(+) [ sashal: adapted to the older API by using an #ifdef CONFIG_MEM_SOFT_DIRTY guard and the pte_swp_clear_uffd_wp() helper instead of the newer uffd helper names and soft-dirty check. ] Signed-off-by: Sasha Levin --- mm/userfaultfd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index f592f92c74079..5ca19e9dd967a 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1134,6 +1134,7 @@ static int move_swap_pte(struct mm_struct *mm, struct vm_area_struct *dst_vma, #ifdef CONFIG_MEM_SOFT_DIRTY orig_src_pte = pte_swp_mksoft_dirty(orig_src_pte); #endif + orig_src_pte = pte_swp_clear_uffd_wp(orig_src_pte); set_pte_at(mm, dst_addr, dst_pte, orig_src_pte); double_pt_unlock(dst_ptl, src_ptl); -- 2.53.0