Re: [patch V2 00/14] x86/fpu: Mop up XSAVES and related damage

From: Dave Hansen
Date: Mon Jun 07 2021 - 09:36:56 EST


On 6/7/21 6:02 AM, Thomas Gleixner wrote:
> On Sun, Jun 06 2021 at 01:47, Thomas Gleixner wrote:
>> P.S: I picked up Dave's PKRU series from
> and while looking deeper at that I found the following existing
> inconsistency vs. PKRU:
>
> On exec() the kernel sets PKRU to the default value which is as
> restrictive as possible.
>
> But on sigrestore PKRU when the init optimization is used PKRU is reset
> to the hardware default (0), which is as permissive as possible:
>
> 1) On XRSTOR from user and the signal handler cleared the PKRU feature
> bit in xsave.header.xfeatures. That's true for the fast and the
> slow path.
>
> 2) For the fx_only case which loads the init_fpstate (with my fixes
> applied that's not longer the case)
>
> So that's inconsistent at best.
>
> As the kernel defines the "init" behaviour of PKRU as non-permissive
> on exec() it should do so consequently in sigrestore as well.

Agreed. The kernel has essentially picked its own init value for PKRU,
separate from the hardware init value. It should be applied consistently.

By the way, are you talking specifically about the _error_ paths where
the kernel is unable to XRSTOR the signal XSAVE buffer for some reason,
and tries to apply either init_fpu or the hardware init state instead?