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 B2A8A28C03E for ; Thu, 10 Jul 2025 08:15:58 +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=1752135358; cv=none; b=CfvnWOv/xNpATOlZJgyvFyAY/lwaZE9+aDHYiriYZKx+ZhbkUGS+xnr0mVbkiip0Xms8vDmqNFHTvVMoma44Bmnws5MvVgHLfT6Es2zok91rzFEWM1GCma58MNe2JRhHrNLVMecgizqRk8YcqdoDsmbOfil4+vzS0RRzUDdRXd8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752135358; c=relaxed/simple; bh=bLftHi5DBXDY11PQBpief6K9FqOVTnx4B4WcA2nxguU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=N0pK/okuwUfpsunTQpsg8ZrVJN659hkNtVBPnG7uXMxUK0W7e7503F+4SRNxuf/NykS+TLJvZ69crcz3UNXy8egLr/0wKpAj70CYTMub23x45YZiAP/WaUdC1f8M3uVAG9E/rAH7epI+SPqjmjMH1EAANz6IdicX4yrJvrpXWfM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CE04MDI/; 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="CE04MDI/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CC38C4CEF4; Thu, 10 Jul 2025 08:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1752135358; bh=bLftHi5DBXDY11PQBpief6K9FqOVTnx4B4WcA2nxguU=; h=From:To:Cc:Subject:Date:Reply-to:From; b=CE04MDI/SPQVkxFVTMo0rYcqIZofr32UKqEacOJKUp7yjs2vA3/v/oHqIZ13uMlEg FP0Hi0y1JAmT/1s7FNAUSxsM7nsxXQQlDT/55hXNPcW4KSHlpEUcazKsMqPHis2Cbr 3YtGO/KYdPSh/QrlPutbBpHszK0NC9fjNqjNIZC8= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2025-38334: x86/sgx: Prevent attempts to reclaim poisoned pages Date: Thu, 10 Jul 2025 10:15:42 +0200 Message-ID: <2025071033-CVE-2025-38334-0d45@gregkh> X-Mailer: git-send-email 2.50.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=4538; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=orG4SOK4IXn/PAzp6rAW6pBhtWDTeRodYS10WXZG884=; b=owGbwMvMwCRo6H6F97bub03G02pJDBn5ZUs3rl8vKNC/xzpyo2zc6wMZam8/T59Ryj/3bcK/h E7v5mMnO2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiTxkY5qf6hpx7trY1ag/H jVXnZvarTb368xDDgtZ78ZrxP2ROHT2d2vyyZsNcLw/JdQA= 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: x86/sgx: Prevent attempts to reclaim poisoned pages TL;DR: SGX page reclaim touches the page to copy its contents to secondary storage. SGX instructions do not gracefully handle machine checks. Despite this, the existing SGX code will try to reclaim pages that it _knows_ are poisoned. Avoid even trying to reclaim poisoned pages. The longer story: Pages used by an enclave only get epc_page->poison set in arch_memory_failure() but they currently stay on sgx_active_page_list until sgx_encl_release(), with the SGX_EPC_PAGE_RECLAIMER_TRACKED flag untouched. epc_page->poison is not checked in the reclaimer logic meaning that, if other conditions are met, an attempt will be made to reclaim an EPC page that was poisoned. This is bad because 1. we don't want that page to end up added to another enclave and 2. it is likely to cause one core to shut down and the kernel to panic. Specifically, reclaiming uses microcode operations including "EWB" which accesses the EPC page contents to encrypt and write them out to non-SGX memory. Those operations cannot handle MCEs in their accesses other than by putting the executing core into a special shutdown state (affecting both threads with HT.) The kernel will subsequently panic on the remaining cores seeing the core didn't enter MCE handler(s) in time. Call sgx_unmark_page_reclaimable() to remove the affected EPC page from sgx_active_page_list on memory error to stop it being considered for reclaiming. Testing epc_page->poison in sgx_reclaim_pages() would also work but I assume it's better to add code in the less likely paths. The affected EPC page is not added to &node->sgx_poison_page_list until later in sgx_encl_release()->sgx_free_epc_page() when it is EREMOVEd. Membership on other lists doesn't change to avoid changing any of the lists' semantics except for sgx_active_page_list. There's a "TBD" comment in arch_memory_failure() about pre-emptive actions, the goal here is not to address everything that it may imply. This also doesn't completely close the time window when a memory error notification will be fatal (for a not previously poisoned EPC page) -- the MCE can happen after sgx_reclaim_pages() has selected its candidates or even *inside* a microcode operation (actually easy to trigger due to the amount of time spent in them.) The spinlock in sgx_unmark_page_reclaimable() is safe because memory_failure() runs in process context and no spinlocks are held, explicitly noted in a mm/memory-failure.c comment. The Linux kernel CVE team has assigned CVE-2025-38334 to this issue. Affected and fixed versions =========================== Fixed in 6.1.142 with commit 00a88e9ea1b170d579c56327c38f7e8cf689df87 Fixed in 6.6.95 with commit 62b62a2a6dc51ed6e8e334861f04220c9cf8106a Fixed in 6.12.35 with commit dc5de5bd6deabd327ced2b2b1d0b4f14cd146afe Fixed in 6.15.4 with commit 31dcbac94bfeabb86bf85b0c36803fdd6536437b Fixed in 6.16-rc1 with commit ed16618c380c32c68c06186d0ccbb0d5e0586e59 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-2025-38334 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: arch/x86/kernel/cpu/sgx/main.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/00a88e9ea1b170d579c56327c38f7e8cf689df87 https://git.kernel.org/stable/c/62b62a2a6dc51ed6e8e334861f04220c9cf8106a https://git.kernel.org/stable/c/dc5de5bd6deabd327ced2b2b1d0b4f14cd146afe https://git.kernel.org/stable/c/31dcbac94bfeabb86bf85b0c36803fdd6536437b https://git.kernel.org/stable/c/ed16618c380c32c68c06186d0ccbb0d5e0586e59