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=1796381459; b=QB5E55OPexKujlNDJ6a3VMG/OLtoxzdxsMNTz3uCeYlsS5G+FxIUxNg3eIpAPkazL2VR u+SxM3VrN0qXxdgHFR/e4dUtyga58WtO5n14+C+irZPbPx9Rvrc8wQHaUcimFZC08BVKJ 8yjYvOoy+aLX9eL+ga4Rcl9jN+YDPKcIpl1pW0ef3f3RZaKtlG+nsgXDCP/hEeJPewvDD t0cPNzVccNBNXJoKcLPxJoKfdMOtA/83FG987Z/7vxIeDisBvXlHmJvUXd0ZBif1Wiv6T jY3//emhj02LZBWpP3Xt9A6CWcOf1bailoT3x4FiV7GtFtr4VP8zJqes5BOSLTEePig== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381459; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=QFwFHZtX47Ugg+vZ/Ib+8G2PTEldSJ+HnqZQs1O02Aw=; b=Eut/QvmR/tLw15qrApgG8AqO6oWvap3uDJeyey7426T2htm8plpqp7F2iRMTH/5xVmsI V57X+5z9R1gXVxF5ji8EJ6sJwEb13MYzmR/Ke7GDajeifeM0Z7z6vTwhHWmUngUwIvAZq C/C7hihwpthzm8d2jg4xZ0vl9t4M5SMtBgvrUxjaiI1r80xQzDSQsx674tw12FJFhBSMC E81xF0K11+zClywGLKp3RKt80j6VyKEwvb/gcJPk428cCayEdFM5ulDJULhryUbYO6wgt tKrbsnD0pXRbIpzze2tni9Fs5OytfEkAJ0yrpRuTby67lq3lQ0DsUb1El6EqgCC/+4w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fjrgMjuI; 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)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ADA0606A332; Fri, 4 Dec 2026 10:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fjrgMjuI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B3111F000CE; Fri, 4 Dec 2026 10:50:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381459; bh=QFwFHZtX47Ugg+vZ/Ib+8G2PTEldSJ+HnqZQs1O02Aw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fjrgMjuIsC+HlbfSoCWtBblWt3VtiUUNTywskvan/LPVuz13p3R3YWMgMwGdBydRm iPmZGDTyiQt1MuqgJDgkaoEFgrD/z2cPI5zEAHXfmKHKLctayeRGdAvWLUl69TiGOm nllSesTopM7pqjZLif4aibPXqjvmgULEzhmTSJ5E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, 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 Subject: [PATCH 7.3 714/742] userfaultfd: clear the inherited uffd bit in move_swap_pte() Date: Fri, 4 Dec 2026 19:09:38 +0900 Message-ID: <20261204100654.044223378@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Donggeun Yoo commit 50abb4245e1ecdd679aef504543bdbc055dc9247 upstream. 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: Signed-off-by: Greg Kroah-Hartman mm/userfaultfd.c | 1 + 1 file changed, 1 insertion(+) --- mm/userfaultfd.c | 1 + 1 file changed, 1 insertion(+) --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1425,6 +1425,7 @@ static int move_swap_pte(struct mm_struc 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);