public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Dave Hansen <dave.hansen@intel.com>, <tony.luck@intel.com>,
	<dave.hansen@linux.intel.com>, <jarkko@kernel.org>,
	<tglx@linutronix.de>, <bp@alien8.de>, <luto@kernel.org>,
	<mingo@redhat.com>, <linux-sgx@vger.kernel.org>, <x86@kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86/sgx: Add poison handling to reclaimer
Date: Wed, 19 Jan 2022 12:47:22 -0800	[thread overview]
Message-ID: <effafec4-affc-297b-4b0e-aeca1884fa4f@intel.com> (raw)
In-Reply-To: <9cefa244-9830-c158-6112-b2c61a464632@intel.com>

Hi Dave,

On 1/19/2022 11:51 AM, Dave Hansen wrote:
> On 1/18/22 3:05 PM, Reinette Chatre wrote:
>> The machine check recovery handling in SGX added the changes
>> listed below to the freeing of pages in sgx_free_epc_page().
>> The SGX reclaimer contains an open coded version of
>> sgx_free_epc_page() and thus did not obtain the changes in
>> support of poison handling.
> 
> I was trying to decide if this is an urgent fix or not.  A more crisp
> problem statement might have helped in the changelog.
> 
> But, from what I can tell, the most probable troublesome scenario here
> would be something like:
> 
>  1. Machine check (#MC) occurs (asynchronous, !MF_ACTION_REQUIRED)
>  2. arch_memory_failure() called is eventually
>  3. (SGX) page->poison set to 1
>  4. Page is reclaimed
>  5. Page added to normal free lists by sgx_reclaim_pages()
>     ^ This is the bug
>  6. Page is reallocated by some innocent enclave, a second (synchronous)
>     in-kernel #MC is induced, probably during EADD instruction.
>     ^ This is the fallout from the bug
> 
> #6 is unfortunate and can be avoided if this patch is applied.
> 
> Basically, this patch ensures that a bad enclave page is isolated
> quickly and causes a minimal amount of collateral damage.  Is this a
> valid summary?
> 
> 	The SGX reclaimer code lacks page poison handling in its free
> 	path.  This can lead to completely avoidable machine checks if a
> 	poisoned page is freed and reallocated instead of being
> 	isolated.

As I understand this code it does look like a valid summary to me. One
detail is that the poison page handling is currently done for SECS pages
when they are freed by the reclaimer (via sgx_reclaimer_write()).

Thank you very much for the detailed analysis. Should I resend with
an improved commit message that contains your scenario description
and summary?

Reinette

  reply	other threads:[~2022-01-19 20:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18 23:05 [PATCH] x86/sgx: Add poison handling to reclaimer Reinette Chatre
2022-01-19 19:51 ` Dave Hansen
2022-01-19 20:47   ` Reinette Chatre [this message]
2022-01-19 20:56     ` Dave Hansen
2022-01-20 12:57 ` Jarkko Sakkinen
2022-01-20 15:28   ` Reinette Chatre

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=effafec4-affc-297b-4b0e-aeca1884fa4f@intel.com \
    --to=reinette.chatre@intel.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jarkko@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.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