Skip to content

Commit e5733d8

Browse files
rchatrehansendc
authored andcommitted
x86/sgx: Fix missing poison handling in reclaimer
The SGX reclaimer code lacks page poison handling in its main free path. This can lead to avoidable machine checks if a poisoned page is freed and reallocated instead of being isolated. A troublesome scenario is: 1. Machine check (#MC) occurs (asynchronous, !MF_ACTION_REQUIRED) 2. arch_memory_failure() is eventually called 3. (SGX) page->poison set to 1 4. Page is reclaimed 5. Page added to normal free lists by sgx_reclaim_pages() ^ This is the bug (poison pages should be isolated on the sgx_poison_page_list instead) 6. Page is reallocated by some innocent enclave, a second (synchronous) in-kernel #MC is induced, probably during EADD instruction. ^ This is the fallout from the bug (6) is unfortunate and can be avoided by replacing the open coded enclave page freeing code in the reclaimer with sgx_free_epc_page() to obtain support for poison page handling that includes placing the poisoned page on the correct list. Fixes: d6d261b ("x86/sgx: Add new sgx_epc_page flag bit to mark free pages") Fixes: 992801a ("x86/sgx: Initial poison handling for dirty and free pages") Signed-off-by: Reinette Chatre <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Link: https://lkml.kernel.org/r/dcc95eb2aaefb042527ac50d0a50738c7c160dac.1643830353.git.reinette.chatre@intel.com
1 parent 8795359 commit e5733d8

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,8 @@ static void sgx_reclaim_pages(void)
344344
{
345345
struct sgx_epc_page *chunk[SGX_NR_TO_SCAN];
346346
struct sgx_backing backing[SGX_NR_TO_SCAN];
347-
struct sgx_epc_section *section;
348347
struct sgx_encl_page *encl_page;
349348
struct sgx_epc_page *epc_page;
350-
struct sgx_numa_node *node;
351349
pgoff_t page_index;
352350
int cnt = 0;
353351
int ret;
@@ -418,13 +416,7 @@ static void sgx_reclaim_pages(void)
418416
kref_put(&encl_page->encl->refcount, sgx_encl_release);
419417
epc_page->flags &= ~SGX_EPC_PAGE_RECLAIMER_TRACKED;
420418

421-
section = &sgx_epc_sections[epc_page->section];
422-
node = section->node;
423-
424-
spin_lock(&node->lock);
425-
list_add_tail(&epc_page->list, &node->free_page_list);
426-
spin_unlock(&node->lock);
427-
atomic_long_inc(&sgx_nr_free_pages);
419+
sgx_free_epc_page(epc_page);
428420
}
429421
}
430422

0 commit comments

Comments
 (0)