x86/sgx: Add xa_store_range() return value check in sgx_setup_epc_section()
PATCH 1/1 x86/sgx: Add xa_store_range() return value check in sgx_setup_epc_section()
In sgx_setup_epc_section(), xa_store_range() is called to store EPC pages' owner section to an Xarray using physical addresses of those EPC pages as index. Currently, the return value of xa_store_range() is not checked, but actually it can fail (i.e. due to -ENOMEM).
Not checking the return value of xa_store_range() would result in the EPC section being used by SGX driver (and KVM SGX guests), but part or all of its EPC pages not being handled by the memory failure handling of EPC page. Such inconsistency should be avoided, even at the cost that this section won't be used by the kernel.
Add the missing check of the return value of xa_store_range(), and when it fails, clean up and fail to initialize the EPC section.
--- arch/x86/kernel/cpu/sgx/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/sgx/main.c +6 -2
@@ -632,8 +632,12 @@ static bool __init sgx_setup_epc_section(u64 phys_addr, u64 size, } section->phys_addr = phys_addr; -xa_store_range (&sgx_epc_address_space, section->phys_addr, - phys_addr + size -1 , section,GFP_KERNEL ); +if (xa_err (xa_store_range (&sgx_epc_address_space, section->phys_addr, + phys_addr + size -1 , section,GFP_KERNEL ))) { +vfree (section->pages); +memunmap (section->virt_addr); +return false; + }for (i =0 ; i < nr_pages; i++) { section->pages[i].section = index;
base-commit: ee56a283988d739c25d2d00ffb22707cb487ab47
Signature · 1 line
2.37.1