linux-sgx.vger.kernel.org archive mirror
 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, Andy Lutomirski <luto@kernel.org>
Subject: Re: [PATCH] x86/sgx: Pass userspace source address directly to EADD
Date: Tue, 27 Aug 2019 15:30:54 +0300	[thread overview]
Message-ID: <20190827123054.yopo4we3joawsy5z@linux.intel.com> (raw)
In-Reply-To: <20190827012049.GB25260@linux.intel.com>

On Mon, Aug 26, 2019 at 06:20:49PM -0700, Sean Christopherson wrote:
> On Mon, Aug 26, 2019 at 09:32:06AM +0300, Jarkko Sakkinen wrote:
> > On Thu, Aug 22, 2019 at 07:10:09PM -0700, Sean Christopherson wrote:
> > > Invoke EADD with the userspace source address instead of first copying
> > > the data to a kernel page to avoid the overhead of alloc_page() and
> > > copy_from_user().
> > > 
> > > Remove all pre-validation of TCS pages.  The source page is no longer
> > > readily available since it's not copied into the kernel, and validating
> > > the TCS essentially requires accessing the entire page since the vast
> > > majority of the TCS is reserved bytes.  Given that userspace can now
> > > cause EADD to fault simply by passing a bad pointer, validating the TCS
> > > to avoid faults on EADD provides little to no value.
> > > 
> > > Suggested-by: Andy Lutomirski <luto@kernel.org>
> > > Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> > 
> > I already merged this to my tree but just realized that the commit
> > message does not address why get_user_pages() is no option.
> 
> AFAICT, gup() would also work, but I don't think it gains us anything,
> e.g. validating the TCS still doesn't work because nothing prevents
> userspace from scribbling the TCS page after it's checked by the kernel.
> If we run into a scenario where we need to check the TCS, e.g. to prevent
> using a feature the kernel doesn't support, then we'd have no choice but
> to copy it into kernel memory[*].
> 
> Going with gup() would be a little more code, and maybe an imperceptibly
> small performance hit, but otherwise the two options are more or less the
> same.
> 
> I (obviously) have a slight preference for passing the userspace address
> directly to EADD, but I'm ok with either approach unless the gup code ends
> up being particularly ugly.
> 
> [*] While typing this out I realized we *must* copy the SECS into kernel
>     memory for ECREATE, otherwise the kernel would be susceptible to
>     TOCTOU attacks on the allowed attributes.  Probably worth a comment.

Lets stick to what was merged.

/Jarkko

      reply	other threads:[~2019-08-27 12:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23  2:10 [PATCH] x86/sgx: Pass userspace source address directly to EADD Sean Christopherson
2019-08-23 13:44 ` Jarkko Sakkinen
2019-08-26  6:32 ` Jarkko Sakkinen
2019-08-27  1:20   ` Sean Christopherson
2019-08-27 12:30     ` 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=20190827123054.yopo4we3joawsy5z@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    --cc=luto@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 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).