From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Haitao Huang <haitao.huang@linux.intel.com>
Cc: linux-sgx@vger.kernel.org,
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: Mon, 5 Oct 2020 06:43:53 +0300 [thread overview]
Message-ID: <20201005034353.GA159163@linux.intel.com> (raw)
In-Reply-To: <op.0rzvwhr9wjvjmi@mqcpg7oapc828.gar.corp.intel.com>
On Sun, Oct 04, 2020 at 10:27:43PM -0500, Haitao Huang wrote:
> 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
Great. That is a good reference point. Thank you.
v2 should work too but needs to be checked.
/Jarkko
prev parent reply other threads:[~2020-10-05 3:43 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
2020-10-05 3:43 ` Jarkko Sakkinen [this message]
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=20201005034353.GA159163@linux.intel.com \
--to=jarkko.sakkinen@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=haitao.huang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.