All of lore.kernel.org
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@suse.de>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andy Lutomirski <luto@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Fenghua Yu <fenghua.yu@intel.com>,
	Tony Luck <tony.luck@intel.com>,
	Yu-cheng Yu <yu-cheng.yu@intel.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Kan Liang <kan.liang@linux.intel.com>
Subject: Re: [patch V3 64/66] x86/fpu: Return proper error codes from user access functions
Date: Wed, 23 Jun 2021 10:30:32 +0200	[thread overview]
Message-ID: <YNLxKB9a6XQHW+w3@zn.tnic> (raw)
In-Reply-To: <20210618143451.682092608@linutronix.de>

On Fri, Jun 18, 2021 at 04:19:27PM +0200, Thomas Gleixner wrote:
> When *RSTOR from user memory raises an exception there is no way to
> differentiate them. That's bad because it forces the slow path even when
> the failure was not a fault. If the operation raised eg. #GP then going
> through the slow path is pointless.
> 
> Use _ASM_EXTABLE_FAULT() which stores the trap number and let the exception
> fixup return the negated trap number as error.
> 
> This allows to seperate the fast path and let it handle faults directly and

separate

> avoid the slow path for all other exceptions.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  arch/x86/include/asm/fpu/internal.h |    9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> --- a/arch/x86/include/asm/fpu/internal.h
> +++ b/arch/x86/include/asm/fpu/internal.h
> @@ -87,6 +87,7 @@ extern void fpstate_init_soft(struct swr
>  static inline void fpstate_init_soft(struct swregs_state *soft) {}
>  #endif
>  
> +/* 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.

Hmm.

-- 
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg

  reply	other threads:[~2021-06-23  8:30 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-18 14:18 [patch V3 00/66] x86/fpu: Spring cleaning and PKRU sanitizing Thomas Gleixner
2021-06-18 14:18 ` [patch V3 01/66] x86/fpu: x86/fpu: Preserve supervisor states in sanitize_restored_user_xstate() Thomas Gleixner
2021-06-19  8:34   ` Borislav Petkov
2021-06-22 11:45   ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner
2021-06-18 14:18 ` [patch V3 02/66] x86/fpu: Make init_fpstate correct with optimized XSAVE Thomas Gleixner
2021-06-18 20:41   ` Thomas Gleixner
2021-06-18 20:44     ` Borislav Petkov
2021-06-22 11:45   ` [tip: x86/urgent] " tip-bot2 for Thomas Gleixner
2021-06-18 14:18 ` [patch V3 03/66] x86/fpu: Fix copy_xstate_to_kernel() gap handling Thomas Gleixner
2021-06-19  9:41   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 04/66] x86/pkeys: Revert a5eff7259790 ("x86/pkeys: Add PKRU value to init_fpstate") Thomas Gleixner
2021-06-18 14:18 ` [patch V3 05/66] x86/fpu: Mark various FPU states __ro_after_init Thomas Gleixner
2021-06-18 14:18 ` [patch V3 06/66] x86/fpu: Make xfeatures_mask_all __ro_after_init Thomas Gleixner
2021-06-20  8:44   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 07/66] x86/fpu: Get rid of fpu__get_supported_xfeatures_mask() Thomas Gleixner
2021-06-20  9:02   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 08/66] x86/fpu: Remove unused get_xsave_field_ptr() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 09/66] x86/fpu: Move inlines where they belong Thomas Gleixner
2021-06-18 14:18 ` [patch V3 10/66] x86/fpu: Limit xstate copy size in xstateregs_set() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 11/66] x86/fpu: Sanitize xstateregs_set() Thomas Gleixner
2021-06-20 21:30   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 12/66] x86/fpu: Reject invalid MXCSR values in copy_kernel_to_xstate() Thomas Gleixner
2021-06-21 10:00   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 13/66] x86/fpu: Simplify PTRACE_GETREGS code Thomas Gleixner
2021-06-18 14:18 ` [patch V3 14/66] x86/fpu: Rewrite xfpregs_set() Thomas Gleixner
2021-06-21 10:20   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 15/66] x86/fpu: Fail ptrace() requests that try to set invalid MXCSR values Thomas Gleixner
2021-06-21 10:17   ` Thomas Gleixner
2021-06-18 14:18 ` [patch V3 16/66] x86/fpu: Clean up fpregs_set() Thomas Gleixner
2021-06-21 12:05   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 17/66] x86/fpu: Make copy_xstate_to_kernel() usable for [x]fpregs_get() Thomas Gleixner
2021-06-21 12:32   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 18/66] x86/fpu: Use copy_xstate_to_uabi_buf() in xfpregs_get() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 19/66] x86/fpu: Use copy_xstate_to_uabi_buf() in fpregs_get() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 20/66] x86/fpu: Remove fpstate_sanitize_xstate() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 21/66] x86/fpu/regset: Move fpu__read_begin() into regset Thomas Gleixner
2021-06-21 13:26   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 22/66] x86/fpu: Move fpu__write_begin() to regset Thomas Gleixner
2021-06-21 15:30   ` Borislav Petkov
2021-06-21 20:15     ` Thomas Gleixner
2021-06-18 14:18 ` [patch V3 23/66] x86/fpu: Get rid of using_compacted_format() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 24/66] x86/kvm: Avoid looking up PKRU in XSAVE buffer Thomas Gleixner
2021-06-18 14:18 ` [patch V3 25/66] x86/fpu: Cleanup arch_set_user_pkey_access() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 26/66] x86/fpu: Get rid of copy_supervisor_to_kernel() Thomas Gleixner
2021-06-18 14:18 ` [patch V3 27/66] x86/fpu: Rename copy_xregs_to_kernel() and copy_kernel_to_xregs() Thomas Gleixner
2021-06-21 18:00   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 28/66] x86/fpu: Rename copy_user_to_xregs() and copy_xregs_to_user() Thomas Gleixner
2021-06-21 19:44   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 29/66] x86/fpu: Rename fxregs related copy functions Thomas Gleixner
2021-06-21 23:00   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 30/66] x86/fpu: Rename fregs " Thomas Gleixner
2021-06-22  9:31   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 31/66] x86/fpu: Rename xstate copy functions which are related to UABI Thomas Gleixner
2021-06-22  9:38   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 32/66] x86/fpu: Deduplicate copy_uabi_from_user/kernel_to_xstate() Thomas Gleixner
2021-06-22 10:09   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 33/66] x86/fpu: Rename copy_fpregs_to_fpstate() to save_fpregs_to_fpstate() Thomas Gleixner
2021-06-22 10:16   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 34/66] x86/fpu: Get rid of the FNSAVE optimization Thomas Gleixner
2021-06-22 10:36   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 35/66] x86/fpu: Rename copy_kernel_to_fpregs() to restore_fpregs_from_kernel() Thomas Gleixner
2021-06-22 10:46   ` Borislav Petkov
2021-06-18 14:18 ` [patch V3 36/66] x86/fpu: Rename initstate copy functions Thomas Gleixner
2021-06-22 10:48   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 37/66] x86/fpu: Rename "dynamic" XSTATEs to "independent" Thomas Gleixner
2021-06-22 11:05   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 38/66] x86/fpu/xstate: Sanitize handling of independent features Thomas Gleixner
2021-06-21 20:42   ` Liang, Kan
2021-06-22 11:32   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 39/66] x86/pkeys: Move read_pkru() and write_pkru() Thomas Gleixner
2021-06-18 14:19 ` [patch V3 40/66] x86/fpu: Rename and sanitize fpu__save/copy() Thomas Gleixner
2021-06-22 13:51   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 41/66] x86/cpu: Sanitize X86_FEATURE_OSPKE Thomas Gleixner
2021-06-22 14:15   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 42/66] x86/pkru: Provide pkru_get_init_value() Thomas Gleixner
2021-06-18 14:19 ` [patch V3 43/66] x86/pkru: Provide pkru_write_default() Thomas Gleixner
2021-06-22 14:30   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 44/66] x86/cpu: Write the default PKRU value when enabling PKE Thomas Gleixner
2021-06-18 14:19 ` [patch V3 45/66] x86/fpu: Use pkru_write_default() in copy_init_fpstate_to_fpregs() Thomas Gleixner
2021-06-18 14:19 ` [patch V3 46/66] x86/fpu: Rename fpu__clear_all() to fpu_flush_thread() Thomas Gleixner
2021-06-22 14:40   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 47/66] x86/fpu: Clean up the fpu__clear() variants Thomas Gleixner
2021-06-22 15:38   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 48/66] x86/fpu: Rename __fpregs_load_activate() to fpregs_restore_userregs() Thomas Gleixner
2021-06-22 15:40   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 49/66] x86/fpu: Move FXSAVE_LEAK quirk info __copy_kernel_to_fpregs() Thomas Gleixner
2021-06-22 15:58   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 50/66] x86/fpu: Rename xfeatures_mask_user() to xfeatures_mask_uabi() Thomas Gleixner
2021-06-22 16:02   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 51/66] x86/fpu: Dont restore PKRU in fpregs_restore_userspace() Thomas Gleixner
2021-06-22 16:08   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 52/66] x86/fpu: Add PKRU storage outside of task XSAVE buffer Thomas Gleixner
2021-06-22 16:55   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 53/66] x86/fpu: Hook up PKRU into ptrace() Thomas Gleixner
2021-06-22 17:01   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 54/66] x86/fpu: Mask PKRU from kernel XRSTOR[S] operations Thomas Gleixner
2021-06-22 17:07   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 55/66] x86/fpu: Remove PKRU handling from switch_fpu_finish() Thomas Gleixner
2021-06-22 17:08   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 56/66] x86/fpu: Dont store PKRU in xstate in fpu_reset_fpstate() Thomas Gleixner
2021-06-22 17:10   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 57/66] x86/pkru: Remove xstate fiddling from write_pkru() Thomas Gleixner
2021-06-22 17:15   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 58/66] x86/fpu: Mark init_fpstate __ro_after_init Thomas Gleixner
2021-06-18 14:19 ` [patch V3 59/66] x86/fpu/signal: Move initial checks into fpu__sig_restore() Thomas Gleixner
2021-06-22 17:35   ` Borislav Petkov
2021-06-22 18:38     ` Thomas Gleixner
2021-06-22 18:43       ` Thomas Gleixner
2021-06-18 14:19 ` [patch V3 60/66] x86/fpu/signal: Remove the legacy alignment check Thomas Gleixner
2021-06-22 17:40   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 61/66] x86/fpu/signal: Sanitize the xstate check on sigframe Thomas Gleixner
2021-06-18 21:02   ` Andrew Cooper
2021-06-18 23:49     ` Thomas Gleixner
2021-06-22 19:10   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 62/66] x86/fpu/signal: Sanitize copy_user_to_fpregs_zeroing() Thomas Gleixner
2021-06-23  7:51   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 63/66] x86/fpu/signal: Split out the direct restore code Thomas Gleixner
2021-06-23  8:10   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 64/66] x86/fpu: Return proper error codes from user access functions Thomas Gleixner
2021-06-23  8:30   ` Borislav Petkov [this message]
2021-06-23 10:56     ` Thomas Gleixner
2021-06-18 14:19 ` [patch V3 65/66] x86/fpu/signal: Handle #PF in the direct restore path Thomas Gleixner
2021-06-23  8:45   ` Borislav Petkov
2021-06-18 14:19 ` [patch V3 66/66] x86/fpu/signal: Let xrstor handle the features to init Thomas Gleixner
2021-06-23  8:56   ` Borislav Petkov
2021-06-21 16:15 ` [patch V3 00/66] x86/fpu: Spring cleaning and PKRU sanitizing Yu, Yu-cheng
2021-06-21 21:53 ` Fenghua Yu
2021-06-21 22:22 ` Bae, Chang Seok
2021-06-22 20:02   ` Bae, Chang Seok
2021-06-24  0:06     ` Bae, Chang Seok
2021-06-22  1:59 ` Oliver Sang
2021-06-22  9:08   ` Thomas Gleixner
2021-06-22 18:56 ` Dey, Megha

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=YNLxKB9a6XQHW+w3@zn.tnic \
    --to=bp@suse.de \
    --cc=bigeasy@linutronix.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=fenghua.yu@intel.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=yu-cheng.yu@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.