Re: [patch V3 64/66] x86/fpu: Return proper error codes from user access functions

From: Thomas Gleixner
Date: Wed Jun 23 2021 - 06:56:47 EST


On Wed, Jun 23 2021 at 10:30, Borislav Petkov wrote:
>> +/* Returns 0 or the negated trap number, which results in -EFAULT for #PF */
>> #define user_insn(insn, output, input...) \
>> ({ \
>> int err; \
>> @@ -94,14 +95,14 @@ static inline void fpstate_init_soft(str
>> might_fault(); \
>> \
>> asm volatile(ASM_STAC "\n" \
>> - "1:" #insn "\n\t" \
>> + "1: " #insn "\n" \
>> "2: " ASM_CLAC "\n" \
>> ".section .fixup,\"ax\"\n" \
>> - "3: movl $-1,%[err]\n" \
>> + "3: negl %%eax\n" \
>> " jmp 2b\n" \
>> ".previous\n" \
>> - _ASM_EXTABLE(1b, 3b) \
>> - : [err] "=r" (err), output \
>> + _ASM_EXTABLE_FAULT(1b, 3b) \
>> + : [err] "=a" (err), output \
>> : "0"(0), input); \
>> err; \
>
> Don't we wanna do the same for XSTATE_OP() too?
>
> Because restore_hwregs_from_user() could call
> xrstor_from_user_sigframe() too which ends up doing XRSTOR and latter
> can cause a #PF too.

Bah, right you are.