[patch 01/10] x86/fpu/signal: Clarify exception handling in restore_fpregs_from_user()

From: Thomas Gleixner
Date: Mon Aug 30 2021 - 12:27:27 EST


FPU restore from a signal frame can trigger various exceptions. The
exceptions are caught with an exception table entry. The handler of this
entry sets the error return value to the negated exception number.

Any other exception than #PF is fatal and recovery is not possible. This
relies on the fact that the #PF exception number is the same as EFAULT, but
that's not really obvious.

Check the error code for -X86_TRAP_PF instead of checking it for -EFAULT to
make it clear how that works.

There is still confusion due to the return code conversion which will be
cleaned up separately.

Suggested-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
---
arch/x86/kernel/fpu/signal.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
--- a/arch/x86/kernel/fpu/signal.c
+++ b/arch/x86/kernel/fpu/signal.c
@@ -13,6 +13,7 @@
#include <asm/fpu/xstate.h>

#include <asm/sigframe.h>
+#include <asm/trapnr.h>
#include <asm/trace/fpu.h>

static struct _fpx_sw_bytes fx_sw_reserved __ro_after_init;
@@ -275,7 +276,7 @@ static int restore_fpregs_from_user(void
fpregs_unlock();

/* Try to handle #PF, but anything else is fatal. */
- if (ret != -EFAULT)
+ if (ret != -X86_TRAP_PF)
return -EINVAL;

ret = fault_in_pages_readable(buf, size);