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 1C01918E359 for ; Mon, 25 Nov 2024 21:20:38 +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=1732569639; cv=none; b=Zz8Jv/u2CPVa5lCk4s7yAs0LZN+92Rv+k5G9HOjweqpjCCXmGGVGUBIaOWgz/dtanqywPpBjYZu53Pij4M1H685qiqLddqXAiTr4nw86L4JJ6+gfS/UeWPSAVDthNbstXybhede7lypIWDfRoBrWgsJ355NrwLUedM+960DoHTo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732569639; c=relaxed/simple; bh=4S7ji8EFaiFtCQAW04bud/8Mdq7ZoejnF7JyG0GnbSM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=kfB4np2MGRYps3yyXzEQI7h+FpSqxi3SBSrrOiVmJftrMpbZB5qFd07s0WcQC3u8BGi5hSBeJItfJrZ2B4j0aanyStbkjjAF5d+0hxrSY57ySgHI4FfHcnQuHl3qxUJpXREw1awCrzTQ7f6VfdBE3o+nLOXh7Uk7qVguI5yYwnE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=iJvUq3I8; 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="iJvUq3I8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50F4FC4CECF; Mon, 25 Nov 2024 21:20:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1732569638; bh=4S7ji8EFaiFtCQAW04bud/8Mdq7ZoejnF7JyG0GnbSM=; h=From:To:Cc:Subject:Date:Reply-to:From; b=iJvUq3I83fqOGL+8q9GW2I+Km4tNGpoSaSmIKCdVIP6JkeLs80UtOdVtpKhvAh3IY Pd39axuuRRwCqEEqTNmvGRbCJ6Vcr9VvGfEI7oi05yrxJzFGrwhQQnQUV9ALkC8cDe rxoG63HtX8li5yGNiBlyT5U/DKpVSBJCgm3bdWDo= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-53096: mm: resolve faulty mmap_region() error path behaviour Date: Mon, 25 Nov 2024 22:20:07 +0100 Message-ID: <2024112506-CVE-2024-53096-5bcc@gregkh> X-Mailer: git-send-email 2.47.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=4159; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=4S7ji8EFaiFtCQAW04bud/8Mdq7ZoejnF7JyG0GnbSM=; b=owGbwMvMwCRo6H6F97bub03G02pJDOkur9ijnAq+fdCVemHgfeRb+FOPq2XtZsEKaxlU/h4UO J7IX7+nI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACZicZdhns6/9/8mHJg3+X7Q 1G1aXK0nZ2s7P2KYpxE4Q4vHRC1sdb30V/cjM0+r/eK7BgA= 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: resolve faulty mmap_region() error path behaviour The mmap_region() function is somewhat terrifying, with spaghetti-like control flow and numerous means by which issues can arise and incomplete state, memory leaks and other unpleasantness can occur. A large amount of the complexity arises from trying to handle errors late in the process of mapping a VMA, which forms the basis of recently observed issues with resource leaks and observable inconsistent state. Taking advantage of previous patches in this series we move a number of checks earlier in the code, simplifying things by moving the core of the logic into a static internal function __mmap_region(). Doing this allows us to perform a number of checks up front before we do any real work, and allows us to unwind the writable unmap check unconditionally as required and to perform a CONFIG_DEBUG_VM_MAPLE_TREE validation unconditionally also. We move a number of things here: 1. We preallocate memory for the iterator before we call the file-backed memory hook, allowing us to exit early and avoid having to perform complicated and error-prone close/free logic. We carefully free iterator state on both success and error paths. 2. The enclosing mmap_region() function handles the mapping_map_writable() logic early. Previously the logic had the mapping_map_writable() at the point of mapping a newly allocated file-backed VMA, and a matching mapping_unmap_writable() on success and error paths. We now do this unconditionally if this is a file-backed, shared writable mapping. If a driver changes the flags to eliminate VM_MAYWRITE, however doing so does not invalidate the seal check we just performed, and we in any case always decrement the counter in the wrapper. We perform a debug assert to ensure a driver does not attempt to do the opposite. 3. We also move arch_validate_flags() up into the mmap_region() function. This is only relevant on arm64 and sparc64, and the check is only meaningful for SPARC with ADI enabled. We explicitly add a warning for this arch if a driver invalidates this check, though the code ought eventually to be fixed to eliminate the need for this. With all of these measures in place, we no longer need to explicitly close the VMA on error paths, as we place all checks which might fail prior to a call to any driver mmap hook. This eliminates an entire class of errors, makes the code easier to reason about and more robust. The Linux kernel CVE team has assigned CVE-2024-53096 to this issue. Affected and fixed versions =========================== Issue introduced in 6.1 with commit deb0f6562884 and fixed in 6.12 with commit 5de195060b2e Issue introduced in 5.10.150 with commit a3c08c021778 Issue introduced in 5.15.75 with commit 43bed0a13a5c Issue introduced in 5.19.17 with commit 6757330b1be5 Issue introduced in 6.0.3 with commit 66f2ed0172af 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-53096 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/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/5de195060b2e251a835f622759550e6202167641