Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BB012882C6 for ; Wed, 18 Jun 2025 11:05:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750244716; cv=none; b=CRRcYhdzh/eXnoA6fr0WB8t47ZgcO3tDK7Qck4NMslrpSITN8ynYspCYZbm/Drzylgm9thazuvoJU5DNz/+kR+uX4CknYDIx4eeRo8Lpil514npceTgkodLRvMIv9ZwFdUAG+tIApRGESkucHwhVISDfNNKsIt9zBspOP+wPhmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750244716; c=relaxed/simple; bh=dhm7hsAanV9XJRRERSscnRkac7oH6l1ErT1soD8cwYY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QXNYv6frJf73BA3fB+IeM6HsOW54zFzvhixr1L/RUSGeX99QRtvmFQ0dJk0lJNxouhONSFh7qqoXM8UiK3I/FP2pzE30Ue8N0cNzX4NH7FpW1Y25AX0w1L36LnMFDfAHKLB2V9Qppnhqw91qXJZOL0vhVCzXIVNPH3AFC/IB738= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=x3jfq08m; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="x3jfq08m" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCD99C4CEE7; Wed, 18 Jun 2025 11:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750244716; bh=dhm7hsAanV9XJRRERSscnRkac7oH6l1ErT1soD8cwYY=; h=From:To:Cc:Subject:Date:Reply-to:From; b=x3jfq08ml7aC3Wor3fGVQN8pEKzIynlOfL7bP+rrtF6kPm+YCo3bIBehqJneyTUfK ytecBlAWpT7BKYgl4T+wqPgnIIMJZs2Mbmcfx3hXuzvKt794srOwhy9D/ChOejF8Hj 1HJ0YXGutG3IosAzmDT+9P8kleMK7qZfk3uyJrW4= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50014: mm/gup: fix FOLL_FORCE COW security issue and remove FOLL_COW Date: Wed, 18 Jun 2025 13:01:19 +0200 Message-ID: <2025061833-CVE-2022-50014-2936@gregkh> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5107; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=reyuqt62hovwK+f9axi+5BFKvCeG1M1DgESNSj4+wc8=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlBcwL3vuZX4+iT0WkyWq8m3x2dP+F2wtG173kbLRpva el23bveEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABPJW8kwP9LJZPoZsy3bln7Z r1C1yG9xPkt7GsOCpV4eqv/uqDe1TvDeFFyX+Hb+zqP/AA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: mm/gup: fix FOLL_FORCE COW security issue and remove FOLL_COW Ever since the Dirty COW (CVE-2016-5195) security issue happened, we know that FOLL_FORCE can be possibly dangerous, especially if there are races that can be exploited by user space. Right now, it would be sufficient to have some code that sets a PTE of a R/O-mapped shared page dirty, in order for it to erroneously become writable by FOLL_FORCE. The implications of setting a write-protected PTE dirty might not be immediately obvious to everyone. And in fact ever since commit 9ae0f87d009c ("mm/shmem: unconditionally set pte dirty in mfill_atomic_install_pte"), we can use UFFDIO_CONTINUE to map a shmem page R/O while marking the pte dirty. This can be used by unprivileged user space to modify tmpfs/shmem file content even if the user does not have write permissions to the file, and to bypass memfd write sealing -- Dirty COW restricted to tmpfs/shmem (CVE-2022-2590). To fix such security issues for good, the insight is that we really only need that fancy retry logic (FOLL_COW) for COW mappings that are not writable (!VM_WRITE). And in a COW mapping, we really only broke COW if we have an exclusive anonymous page mapped. If we have something else mapped, or the mapped anonymous page might be shared (!PageAnonExclusive), we have to trigger a write fault to break COW. If we don't find an exclusive anonymous page when we retry, we have to trigger COW breaking once again because something intervened. Let's move away from this mandatory-retry + dirty handling and rely on our PageAnonExclusive() flag for making a similar decision, to use the same COW logic as in other kernel parts here as well. In case we stumble over a PTE in a COW mapping that does not map an exclusive anonymous page, COW was not properly broken and we have to trigger a fake write-fault to break COW. Just like we do in can_change_pte_writable() added via commit 64fe24a3e05e ("mm/mprotect: try avoiding write faults for exclusive anonymous pages when changing protection") and commit 76aefad628aa ("mm/mprotect: fix soft-dirty check in can_change_pte_writable()"), take care of softdirty and uffd-wp manually. For example, a write() via /proc/self/mem to a uffd-wp-protected range has to fail instead of silently granting write access and bypassing the userspace fault handler. Note that FOLL_FORCE is not only used for debug access, but also triggered by applications without debug intentions, for example, when pinning pages via RDMA. This fixes CVE-2022-2590. Note that only x86_64 and aarch64 are affected, because only those support CONFIG_HAVE_ARCH_USERFAULTFD_MINOR. Fortunately, FOLL_COW is no longer required to handle FOLL_FORCE. So let's just get rid of it. Thanks to Nadav Amit for pointing out that the pte_dirty() check in FOLL_FORCE code is problematic and might be exploitable. Note 1: We don't check for the PTE being dirty because it doesn't matter for making a "was COWed" decision anymore, and whoever modifies the page has to set the page dirty either way. Note 2: Kernels before extended uffd-wp support and before PageAnonExclusive (< 5.19) can simply revert the problematic commit instead and be safe regarding UFFDIO_CONTINUE. A backport to v5.19 requires minor adjustments due to lack of vma_soft_dirty_enabled(). The Linux kernel CVE team has assigned CVE-2022-50014 to this issue. Affected and fixed versions =========================== Issue introduced in 5.16 with commit 9ae0f87d009ca6c4aab2882641ddfc319727e3db and fixed in 5.19.6 with commit 9def52eb10baab3b700858003d462fcf17d62873 Issue introduced in 5.16 with commit 9ae0f87d009ca6c4aab2882641ddfc319727e3db and fixed in 6.0 with commit 5535be3099717646781ce1540cf725965d680e7b Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-50014 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: include/linux/mm.h mm/gup.c mm/huge_memory.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/9def52eb10baab3b700858003d462fcf17d62873 https://git.kernel.org/stable/c/5535be3099717646781ce1540cf725965d680e7b