[PATCH 1/8] UBUNTU: SAUCE: ubuntu/sgx: backport fixes to 1.33
Tim Gardner
tim.gardner at canonical.com
Thu Aug 12 12:09:06 UTC 2021
BugLink: https://bugs.launchpad.net/bugs/1936240
https://github.com/intel/SGXDataCenterAttestationPrimitives
612c6ffd16cf9f6d5b2914c274cf280b460b5f8e ("Linux Driver: backport fixes to 1.33")
Signed-off-by: Tim Gardner <tim.gardner at canonical.com>
---
ubuntu/sgx/driver.c | 2 +-
ubuntu/sgx/encl.c | 1 +
ubuntu/sgx/ioctl.c | 15 ++++++++++-----
ubuntu/sgx/reclaim.c | 5 ++++-
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/ubuntu/sgx/driver.c b/ubuntu/sgx/driver.c
index bcca5a676eca4..7e3003b6237d9 100644
--- a/ubuntu/sgx/driver.c
+++ b/ubuntu/sgx/driver.c
@@ -123,7 +123,7 @@ static unsigned long sgx_get_unmapped_area(struct file *file,
unsigned long pgoff,
unsigned long flags)
{
- if (flags & MAP_PRIVATE)
+ if ((flags & MAP_TYPE) == MAP_PRIVATE)
return -EINVAL;
if (flags & MAP_FIXED)
diff --git a/ubuntu/sgx/encl.c b/ubuntu/sgx/encl.c
index 8e8e861d5c7e9..8dab735ca1c95 100644
--- a/ubuntu/sgx/encl.c
+++ b/ubuntu/sgx/encl.c
@@ -590,6 +590,7 @@ void sgx_encl_release(struct kref *ref)
if (encl->backing)
fput(encl->backing);
+ cleanup_srcu_struct(&encl->srcu);
WARN_ON_ONCE(!list_empty(&encl->mm_list));
/* Detect EPC page leak's. */
diff --git a/ubuntu/sgx/ioctl.c b/ubuntu/sgx/ioctl.c
index 79b8c80197659..0dd2f4ef970d5 100644
--- a/ubuntu/sgx/ioctl.c
+++ b/ubuntu/sgx/ioctl.c
@@ -332,7 +332,7 @@ static int __sgx_encl_add_page(struct sgx_encl *encl,
ret = get_user_pages(src, 1, 0, &src_page, NULL);
if (ret < 1)
- return ret;
+ return -EFAULT;
pginfo.secs = (unsigned long)sgx_epc_addr(encl->secs.epc_page);
pginfo.addr = SGX_ENCL_PAGE_ADDR(encl_page);
@@ -459,8 +459,11 @@ static int sgx_encl_add_page(struct sgx_encl *encl, unsigned long src,
* Destroy enclave on ENCLS failure as this means that EPC has been
* invalidated.
*/
- if (ret == -EIO)
+ if (ret == -EIO){
+ mutex_lock(&encl->lock);
sgx_encl_destroy(encl);
+ mutex_unlock(&encl->lock);
+ }
return ret;
}
@@ -802,8 +805,10 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
if (encl_flags & SGX_ENCL_IOCTL)
return -EBUSY;
- if (encl_flags & SGX_ENCL_DEAD)
- return -EFAULT;
+ if (encl_flags & SGX_ENCL_DEAD){
+ ret = -EFAULT;
+ goto out;
+ }
switch (cmd) {
case SGX_IOC_ENCLAVE_CREATE:
@@ -822,7 +827,7 @@ long sgx_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
ret = -ENOIOCTLCMD;
break;
}
-
+out:
atomic_andnot(SGX_ENCL_IOCTL, &encl->flags);
return ret;
diff --git a/ubuntu/sgx/reclaim.c b/ubuntu/sgx/reclaim.c
index 99ada8857aee1..1ba0cec6dba4b 100644
--- a/ubuntu/sgx/reclaim.c
+++ b/ubuntu/sgx/reclaim.c
@@ -45,6 +45,9 @@ static void sgx_sanitize_section(struct sgx_epc_section *section)
cond_resched();
}
+ spin_lock(§ion->lock);
+ list_splice(&secs_list, §ion->unsanitized_page_list);
+ spin_unlock(§ion->lock);
}
static int ksgxswapd(void *p)
@@ -469,11 +472,11 @@ void sgx_reclaim_pages(void)
continue;
skip:
- kref_put(&encl_page->encl->refcount, sgx_encl_release);
spin_lock(&sgx_active_page_list_lock);
list_add_tail(&epc_page->list, &sgx_active_page_list);
spin_unlock(&sgx_active_page_list_lock);
+ kref_put(&encl_page->encl->refcount, sgx_encl_release);
chunk[i] = NULL;
}
--
2.32.0
More information about the kernel-team
mailing list