linux/arch/x86/kernel/cpu/sgx
Reinette Chatre e5733d8c89 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: d6d261bded ("x86/sgx: Add new sgx_epc_page flag bit to mark free pages")
Fixes: 992801ae92 ("x86/sgx: Initial poison handling for dirty and free pages")
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Link: https://lkml.kernel.org/r/dcc95eb2aaefb042527ac50d0a50738c7c160dac.1643830353.git.reinette.chatre@intel.com
2022-02-17 10:24:50 -08:00
..
driver.c x86/sgx: Move provisioning device creation out of SGX driver 2021-04-06 19:18:46 +02:00
driver.h x86/sgx: Add SGX_IOC_ENCLAVE_PROVISION 2020-11-18 18:02:50 +01:00
encl.c x86/sgx: Silence softlockup detection when releasing large enclaves 2022-02-10 15:58:14 -08:00
encl.h x86/sgx: use vma_lookup() in sgx_encl_find() 2021-06-29 10:53:51 -07:00
encls.h x86/sgx: Remove .fixup usage 2021-12-11 09:09:49 +01:00
ioctl.c x86/sgx: Move provisioning device creation out of SGX driver 2021-04-06 19:18:46 +02:00
main.c x86/sgx: Fix missing poison handling in reclaimer 2022-02-17 10:24:50 -08:00
Makefile x86/sgx: Introduce virtual EPC for use by KVM guests 2021-04-06 09:43:17 +02:00
sgx.h x86/sgx: Add an attribute for the amount of SGX memory in a NUMA node 2021-12-09 07:02:22 -08:00
virt.c x86/sgx/virt: implement SGX_IOC_VEPC_REMOVE ioctl 2021-10-22 08:32:12 -07:00