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 5022B1F151B for ; Tue, 21 Jan 2025 12:09:26 +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=1737461367; cv=none; b=oqY45CK193acJYMsqI5hGyawoBOwoNQof7u0zn6YqDTFA6Idin1rnebcCto0BLt6+b5R1C/CfVAgw5iY6w/L7FDzJpIrV/H4brtXozPhnug3SIe3jBLDwePLia8JMqTPbKbPRvh5xUq4gzUg8qfoAK+SOK21snXYnJJAwJla+x4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737461367; c=relaxed/simple; bh=yqTSCh5EqGQNZowOMVjDfDLTj92nqfT/i5Qk/104I+A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=WuRzYb+PUtSbLUsVkGWTQnf7SrVhdTbCzB39bW+FY0EgNyiFYtkRmQtiG4Zzt3FNvP+dIzNfAnIqi1AX3NnmtmvehVotJJfvfsAkl4gesbX4a583DA4EAA4J4U1JhjlTjIMdMABZ0Ed8VhJq7VEfaFqXwtPWdn16eqX56U+JONc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=iX+/e4VI; 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="iX+/e4VI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 604D8C4CEDF; Tue, 21 Jan 2025 12:09:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1737461366; bh=yqTSCh5EqGQNZowOMVjDfDLTj92nqfT/i5Qk/104I+A=; h=From:To:Cc:Subject:Date:Reply-to:From; b=iX+/e4VIeNjwUXwjCLBCsveU3KMORgQF2yiUKOqnKp+MyU+L8lGXzElilsJDchsdS BOgfFKIrb3BucnyLpC8IoyN3x6kBXS0OaGJUWIcNoj5lP4noyy+FNkd6gba2sqhzPW I63qVmFnlpLBuL12dR22ObML/fgBZ5dhskGC9PhA= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-57937: mm: reinstate ability to map write-sealed memfd mappings read-only Date: Tue, 21 Jan 2025 13:09:20 +0100 Message-ID: <2025012119-CVE-2024-57937-158a@gregkh> X-Mailer: git-send-email 2.48.1 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=4857; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=yqTSCh5EqGQNZowOMVjDfDLTj92nqfT/i5Qk/104I+A=; b=owGbwMvMwCRo6H6F97bub03G02pJDOn9ffnyb+ce+RfgOW/7P409QWHuMSHGMsfU/dhWvKjO/ sW7tU+2I5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACYifZhhwV5Xgxjpbtfd2pPE c+y/P4qRviDxkGHBksC/8Y9bplRkct7r4PxnYKAueKYfAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: mm: reinstate ability to map write-sealed memfd mappings read-only Patch series "mm: reinstate ability to map write-sealed memfd mappings read-only". In commit 158978945f31 ("mm: perform the mapping_map_writable() check after call_mmap()") (and preceding changes in the same series) it became possible to mmap() F_SEAL_WRITE sealed memfd mappings read-only. Commit 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") unintentionally undid this logic by moving the mapping_map_writable() check before the shmem_mmap() hook is invoked, thereby regressing this change. This series reworks how we both permit write-sealed mappings being mapped read-only and disallow mprotect() from undoing the write-seal, fixing this regression. We also add a regression test to ensure that we do not accidentally regress this in future. Thanks to Julian Orth for reporting this regression. This patch (of 2): In commit 158978945f31 ("mm: perform the mapping_map_writable() check after call_mmap()") (and preceding changes in the same series) it became possible to mmap() F_SEAL_WRITE sealed memfd mappings read-only. This was previously unnecessarily disallowed, despite the man page documentation indicating that it would be, thereby limiting the usefulness of F_SEAL_WRITE logic. We fixed this by adapting logic that existed for the F_SEAL_FUTURE_WRITE seal (one which disallows future writes to the memfd) to also be used for F_SEAL_WRITE. For background - the F_SEAL_FUTURE_WRITE seal clears VM_MAYWRITE for a read-only mapping to disallow mprotect() from overriding the seal - an operation performed by seal_check_write(), invoked from shmem_mmap(), the f_op->mmap() hook used by shmem mappings. By extending this to F_SEAL_WRITE and critically - checking mapping_map_writable() to determine if we may map the memfd AFTER we invoke shmem_mmap() - the desired logic becomes possible. This is because mapping_map_writable() explicitly checks for VM_MAYWRITE, which we will have cleared. Commit 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") unintentionally undid this logic by moving the mapping_map_writable() check before the shmem_mmap() hook is invoked, thereby regressing this change. We reinstate this functionality by moving the check out of shmem_mmap() and instead performing it in do_mmap() at the point at which VMA flags are being determined, which seems in any case to be a more appropriate place in which to make this determination. In order to achieve this we rework memfd seal logic to allow us access to this information using existing logic and eliminate the clearing of VM_MAYWRITE from seal_check_write() which we are performing in do_mmap() instead. The Linux kernel CVE team has assigned CVE-2024-57937 to this issue. Affected and fixed versions =========================== Issue introduced in 6.12 with commit 5de195060b2e251a835f622759550e6202167641 and fixed in 6.12.9 with commit 464770df46095e6967334d77113972960f7ef1fa Issue introduced in 6.12 with commit 5de195060b2e251a835f622759550e6202167641 and fixed in 6.13 with commit 8ec396d05d1b737c87311fb7311f753b02c2a6b1 Issue introduced in 5.10.231 with commit 43323a4e5b3f8ccc08e2f835abfdc7ee9da8f6ed Issue introduced in 5.15.174 with commit 44f48eb9a6051826227bbd375446064fb2a43c6c Issue introduced in 6.1.119 with commit 52c81fd0f5a8bf8032687b94ccf00d13b44cc5c8 Issue introduced in 6.6.63 with commit bdc136e2b05fabcd780fe5f165d154eb779dfcb0 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-2024-57937 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/memfd.h include/linux/mm.h mm/memfd.c mm/mmap.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/464770df46095e6967334d77113972960f7ef1fa https://git.kernel.org/stable/c/8ec396d05d1b737c87311fb7311f753b02c2a6b1