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

From: Edgecombe, Rick P
Date: Fri Apr 26 2024 - 12:33:48 EST


On Fri, 2024-04-26 at 09:13 -0700, Jeff Xu wrote:
> > > I’m wary about reordering anything here. Also, this code is not aware of
> > > the altstack permissions. I’m wondering if wrpkru(0) is needed here too.
> > >
> > We can't change PKRU after restore_sigcontext,  the calling thread
> > would have PKRU 0, not the original PKRU from before handling the
> > signal.
>
> probably putting restore_altstack ahead of restore_sigcontext would be
> good enough.
> restore_altstack doesn't seem to need to be after restore_sigcontex,
> it reads data
> from the sigframe and calls do_sigaltstack to update the current struct.

Just was CCed, and haven't reviewed the whole thread.

But I hit an issue with the ordering in setting up a signal frame. I noted that
the ordering in sigreturn was potentially wrong in the same way:
https://lore.kernel.org/lkml/20231107182251.91276-1-rick.p.edgecombe@xxxxxxxxx/

It might be useful analysis.