linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	"H. Peter Anvin" <hpa@zytor.com>, Oleg Nesterov <oleg@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Brian Gerst <brgerst@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Christoph Hellwig <hch@lst.de>
Subject: Re: Rethinking sigcontext's xfeatures slightly for PKRU's benefit?
Date: Thu, 30 Jun 2016 10:36:27 -0700	[thread overview]
Message-ID: <CALCETrVZ=M1Gjqf3y7cwjmobAfUU03Nti6S==3CNsy-WH1mFmA@mail.gmail.com> (raw)
In-Reply-To: <CALCETrURNfj_bvev-rKXLNhHoS6FBvhKSMyzPt-N0YqMBHWW3g@mail.gmail.com>

On Mon, Dec 21, 2015 at 3:07 PM, Andy Lutomirski <luto@amacapital.net> wrote:
> On Mon, Dec 21, 2015 at 3:04 PM, Dave Hansen
> <dave.hansen@linux.intel.com> wrote:
>> On 12/18/2015 02:28 PM, Andy Lutomirski wrote:
>> ...
>>>> I could imagine that some kernel person would want to use even more
>>>> keys, but I think two fixed keys are kind of the minimal we'd want to
>>>> use.
>>>
>>> I imagine we'd reserve key 0 for normal page and key 1 for deny-read.
>>> Let me be a bit more concrete about what I'm suggesting:
>>>
>>> We'd have thread_struct.baseline_pkru.  It would start with key 0
>>> allowing all access and key 1 denying reads.
>>
>> Are you sure thread_struct is the right place for this?  I think of
>> signal handlers as a process-wide thing, and it seems a bit goofy if we
>> have the PKRU value in a signal handler depend on the PKRU of the thread
>> that got interrupted.
>
> I think you're right.  mmu_context_t might be a better choice.
>
>>
>>> We'd have a syscall like set_protection_key that could allocate unused
>>> keys and change the values of keys that have been allocated.  Those
>>> changes would be reflected in baseline_pkru.  Changes to keys 0 and 1
>>> in baseline_pkru would not be allowed.
>>
>> FWIW, I think we can do this without *actually* dedicating key 1 to
>> execute-only.  But that's a side issue.
>>
>>> Signal delivery would load baseline_pkru into the PKRU register.
>>> Signal restore would restore PKRU to its previous value.
>>
>> Do you really mean "its previous value" or are you OK with the existing
>> behavior which restores PKRU from the XSAVE buffer in the sigcontext?
>
> By "its previous value" I meant the value in the XSAVE buffer in the
> sigcontext.  So I think I'm okay with that :)
>
>>
>>> WRPKRU would, of course, override baseline_pkru, but it wouldn't
>>> change baseline_pkru.  The set_protection_key syscall would modify
>>> *both* real PKRU and baseline_pkru.
>>
>> How about this:
>>
>> We make baseline_pkru a process-wide baseline and store it in
>> mm->context.  That way, no matter which thread gets interrupted for a
>> signal, they see consistent values.  We only write to it when an app
>> _specifically_ asks for it to be updated with a special flag to
>> sys_pkey_set().
>>
>> When an app uses the execute-only support, we implicitly set the
>> read-disable bit in baseline_pkru for the execute-only pkey.
>
> Sounds good, I think.

Resurrecting an old thread, but:

Looking at your git tree, which I assume is a reasonably approximation
of your current patches, this seems to be unimplemented.  I, at least,
would be nervous about using PKRU for protection of critical data if
signal handlers are unconditionally exempt.

Also, the lazily allocated no-read key for execute-only is done in the
name of performance, but it results in odd semantics.  How much of a
performance win is preserving the init optimization of PKRU in
practice?  (I.e. how much faster are XSAVE and XRSTOR?)  I can't test
because even my Skylake laptop doesn't have PKRU.

--Andy

  reply	other threads:[~2016-06-30 17:37 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-18  1:48 Rethinking sigcontext's xfeatures slightly for PKRU's benefit? Andy Lutomirski
2015-12-18  2:13 ` Dave Hansen
2015-12-18  2:32   ` Andy Lutomirski
2015-12-18  2:52     ` Dave Hansen
2015-12-18  5:29       ` Andy Lutomirski
2015-12-18  6:43         ` H. Peter Anvin
2015-12-18 16:04           ` Andy Lutomirski
2015-12-18 16:56             ` Dave Hansen
2015-12-18 18:42             ` Dave Hansen
2015-12-18 19:21               ` Andy Lutomirski
2015-12-18 20:07                 ` Dave Hansen
2015-12-18 20:28                   ` Andy Lutomirski
2015-12-18 20:37                   ` Linus Torvalds
2015-12-18 20:49                     ` Andy Lutomirski
2015-12-18 20:58                       ` H. Peter Anvin
2015-12-18 21:02                         ` Andy Lutomirski
2015-12-18 21:08                           ` Dave Hansen
2015-12-18 21:04                       ` Linus Torvalds
2015-12-18 21:09                         ` Linus Torvalds
2015-12-18 21:12                         ` Dave Hansen
2015-12-18 21:45                           ` Linus Torvalds
2015-12-18 22:28                             ` Andy Lutomirski
2015-12-18 23:08                               ` Linus Torvalds
2015-12-18 23:16                                 ` Andy Lutomirski
2015-12-18 23:20                                   ` Linus Torvalds
2015-12-21 17:04                                   ` Dave Hansen
2015-12-21 22:52                                     ` Andy Lutomirski
2015-12-21 23:00                                       ` Dave Hansen
2015-12-21 23:02                                         ` Andy Lutomirski
2015-12-21 23:05                                           ` Dave Hansen
2015-12-21 23:04                               ` Dave Hansen
2015-12-21 23:07                                 ` Andy Lutomirski
2016-06-30 17:36                                   ` Andy Lutomirski [this message]
2016-06-30 21:25                                     ` Dave Hansen
2016-07-01 16:30                                       ` Andy Lutomirski
2015-12-29 23:48                             ` Dave Hansen
2015-12-18  8:32         ` Ingo Molnar
2015-12-18  8:59 ` Christoph Hellwig
2015-12-18 12:57   ` Borislav Petkov
2016-01-12 13:38     ` Ingo Molnar
2016-01-12 13:42       ` Christoph Hellwig
2016-01-13 10:48         ` Ingo Molnar

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='CALCETrVZ=M1Gjqf3y7cwjmobAfUU03Nti6S==3CNsy-WH1mFmA@mail.gmail.com' \
    --to=luto@amacapital.net \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hch@lst.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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).