linux-stable/arch/x86/include/asm/fpu
Thomas Gleixner 43be46e896 x86/fpu: Sanitize xstateregs_set()
xstateregs_set() operates on a stopped task and tries to copy the provided
buffer into the task's fpu.state.xsave buffer.

Any error while copying or invalid state detected after copying results in
wiping the target task's FPU state completely including supervisor states.

That's just wrong. The caller supplied invalid data or has a problem with
unmapped memory, so there is absolutely no justification to corrupt the
target state.

Fix this with the following modifications:

 1) If data has to be copied from userspace, allocate a buffer and copy from
    user first.

 2) Use copy_kernel_to_xstate() unconditionally so that header checking
    works correctly.

 3) Return on error without corrupting the target state.

This prevents corrupting states and lets the caller deal with the problem
it caused in the first place.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121452.214903673@linutronix.de
2021-06-23 17:49:46 +02:00
..
api.h x86/cpufeatures: Force disable X86_FEATURE_ENQCMD and remove update_pasid() 2021-06-03 16:33:09 +02:00
internal.h x86/fpu: Move inlines where they belong 2021-06-23 17:49:46 +02:00
regset.h x86: switch to ->regset_get() 2020-07-27 14:31:07 -04:00
signal.h x86/signal: Introduce helpers to get the maximum signal frame size 2021-05-19 11:46:27 +02:00
types.h x86/fpu/xstate: Add supervisor PASID state for ENQCMD 2020-09-17 20:22:10 +02:00
xcr.h x86/fpu: Move xgetbv()/xsetbv() into a separate header 2020-09-07 19:54:20 +02:00
xstate.h x86/fpu: Sanitize xstateregs_set() 2021-06-23 17:49:46 +02:00