mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Andy Lutomirski" <luto@kernel.org>
To: "Dave Hansen" <dave.hansen@intel.com>,
	"Stephen Röttger" <sroettger@google.com>
Cc: "Kees Cook" <keescook@chromium.org>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Jann Horn" <jannh@google.com>
Subject: Re: PKU usage improvements for threads
Date: Fri, 02 Sep 2022 10:18:36 -0700	[thread overview]
Message-ID: <ec3cb7fb-8161-487e-ba6e-5d260b88af80@www.fastmail.com> (raw)
In-Reply-To: <a96082e1-96ad-e92b-a5d0-d239123d943e@intel.com>



On Thu, Aug 25, 2022, at 7:36 AM, Dave Hansen wrote:
> On 8/25/22 05:30, Stephen Röttger wrote:
>>>> We were also thinking about if this should be a more generic feature instead of
>>>> being tied to pkeys. I.e. the doc above has an alternative proposal to introduce
>>>> something like a memory seal/unseal syscall.
>>>> I was personally leaning towards using pkeys for this for a few reasons:
>>>> * intuitively it would make sense to me to extend PKEY_DISABLE_ACCESS
>>>>   to also mean disable all changes to the memory, not just the data.
>>> It would make some sense, but we can't do it with the existing
>>> PKEY_DISABLE_ACCESS ABI.  It would surely break existing users if they
>>> couldn't munmap() memory that was PKEY_DISABLE_ACCESS.
>> Our thought was that this could be opt-in with a prctl().

I know Linux never copies other OSes, but OpenBSD is considering this:

https://undeadly.org/cgi?action=article;sid=20220902100648

If it works well, we could implement it.

>
> So, today, you have this:
>
> 	foo = malloc(PAGE_SIZE);
> 	pkey_mprotect(foo, PAGE_SIZE, READ|WRITE, pkey=1);
> 	munmap(foo); // <-- works fine
> 	mmap(hint=foo, ...); // now attacker controls &foo
>
> Which is problematic.  What you want instead is something like this:
>
> 	prctl(PR_ARCH_NO_MUNMAP_ON_PKEY); // or whatever
> 	foo = malloc(PAGE_SIZE);
> 	pkey_mprotect(foo, PAGE_SIZE, READ|WRITE, pkey=1);
> 	wrpkru(PKEY_DISABLE_ACCESS<<pkey*2);
> 	munmap(foo); // returns -EPERM (or whatever)
>
> Which requires the kernel to check when it's modifying a VMA (like the
> munmap() above) to see if PKRU _currently_ permits access to the VMA's
> contents.  If not, the kernel should refuse to modify the VMA.
>
> Like I said, I don't think this is _insane_, but I can see it breaking
> perfectly innocent things.  For instance, an app that today does a
> free() if pkey-assigned memory might work perfectly fine for a long time
> since that memory is rarely unmapped.  But, the minute that malloc()
> decides it needs to zap the memory, *malloc()* will fail.
>
> I also wonder how far these semantics would go.  Would madvise() work on
> these access-denied VMAs?
>
> My gut says that we don't want to mix up pkey semantics with this new
> mechanism.

  reply	other threads:[~2022-09-02 17:19 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
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 [this message]
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=ec3cb7fb-8161-487e-ba6e-5d260b88af80@www.fastmail.com \
    --to=luto@kernel.org \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.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®