public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	Ingo Molnar <mingo@kernel.org>,
	Keith Lucas <keith.lucas@oracle.com>
Subject: Re: [PATCH v3 3/4] x86/pkeys: Update PKRU to enable all pkeys before XSAVE
Date: Wed, 08 May 2024 14:52:18 +0200	[thread overview]
Message-ID: <874jb8pit9.ffs@tglx> (raw)
In-Reply-To: <FF998E58-D109-45B1-9BD8-FEF873E2FA7A@oracle.com>

On Tue, May 07 2024 at 17:34, Aruna Ramakrishna wrote:
>> On May 7, 2024, at 9:47 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
>>
>> Also this lacks any justification why this enables all pkeys and how
>> that is the right thing to do instead of using init_pkru_value which
>> is what is set by fpu__clear_user_states() before going back to user
>> space. For signal handling this can be the only valid PKEY state unless
>> I'm missing something here.
>
> If the alt sig stack is protected by a different pkey (other than pkey 0), then
> this flow would need to enable that, along with the pkey for the thread’s 
> stack. Since the code has no way of knowing what pkey the altstack needs,
> it enables all for this brief window.

Again. The flow here is:

handle_signal()
  enable_access_to_altstack()

  ....

  fpu__clear_user_states()
    restore_fpregs_from_init_fpstate(XFEATURE_MASK_USER_RESTORE)
    os_xrstor(&init_fpstate, features_mask)
    pkru_write_default()
      write_pkru(init_pkru_value);  <- Loads the default PKRU value
           
return_to_user_space()

User space resumes with the default PKRU value and the first thing user
space does when entering the signal handler is to push stuff on the
signal stack.

If the signal stack is protected by a key which is not contained in
init_pkru_value then the application segfaults in a non recoverable way,
no?

So arguably it is sufficient to ensure that PKRU has the keys in
init_pkru_value enabled:

    sigpkru = read_pkru() & init_pkru_value;

If user space protects the task stack or the sigalt stack with a key
which is not in init_pkru_value then it does not matter at all whether
it dies in handle_signal() or later when returning to user space, no?

I'm not fundamentaly opposed to enable all keys, but I don't buy this
without a proper explanation why this has been chosen over enabling only
the absolute minimum access rights.

Thanks,

        tglx

  reply	other threads:[~2024-05-08 12:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 18:05 [PATCH v3 0/4] x86/pkeys: update PKRU to enable pkey 0 before Aruna Ramakrishna
2024-04-25 18:05 ` [PATCH v3 1/4] x86/pkeys: Signal handling function interface changes to accept PKRU as a parameter Aruna Ramakrishna
2024-05-07 12:16   ` Thomas Gleixner
2024-04-25 18:05 ` [PATCH v3 2/4] x86/pkeys: Add helper functions to update PKRU on sigframe Aruna Ramakrishna
2024-05-07 16:16   ` Thomas Gleixner
2024-05-07 17:15     ` Aruna Ramakrishna
2024-04-25 18:05 ` [PATCH v3 3/4] x86/pkeys: Update PKRU to enable all pkeys before XSAVE Aruna Ramakrishna
2024-05-07 16:47   ` Thomas Gleixner
2024-05-07 17:34     ` Aruna Ramakrishna
2024-05-08 12:52       ` Thomas Gleixner [this message]
2024-04-25 18:05 ` [PATCH v3 4/4] selftests/mm: Add new testcases for pkeys Aruna Ramakrishna
2024-05-07  3:17   ` kernel test robot
2024-05-07 12:05   ` Thomas Gleixner
2024-05-07 16:56     ` Thomas Gleixner
2024-05-07 18:04       ` Aruna Ramakrishna
2024-05-08 12:55         ` Thomas Gleixner

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=874jb8pit9.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=aruna.ramakrishna@oracle.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=keith.lucas@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --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