mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: "Stephen Röttger" <sroettger@google.com>
Cc: Kees Cook <keescook@chromium.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org,
	Andy Lutomirski <luto@kernel.org>
Subject: Re: PKU usage improvements for threads
Date: Tue, 23 Aug 2022 11:12:24 -0700	[thread overview]
Message-ID: <b4f0dca5-1d15-67f7-4600-9a0a91e9d0bd@intel.com> (raw)
In-Reply-To: <CAEAAPHa3g0QwU=DZ2zVCqTCSh-+n2TtVKrQ07LvpwDjQ-F09gA@mail.gmail.com>

On 8/23/22 04:08, Stephen Röttger wrote:
> On Mon, Aug 22, 2022 at 11:11 PM Dave Hansen <dave.hansen@intel.com> wrote:
>> On 8/22/22 13:40, Kees Cook wrote:
>>> 1) It appears to be a bug that a thread without the correct PK can make
>>> VMAs covered by a separate PK, out from under other threads. (e.g. mmap
>>> a new mapping to wipe out the defined PK for it.) It seems that PK checks
>>> should be made when modifying VMAs.
>>
>> Could you give an example of this?  Is this something along the lines of
>> a mmap(MAP_FIXED) wiping out an earlier mapping?  Or, is it more subtle
>> than that?
> 
> Yes, that's one example. And the same applies to other operations on the
> VMA. E.g. another case we'd like to prevent would be munmap(addr) where
> addr is covered by a pkey to which the calling thread doesn't have access
> permissions to.

Yeah, that's something for which our defenses are quite weak.  But, it
also calls for a very generic mm/ solution and not something specific at
all to pkeys.

I assume that you wouldn't want to turn off *all* mmap(), MAP_FIXED or
munmap() in the process.  You just want to make one or more VMAs more or
less immutable.  That _sounds_ like a topic that would have broached at
some point in the past, although it doesn't ring any bells.

The concept would make a good lightning talk at Plumbers of LSF/MM.

>>> 2) It would be very helpful to have a mechanism for the signal stack to
>>> be PK aware, in the sense that the kernel would switch to a predefined
>>> PK. i.e. having a new interface to sigaltstack() which includes a PK.
>>
>> Are you thinking that when switching to the sigaltstack that it would
>> also pick up a specific PKRU value?  Or, that it would ensure that PKRU
>> allows access to the sigaltstack's pkey?
> 
> Either of those would work for us.
> 
>> Logically something like this:
>>
>>         stack_t sas = {
>>                 ss_sp = stack_ptr;
>>                 ss_flags = ... flags;
>>                 ss_size = ...;
>>                 ss_pkey = 12;
>>         };
>>
>> Then the kernel would set up RSP to point to ss_sp, and do (logically):
>>
>>    pkkru &= ~(3<<(12*2)); // clear Write and Access-disable for pkey-12
>>
>> before building the signal frame running the signal handler?
> 
> Yeah, that would work for our use case.
> We also have a doc discussing this in more detail :) :

That doesn't seem like it would be too much of a stretch.  There's a
delicate point when building the stack frame that the kernel would need
to move over to the new PKRU value to build the frame before it writes
the *OLD* value to the frame.  But, it's far from impossible.

I also bet we could do this with minimal new ABI.  There's already a
->ss_flags field.  We could assign a flag to mean that stack_t doesn't
end at '->ss_size' and that there's a pkey value *after* ss_size.  I do
think having a single pkey that is made accessible before signal entry
is a more flexible ABI than taking an explicit PKRU value.

I think that would allow just reusing sys_sigaltstack().


  reply	other threads:[~2022-08-23 19:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-22 20:40 Kees Cook
2022-08-22 21:11 ` Dave Hansen
2022-08-23 11:08   ` Stephen Röttger
2022-08-23 18:12     ` Dave Hansen [this message]
2022-08-23 18:24       ` Andy Lutomirski
2022-08-24  8:51         ` Stephen Röttger
2022-08-24 16:28           ` Dave Hansen
2022-08-24 16:45           ` Andy Lutomirski
2022-08-25 12:30             ` Stephen Röttger
2022-08-25 14:36               ` Dave Hansen
2022-09-02 17:18                 ` Andy Lutomirski
2022-09-03  0:16         ` Fangfei Yang
2022-09-03  0:14       ` Fangfei Yang
2022-09-06  4:34         ` Andy Lutomirski
2022-09-06  5:58           ` Fangfei Yang

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=b4f0dca5-1d15-67f7-4600-9a0a91e9d0bd@intel.com \
    --to=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=sroettger@google.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

all inboxes | Powered by JetHome®