From nobody Mon Jun 15 10:49:15 2026 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EB523E274E for ; Thu, 9 Apr 2026 15:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775748515; cv=none; b=ur7aNh6ZsqdOWjGG1dwJbSVqzOkS4zUE+J979r8HDCL5LQiwo/+BV7sUVgfOe1CUNW9bY/gYe6ygvo2ywpspy9hsj4eCUtFw73tQT/Ou6Re/36q7Q7jh+AOae+68I70bZ6YXYoxh0ft4U1PCBDDoHFxWwEkcmrMhjPyGkhze/o0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775748515; c=relaxed/simple; bh=/N+eEafkkkzcKAncyso2/4KjnGl5N91tx2c0DHFGeLQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DVlDXhy/gMX0L+iSywp9qTnrt5slwvVOrEBOdf6ALuSRqbtlZHtZm8KfHSRmiSXCncOmqesD3uaSdGeNyt2f+sJXJWvaibcWBRVvqnBbfc4OoCprsj2v2h+t7vUU0+AfzwQ7ZgGO2BP1nD/GLZJmVXc75VtuCdpeDxZYg3DmhOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b=SHcTFoW2; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.b="SHcTFoW2" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-8cd71fb9f06so54842685a.2 for ; Thu, 09 Apr 2026 08:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1775748510; x=1776353310; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+DnPa6Sb2TShUFRzmwJOmZQYJ7+4xed43t8HDhFa3Hg=; b=SHcTFoW2BPOwnFPlBCZDt0RphHQbNTZtV0tIYoNutZKRhF6MRelWO4hoBNoZ34v2bz x6hxZeyNWEQ+k5tcW0pCVC06mB772IW6sokj3AQ01zLlYfy4tdHPQ/fgah4K4uLo1DtZ kI3/ssKfioatVcABhuaEDizZLaws+iBdv/pFqHuZmocsdOax3Mc1KKMk5RyIrXSnWbiM q8G204gQ7t08Pprr7rLUZ4AEYR1TB/ovcHTeaIK5fH6eImnmnwQ0sorAFCmWyVlywOgC gct/DwNjicysvmaQxSkZDAQes96ZRgXhnu4IRdW/rkjTrKBmdnDJLNeISZ8keQes4+L8 Xr8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775748510; x=1776353310; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+DnPa6Sb2TShUFRzmwJOmZQYJ7+4xed43t8HDhFa3Hg=; b=q5McRIuNZ/A6wmrHBSvggFu6ZDmTJJfo+XzuWUEIOO9Rx1iVKQGPnwxHiL1ikj1acL DVwL4nEPaoflqtDFD5c67ncpqBBX9tP7Iaaht7oozxYHY5Nd7B9FajiyYRsjUwFWpo3h MTvJtCuKzSVePVywxVHonpusRx4gr34FUXGXiL50qBQq0ojD7J2a+vspZNCBQZhGyAdf Ble5BW/LyKtUyGAMG75PeDLl5F6iYl5zaZfflfwPol29/WaVoHnXDKOxUGGgEyr6gjan kEubKZ3f1zmKNcBNEQlTapGX4N4mD10ySHLoNLeF2HuPvd/SeM4ZQOSVGKoDO3Dx5aw1 JiJg== X-Gm-Message-State: AOJu0YwwVko1kwC2uWzY0b6Z1wYuByUEO6Hys8wcVxyo+reG0lqwzdXs 0uiznSUUFg3XEHUdOKXqFA0Ji1/fVA5qc7qYGP2omiiF/fBDEa2VFiEcsMGPrzKMu38= X-Gm-Gg: AeBDiespptGxw/Hb70XWKG0nmFlDVDCpfPIKIKxHsH/ceqM5B+Q0Wg9w18u0Bc/Hk3o r4RP5j9/e+SNdMvuEbzulOfUW83GOR3xl4Hn2vcjUrGZ394mhetaDiY6lZncNPOzMXCBHOBLd4u /38NTUW2D2z77rfjlvZVy/NUVmgE2jHBl4Yp3X+x2o1Ck5IuSwMbAJlGUps09+31E/PTeWyH8ru 9n+W7LrRIS80AgPwCTe/aOyHZbrIz8sCvEXkiMEGGaiWd3kn3AmWn00mVoCzZp+y05MJL5qUvky iOJbTt2FfqMPFn58bF7O6aYR2HgKo8LGD/fT7qaOvL+7V5LF8CS/ywdF6vyv6nyUtpFcExBD37U 6+Rg7Q8PVQ/soeGxxPY0lRdvjtZtIgyfvtvhibm11ogGGrhfp0BLR1eCGHne0RAOXkAbiv0Gnu8 EMLh4byDUb4F0Dal7h7OVvKgzNXGu1Yfpuwv4nNMY6RebDLetEiBIsZSrpnG8fFo23rRlDLDYB/ fkXvNOKjOCJhD9zuw== X-Received: by 2002:a05:620a:4486:b0:8d8:ba4a:596c with SMTP id af79cd13be357-8d8ba4a5bb4mr1928631685a.51.1775748509683; Thu, 09 Apr 2026 08:28:29 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-71-191-243-150.washdc.fios.verizon.net. [71.191.243.150]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8d3f588d2b1sm1529802085a.43.2026.04.09.08.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Apr 2026 08:28:29 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, akpm@linux-foundation.org, rppt@kernel.org, peterx@redhat.com, surenb@google.com, aarcange@redhat.com, stable@vger.kernel.org Subject: [PATCH] userfaultfd: preserve write protection across UFFDIO_MOVE Date: Thu, 9 Apr 2026 11:28:22 -0400 Message-ID: <20260409152822.1073083-1-gourry@gourry.net> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" move_present_ptes() unconditionally makes the destination PTE writable, dropping uffd-wp write-protection from the source PTE. The original intent was to follow mremap() behavior, but mremap()'s move_ptes() preserves the source write state unconditionally. Modify uffd to preserve the source write state and check the uffd-wp condition of the source before setting writable on the destination. Fixes: adef440691ba ("userfaultfd: UFFDIO_MOVE uABI") Cc: stable@vger.kernel.org Signed-off-by: Gregory Price Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Suren Baghdasaryan --- mm/userfaultfd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e6dfd5f28acd..783ca68aed88 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -1123,7 +1123,10 @@ static long move_present_ptes(struct mm_struct *mm, orig_dst_pte =3D pte_mksoft_dirty(orig_dst_pte); if (pte_dirty(orig_src_pte)) orig_dst_pte =3D pte_mkdirty(orig_dst_pte); - orig_dst_pte =3D pte_mkwrite(orig_dst_pte, dst_vma); + if (pte_write(orig_src_pte)) + orig_dst_pte =3D pte_mkwrite(orig_dst_pte, dst_vma); + if (pte_uffd_wp(orig_src_pte)) + orig_dst_pte =3D pte_mkuffd_wp(orig_dst_pte); set_pte_at(mm, dst_addr, dst_pte, orig_dst_pte); =20 src_addr +=3D PAGE_SIZE; --=20 2.52.0