Re: [RFC PATCH] x86/pkeys: update PKRU to enable pkey 0 before XSAVE

From: Dave Hansen
Date: Thu Mar 14 2024 - 14:30:08 EST


On 3/14/24 11:14, Aruna Ramakrishna wrote:
> I thought the PKRU value being reset in the signal handler was supposed
> to be the default behavior. In which case, this is a bug.
>
> "Signal Handler Behavior
> Each time a signal handler is invoked (including nested signals),
> the thread is temporarily given a new, default set of protection
> key rights that override the rights from the interrupted context.”
>
> (Ref: https://man7.org/linux/man-pages/man7/pkeys.7.html)

As the person who wrote those words, I can honestly say that there were
*ZERO* considerations for what the kernel's permissions were while
setting up the frame. I was assuming then and assume to this day that
it's practically impossible to turn off pkey-0 writes and get sane behavior.

If we want to lawyer-word the manpage, I'll just argue that "Each time a
signal handler is invoked" literally doesn't apply until the moment that
RIP is pointing back to userspace. :)

If this is truly about the manpage, then I'll happily amend the manpage
to say, "don't turn off pkey 0 access or else". I'd *MUCH* rather do
that than add more pkey munging to the kernel.

In other words, you're not going to spur me into action my thwapping me
with the manpage that I wrote. You've got to convince me that your new
use case is valid, this is the best way to support your new use case,
and that your implementation of the new feature is sane.