All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: Re: [PATCH for_v23 3/9] x86/sgx: Fix a memory leak in sgx_encl_destroy()
Date: Tue, 15 Oct 2019 00:00:27 +0300	[thread overview]
Message-ID: <20191014210005.GT15552@linux.intel.com> (raw)
In-Reply-To: <20191010224947.GH23798@linux.intel.com>

On Thu, Oct 10, 2019 at 03:49:48PM -0700, Sean Christopherson wrote:
> On Thu, Oct 10, 2019 at 02:42:55PM -0700, Sean Christopherson wrote:
> > Delete an enclave page's entry in the radix tree regardless of whether
> > or not it has an associated EPC page.
> > 
> > Note, the reclaimer doesn't need the tree to reclaim EPC pages, i.e.
> > it's safe to delete the tree entry even if sgx_free_page() fails.
> > 
> > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > ---
> >  arch/x86/kernel/cpu/sgx/encl.c | 15 +++++++--------
> >  1 file changed, 7 insertions(+), 8 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/cpu/sgx/encl.c b/arch/x86/kernel/cpu/sgx/encl.c
> > index ea21d3737a32..68ec8944692a 100644
> > --- a/arch/x86/kernel/cpu/sgx/encl.c
> > +++ b/arch/x86/kernel/cpu/sgx/encl.c
> > @@ -468,15 +468,14 @@ void sgx_encl_destroy(struct sgx_encl *encl)
> >  
> >  	radix_tree_for_each_slot(slot, &encl->page_tree, &iter, 0) {
> >  		entry = *slot;
> > -		if (entry->epc_page) {
> > -			if (!sgx_free_page(entry->epc_page)) {
> > -				encl->secs_child_cnt--;
> > -				entry->epc_page = NULL;
> > -			}
> > -
> > -			radix_tree_delete(&entry->encl->page_tree,
> > -					  PFN_DOWN(entry->desc));
> > +		if (entry->epc_page &&
> > +		    !sgx_free_page(entry->epc_page)) {
> > +			encl->secs_child_cnt--;
> > +			entry->epc_page = NULL;
> >  		}
> > +
> > +		radix_tree_delete(&entry->encl->page_tree,
> > +				  PFN_DOWN(entry->desc));
> 
> Uh, just realized we're not freeing the entry itself.  That's obviously
> not good.  I'll spin a v2 to fix this proper.

OK.

So I applied 1/9 and 2/9 from this one. I guess they were good
(just a sanity check)?

/Jarkko

  reply	other threads:[~2019-10-14 21:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-10 21:42 [PATCH for_v23 0/9] x86/sgx: misc page related fixes Sean Christopherson
2019-10-10 21:42 ` [PATCH for_v23 1/9] x86/sgx: WARN once if an enclave is released with unfreed EPC pages Sean Christopherson
2019-10-14 20:31   ` Jarkko Sakkinen
2019-10-14 20:33     ` Jarkko Sakkinen
2019-10-14 23:56       ` Sean Christopherson
2019-10-10 21:42 ` [PATCH for_v23 2/9] x86/sgx: Do not EWB SECS if the enclave is dead Sean Christopherson
2019-10-14 20:58   ` Jarkko Sakkinen
2019-10-10 21:42 ` [PATCH for_v23 3/9] x86/sgx: Fix a memory leak in sgx_encl_destroy() Sean Christopherson
2019-10-10 22:49   ` Sean Christopherson
2019-10-14 21:00     ` Jarkko Sakkinen [this message]
2019-10-14 23:57       ` Sean Christopherson
2019-10-10 21:42 ` [PATCH for_v23 4/9] x86/sgx: WARN on any non-zero return from __eremove() Sean Christopherson
2019-10-10 21:42 ` [PATCH for_v23 5/9] x86/sgx: WARN only once if EREMOVE fails Sean Christopherson
2019-10-10 21:42 ` [PATCH for_v23 6/9] x86/sgx: Split second half of sgx_free_page() to a separate helper Sean Christopherson
2019-10-10 21:42 ` [PATCH for_v23 7/9] x86/sgx: Use the post-reclaim variant of __sgx_free_page() Sean Christopherson
2019-10-10 21:43 ` [PATCH for_v23 8/9] x86/sgx: Don't update free page count if EPC section allocation fails Sean Christopherson
2019-10-10 21:43 ` [PATCH for_v23 9/9] x86/sgx: Reinstate per EPC section free page counts Sean Christopherson

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=20191014210005.GT15552@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=sean.j.christopherson@intel.com \
    /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.