diff mbox

[intel-sgx-kernel-dev,3/4] intel_sgx: Lock the enlcave when updating va_pages

Message ID 1484081758-20302-4-git-send-email-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sean Christopherson Jan. 10, 2017, 8:55 p.m. UTC
The unlocked modification of encl->va_pages can cause segfaults if
two or more threads trigger a VA page allocation at the same time.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkine@linux.intel.com>
---
 drivers/platform/x86/intel_sgx_ioctl.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox

Patch

diff --git a/drivers/platform/x86/intel_sgx_ioctl.c b/drivers/platform/x86/intel_sgx_ioctl.c
index 3a4a8fa..b78c552 100644
--- a/drivers/platform/x86/intel_sgx_ioctl.c
+++ b/drivers/platform/x86/intel_sgx_ioctl.c
@@ -435,7 +435,10 @@  static int sgx_init_page(struct sgx_encl *encl,
 
 		va_page->epc_page = epc_page;
 		va_offset = sgx_alloc_va_slot(va_page);
+
+		mutex_lock(&encl->lock);
 		list_add(&va_page->list, &encl->va_pages);
+		mutex_unlock(&encl->lock);
 	}
 
 	entry->va_page = va_page;