public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Robert Kueffner <r.m.kueffner@gmail.com>
To: Kyle Huey <me@kylehuey.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Borislav Petkov <bp@alien8.de>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Robert Kueffner <r.m.kueffner@gmail.com>
Subject: Memory protection keys: Signal handlers crash if pkey0 is write-disabled
Date: Thu, 7 Sep 2023 17:22:10 -0400	[thread overview]
Message-ID: <FF299375-B46F-46D0-90A9-333959FE9380@gmail.com> (raw)

I am trying to establish memory protection domains in x86/linux using memory protection keys and the protection key register PKRU. 
Briefly:
(1) My program allocates a new protection key pkey1 and associated memory, and installs custom signal handlers for FPE+SEGV
(2) I define "user code" as code that should only operate in that memory, i.e. I want to disable write on pages with pkey0 by setting PKRU.WD0=true
(3) In this setup, if the user code causes an exception, the kernel causes an additional SEGV when switching to my signal handler
		(a) in case of user code causing SEGV this occurs upon return from sigprocmask()
		(b) in case of user code causing FPE this occurs right upon switching to the signal handler
(3) only happens when user code runs with WD0=true, my example code tests successfully as long as WD0=false

Is there some way to make this work, or is it generally not possible to successfully handle exceptions if WD0=true?

More details and a minimal implementation: https://unix.stackexchange.com/questions/755160/memory-protection-keys-exception-handler-crashes-if-pkey0-is-write-disabled

Robert

---

12th Gen Intel(R) Core(TM) i7-12700

Linux version 6.2.0-32-generic (buildd@lcy02-amd64-023) (x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.40) #32-Ubuntu SMP PREEMPT_DYNAMIC Mon Aug 14 10:03:50 UTC 2023

             reply	other threads:[~2023-09-07 21:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-07 21:22 Robert Kueffner [this message]
2023-09-07 21:31 ` Memory protection keys: Signal handlers crash if pkey0 is write-disabled Dave Hansen
2023-09-07 23:07   ` Robert Kueffner
2023-09-08 15:14     ` Dave Hansen
2023-09-08 15:43       ` Robert Kueffner

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=FF299375-B46F-46D0-90A9-333959FE9380@gmail.com \
    --to=r.m.kueffner@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=me@kylehuey.com \
    --cc=tglx@linutronix.de \
    /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