mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "x86@kernel.org" <x86@kernel.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	Keith Lucas <keith.lucas@oracle.com>,
	Andrew Brownsword <andrew.brownsword@oracle.com>,
	Dave Kleikamp <dave.kleikamp@oracle.com>,
	Joe Jin <joe.jin@oracle.com>
Subject: Re: PKRU issue while using alternate signal stack
Date: Wed, 21 Feb 2024 12:45:59 -0800	[thread overview]
Message-ID: <132c19fd-5969-4b46-be64-6f19f6927f10@intel.com> (raw)
In-Reply-To: <SJ0PR10MB447870F586BFD2F326F55C819F572@SJ0PR10MB4478.namprd10.prod.outlook.com>

On 2/21/24 11:54, Aruna Ramakrishna wrote:
> If the pkru_write_default() call were to move up the flow here, before 
> copy_fpstate_to_sigframe(), then the signal handling would work as 
> expected. But this code/flow is quite complicated, and we’d appreciate 
> some expert opinion.

First, I think you're not the first ones to report this, or want the
behavior tweaked.  I can't seem to find the thread at the moment, but
you might want to search to see if you have some fellow travelers here.

This is a bit of a chicken-and-egg problem.  We used to have some
complicated code to munge the (compacted+supervisor) kernel fpstate into
the (uncompacted+user) userspace sigframe.  That sucked, so we
simplified it to always use XSAVE to write the uncompacted+user format.

But that implementation choice fundamentally means that the register
state *MUST* match sigframe contents, at least at the time of XSAVE.
That's in direct conflict to your requirement that the sigframe be
written with different PKRU contents than what was in place at the time
that the exception happened.

That means we either need to abandon the xsave_to_user_sigframe()
approach, or we need to do something like:

	tmp_pkru = rdpkru();
	wrpkru(0);
	xsave_to_user_sigframe();
	put_user(pkru_sigframe_addr, tmp_pkru);

Which is horrid.

There are other games you could play with get_user_pages(), vmap() and
XSAVE but those would be even more horrid.

The simplest option is to just leave the altstacks writeable by all.

      reply	other threads:[~2024-02-21 20:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 19:54 Aruna Ramakrishna
2024-02-21 20:45 ` Dave Hansen [this message]

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=132c19fd-5969-4b46-be64-6f19f6927f10@intel.com \
    --to=dave.hansen@intel.com \
    --cc=andrew.brownsword@oracle.com \
    --cc=aruna.ramakrishna@oracle.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=dave.kleikamp@oracle.com \
    --cc=joe.jin@oracle.com \
    --cc=keith.lucas@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --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®