diff --git a/sgx_encl.c b/sgx_encl.c index 8d7680f..a03c30a 100644 --- a/sgx_encl.c +++ b/sgx_encl.c @@ -252,10 +252,11 @@ static bool sgx_process_add_page_req(struct sgx_add_page_req *req, #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)) ret = vmf_insert_pfn(vma, encl_page->addr, PFN_DOWN(epc_page->pa)); + if (ret != VM_FAULT_NOPAGE) { #else ret = vm_insert_pfn(vma, encl_page->addr, PFN_DOWN(epc_page->pa)); -#endif if (ret) { +#endif sgx_put_backing(backing, 0); return false; } diff --git a/sgx_encl2.c b/sgx_encl2.c index 8e6fa9b..0df9b00 100644 --- a/sgx_encl2.c +++ b/sgx_encl2.c @@ -171,12 +171,15 @@ struct sgx_encl_page *sgx_encl_augment(struct vm_area_struct *vma, #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)) ret = vmf_insert_pfn(vma, encl_page->addr, PFN_DOWN(epc_page->pa)); + sgx_put_page(epc_va); + sgx_put_page(secs_va); + if (ret != VM_FAULT_NOPAGE) { #else ret = vm_insert_pfn(vma, encl_page->addr, PFN_DOWN(epc_page->pa)); -#endif sgx_put_page(epc_va); sgx_put_page(secs_va); if (ret) { +#endif pr_err("sgx: vm_insert_pfn failure with ret=%d\n", ret); goto out; } diff --git a/sgx_util.c b/sgx_util.c index 9faa59b..e9742d3 100644 --- a/sgx_util.c +++ b/sgx_util.c @@ -321,10 +321,11 @@ static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma, #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 20, 0)) rc = vmf_insert_pfn(vma, entry->addr, PFN_DOWN(entry->epc_page->pa)); + if (rc != VM_FAULT_NOPAGE) { #else rc = vm_insert_pfn(vma, entry->addr, PFN_DOWN(entry->epc_page->pa)); -#endif if (rc) { +#endif /* Kill the enclave if vm_insert_pfn fails; failure only occurs * if there is a driver bug or an unrecoverable issue, e.g. OOM. */