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 B20D42010FD for ; Mon, 2 Dec 2024 13:53:53 +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=1733147633; cv=none; b=Y3KvpJey6eplvkR7R+GWl7sk46tsiYA0TYakaczsCRCM2s2hdPSYG84mVNu98JmL3t559jXU7TVYWxLsOBKMGqeGXihI83UDofvK+CIghaRM4tpWgiqzXqYc2wj4J91dywd4CTZsHKVBAgJnZYAqpkcrwzs1Jxrr7oV3+GVt+5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733147633; c=relaxed/simple; bh=xhcf4KCxVRMXCh0KLWzyGPKWUYu4kKLVjcAuv1vfIa0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=uXAs4p6QblXNaTXWaYJZMdVuh+484I10E5sCuqMgTOJ/edqILklBzpvHVotjv3A5hKlsiCHm0B4IIVi3Vt/jkBqEjKJB1MS/NoYhAPGXIW7wZhC8CpQq3BQI27BcjPmv1TSN95UCIdj8dFeDZcbmtZ9tyb9ZFFg2zi77+mkEVL8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UoPcEncw; 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="UoPcEncw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 221FBC4CED1; Mon, 2 Dec 2024 13:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733147633; bh=xhcf4KCxVRMXCh0KLWzyGPKWUYu4kKLVjcAuv1vfIa0=; h=From:To:Cc:Subject:Date:Reply-to:From; b=UoPcEncwZu20k2THjrF46aWYSF9/CHCXPGi/uEOLoENdcjaeGZq4JXHNm4c/686aK x//cM2WbOcDk2PiALZ1Y5DVJN0/yRGnHCwz3KfSomZ1cll78NkV0T9s6wNTaFzZwxx sY0YPd8qTpDzjyPOG+9L5pkUkBGXyki5qJ1BCQYI= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-53111: mm/mremap: fix address wraparound in move_page_tables() Date: Mon, 2 Dec 2024 14:52:50 +0100 Message-ID: <2024120248-CVE-2024-53111-eb9b@gregkh> X-Mailer: git-send-email 2.47.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=4004; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=xhcf4KCxVRMXCh0KLWzyGPKWUYu4kKLVjcAuv1vfIa0=; b=owGbwMvMwCRo6H6F97bub03G02pJDOm+uze8LT6l+iTyYdc7//wF394bHrlx1NKC+0/zxvKW2 +peLQpzOmJZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAimVMZFlyMVrkTG/DHPNr2 S7D/wgexfMwuWxnmV9o68B2115rU4da35YWgen2H6nd2AA== 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/mremap: fix address wraparound in move_page_tables() On 32-bit platforms, it is possible for the expression `len + old_addr < old_end` to be false-positive if `len + old_addr` wraps around. `old_addr` is the cursor in the old range up to which page table entries have been moved; so if the operation succeeded, `old_addr` is the *end* of the old region, and adding `len` to it can wrap. The overflow causes mremap() to mistakenly believe that PTEs have been copied; the consequence is that mremap() bails out, but doesn't move the PTEs back before the new VMA is unmapped, causing anonymous pages in the region to be lost. So basically if userspace tries to mremap() a private-anon region and hits this bug, mremap() will return an error and the private-anon region's contents appear to have been zeroed. The idea of this check is that `old_end - len` is the original start address, and writing the check that way also makes it easier to read; so fix the check by rearranging the comparison accordingly. (An alternate fix would be to refactor this function by introducing an "orig_old_start" variable or such.) Tested in a VM with a 32-bit X86 kernel; without the patch: ``` user@horn:~/big_mremap$ cat test.c #define _GNU_SOURCE #include #include #include #include #define ADDR1 ((void*)0x60000000) #define ADDR2 ((void*)0x10000000) #define SIZE 0x50000000uL int main(void) { unsigned char *p1 = mmap(ADDR1, SIZE, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED_NOREPLACE, -1, 0); if (p1 == MAP_FAILED) err(1, "mmap 1"); unsigned char *p2 = mmap(ADDR2, SIZE, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE|MAP_FIXED_NOREPLACE, -1, 0); if (p2 == MAP_FAILED) err(1, "mmap 2"); *p1 = 0x41; printf("first char is 0x%02hhx\n", *p1); unsigned char *p3 = mremap(p1, SIZE, SIZE, MREMAP_MAYMOVE|MREMAP_FIXED, p2); if (p3 == MAP_FAILED) { printf("mremap() failed; first char is 0x%02hhx\n", *p1); } else { printf("mremap() succeeded; first char is 0x%02hhx\n", *p3); } } user@horn:~/big_mremap$ gcc -static -o test test.c user@horn:~/big_mremap$ setarch -R ./test first char is 0x41 mremap() failed; first char is 0x00 ``` With the patch: ``` user@horn:~/big_mremap$ setarch -R ./test first char is 0x41 mremap() succeeded; first char is 0x41 ``` The Linux kernel CVE team has assigned CVE-2024-53111 to this issue. Affected and fixed versions =========================== Issue introduced in 6.7 with commit af8ca1c14906 and fixed in 6.11.10 with commit 909543dc279a Issue introduced in 6.7 with commit af8ca1c14906 and fixed in 6.12 with commit a4a282daf1a1 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-53111 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: mm/mremap.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/909543dc279a91122fb08e4653a72b82f0ad28f4 https://git.kernel.org/stable/c/a4a282daf1a190f03790bf163458ea3c8d28d217