Skip to content

Commit 23d833f

Browse files
committed
x86/sgx: Fix deadlock in SGX NUMA node search
JIRA: https://issues.redhat.com/browse/RHEL-22826 JIRA: https://issues.redhat.com/browse/RHEL-63522 CVE: CVE-2024-49856 Upstream Status: merged into the linux.git commit 9c93684 Author: Aaron Lu <aaron.lu@intel.com> Date: Thu Sep 5 16:08:54 2024 +0800 x86/sgx: Fix deadlock in SGX NUMA node search When the current node doesn't have an EPC section configured by firmware and all other EPC sections are used up, CPU can get stuck inside the while loop that looks for an available EPC page from remote nodes indefinitely, leading to a soft lockup. Note how nid_of_current will never be equal to nid in that while loop because nid_of_current is not set in sgx_numa_mask. Also worth mentioning is that it's perfectly fine for the firmware not to setup an EPC section on a node. While setting up an EPC section on each node can enhance performance, it is not a requirement for functionality. Rework the loop to start and end on *a* node that has SGX memory. This avoids the deadlock looking for the current SGX-lacking node to show up in the loop when it never will. Fixes: 901ddbb ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()") Reported-by: "Molina Sabido, Gerardo" <gerardo.molina.sabido@intel.com> Signed-off-by: Aaron Lu <aaron.lu@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Acked-by: Dave Hansen <dave.hansen@linux.intel.com> Tested-by: Zhimin Luo <zhimin.luo@intel.com> Link: https://lore.kernel.org/all/20240905080855.1699814-2-aaron.lu%40intel.com Signed-off-by: Vladis Dronov <vdronov@redhat.com>
1 parent d7e34f7 commit 23d833f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

arch/x86/kernel/cpu/sgx/main.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -474,24 +474,25 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void)
474474
{
475475
struct sgx_epc_page *page;
476476
int nid_of_current = numa_node_id();
477-
int nid = nid_of_current;
477+
int nid_start, nid;
478478

479-
if (node_isset(nid_of_current, sgx_numa_mask)) {
480-
page = __sgx_alloc_epc_page_from_node(nid_of_current);
481-
if (page)
482-
return page;
483-
}
484-
485-
/* Fall back to the non-local NUMA nodes: */
486-
while (true) {
487-
nid = next_node_in(nid, sgx_numa_mask);
488-
if (nid == nid_of_current)
489-
break;
479+
/*
480+
* Try local node first. If it doesn't have an EPC section,
481+
* fall back to the non-local NUMA nodes.
482+
*/
483+
if (node_isset(nid_of_current, sgx_numa_mask))
484+
nid_start = nid_of_current;
485+
else
486+
nid_start = next_node_in(nid_of_current, sgx_numa_mask);
490487

488+
nid = nid_start;
489+
do {
491490
page = __sgx_alloc_epc_page_from_node(nid);
492491
if (page)
493492
return page;
494-
}
493+
494+
nid = next_node_in(nid, sgx_numa_mask);
495+
} while (nid != nid_start);
495496

496497
return ERR_PTR(-ENOMEM);
497498
}

0 commit comments

Comments
 (0)