linux-sgx.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Haitao Huang" <haitao.huang@linux.intel.com>
To: linux-sgx@vger.kernel.org,
	"Jarkko Sakkinen" <jarkko.sakkinen@linux.intel.com>
Cc: "Sean Christopherson" <sean.j.christopherson@intel.com>,
	"Jethro Beekman" <jethro@fortanix.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>
Subject: Re: [PATCH] x86/sgx: Fix sgx_encl_may_map locking
Date: Sun, 04 Oct 2020 22:27:43 -0500	[thread overview]
Message-ID: <op.0rzvwhr9wjvjmi@mqcpg7oapc828.gar.corp.intel.com> (raw)
In-Reply-To: <20201005004120.105849-1-jarkko.sakkinen@linux.intel.com>

On Sun, 04 Oct 2020 19:41:20 -0500, Jarkko Sakkinen  
<jarkko.sakkinen@linux.intel.com> wrote:

> Fix the issue further discussed in:
>
> 1.  
> https://lore.kernel.org/linux-sgx/op.0rwbv916wjvjmi@mqcpg7oapc828.gar.corp.intel.com/
> 2.  
> https://lore.kernel.org/linux-sgx/20201003195440.GD20115@casper.infradead.org/
>
> Reported-by: Haitao Huang <haitao.huang@linux.intel.com>
> Cc: Sean Christopherson <sean.j.christopherson@intel.com>
> Cc: Jethro Beekman <jethro@fortanix.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  arch/x86/kernel/cpu/sgx/encl.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kernel/cpu/sgx/encl.c  
> b/arch/x86/kernel/cpu/sgx/encl.c
> index ae45f8f0951e..a225e96c7a39 100644
> --- a/arch/x86/kernel/cpu/sgx/encl.c
> +++ b/arch/x86/kernel/cpu/sgx/encl.c
> @@ -304,11 +304,10 @@ int sgx_encl_may_map(struct sgx_encl *encl,  
> unsigned long start,
>  		     unsigned long end, unsigned long vm_flags)
>  {
>  	unsigned long vm_prot_bits = vm_flags & (VM_READ | VM_WRITE | VM_EXEC);
> -	unsigned long idx_start = PFN_DOWN(start);
> -	unsigned long idx_end = PFN_DOWN(end - 1);
> +	unsigned long start_i = PFN_DOWN(start);
> +	unsigned long end_i = PFN_DOWN(end - 1);
>  	struct sgx_encl_page *page;
> -
> -	XA_STATE(xas, &encl->page_array, idx_start);
> +	int i;
> 	/*
>  	 * Disallow READ_IMPLIES_EXEC tasks as their VMA permissions might
> @@ -317,9 +316,14 @@ int sgx_encl_may_map(struct sgx_encl *encl,  
> unsigned long start,
>  	if (current->personality & READ_IMPLIES_EXEC)
>  		return -EACCES;
> -	xas_for_each(&xas, page, idx_end)
> +	for (i = start_i; i <= end_i; i++) {
> +		mutex_lock(&encl->lock);
> +		page = xa_load(&encl->page_array, i);
> +		mutex_unlock(&encl->lock);
> +
>  		if (!page || (~page->vm_max_prot_bits & vm_prot_bits))
>  			return -EACCES;
> +	}
> 	return 0;
>  }

Works with no PROVE_LOCKING complaints.
Haitao

  reply	other threads:[~2020-10-05  3:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05  0:41 [PATCH] x86/sgx: Fix sgx_encl_may_map locking Jarkko Sakkinen
2020-10-05  3:27 ` Haitao Huang [this message]
2020-10-05  3:43   ` Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=op.0rzvwhr9wjvjmi@mqcpg7oapc828.gar.corp.intel.com \
    --to=haitao.huang@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=jethro@fortanix.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).