diff mbox

[intel-sgx-kernel-dev] Change mmap_sem lock to write in enclave_create

Message ID 1503081759-7979-1-git-send-email-angie.v.chinchilla@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Angie Chinchilla Aug. 18, 2017, 6:42 p.m. UTC
Change mmap_sem lock to write for writing to vma in enclave_create.

Signed-off-by: Angie Chinchilla <angie.v.chinchilla@intel.com>
---
 drivers/platform/x86/intel_sgx/sgx_ioctl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Jarkko Sakkinen Aug. 19, 2017, 5:16 p.m. UTC | #1
On Fri, Aug 18, 2017 at 02:42:39PM -0400, Angie Chinchilla wrote:
> Change mmap_sem lock to write for writing to vma in enclave_create.
> 
> Signed-off-by: Angie Chinchilla <angie.v.chinchilla@intel.com>

And why you would want to do that?

/Jarkko

> ---
>  drivers/platform/x86/intel_sgx/sgx_ioctl.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/platform/x86/intel_sgx/sgx_ioctl.c b/drivers/platform/x86/intel_sgx/sgx_ioctl.c
> index 1f2a269..85770ae 100644
> --- a/drivers/platform/x86/intel_sgx/sgx_ioctl.c
> +++ b/drivers/platform/x86/intel_sgx/sgx_ioctl.c
> @@ -524,17 +524,17 @@ static long sgx_ioc_enclave_create(struct file *filep, unsigned int cmd,
>  		goto out;
>  	}
>  
> -	down_read(&current->mm->mmap_sem);
> +	down_write(&current->mm->mmap_sem);
>  	vma = find_vma(current->mm, secs->base);
>  	if (!vma || vma->vm_ops != &sgx_vm_ops ||
>  	    vma->vm_start != secs->base ||
>  	    vma->vm_end != (secs->base + secs->size)) {
>  		ret = -EINVAL;
> -		up_read(&current->mm->mmap_sem);
> +		up_write(&current->mm->mmap_sem);
>  		goto out;
>  	}
>  	vma->vm_private_data = encl;
> -	up_read(&current->mm->mmap_sem);
> +	up_write(&current->mm->mmap_sem);
>  
>  	mutex_lock(&sgx_tgid_ctx_mutex);
>  	list_add_tail(&encl->encl_list, &encl->tgid_ctx->encl_list);
> -- 
> 2.7.4
> 
> _______________________________________________
> intel-sgx-kernel-dev mailing list
> intel-sgx-kernel-dev@lists.01.org
> https://lists.01.org/mailman/listinfo/intel-sgx-kernel-dev
diff mbox

Patch

diff --git a/drivers/platform/x86/intel_sgx/sgx_ioctl.c b/drivers/platform/x86/intel_sgx/sgx_ioctl.c
index 1f2a269..85770ae 100644
--- a/drivers/platform/x86/intel_sgx/sgx_ioctl.c
+++ b/drivers/platform/x86/intel_sgx/sgx_ioctl.c
@@ -524,17 +524,17 @@  static long sgx_ioc_enclave_create(struct file *filep, unsigned int cmd,
 		goto out;
 	}
 
-	down_read(&current->mm->mmap_sem);
+	down_write(&current->mm->mmap_sem);
 	vma = find_vma(current->mm, secs->base);
 	if (!vma || vma->vm_ops != &sgx_vm_ops ||
 	    vma->vm_start != secs->base ||
 	    vma->vm_end != (secs->base + secs->size)) {
 		ret = -EINVAL;
-		up_read(&current->mm->mmap_sem);
+		up_write(&current->mm->mmap_sem);
 		goto out;
 	}
 	vma->vm_private_data = encl;
-	up_read(&current->mm->mmap_sem);
+	up_write(&current->mm->mmap_sem);
 
 	mutex_lock(&sgx_tgid_ctx_mutex);
 	list_add_tail(&encl->encl_list, &encl->tgid_ctx->encl_list);