x86: Implement thread_struct whitelist for hardened usercopy
authorKees Cook <keescook@chromium.org>
Wed, 16 Aug 2017 20:26:03 +0000 (13:26 -0700)
committerKees Cook <keescook@chromium.org>
Mon, 15 Jan 2018 20:08:05 +0000 (12:08 -0800)
This whitelists the FPU register state portion of the thread_struct for
copying to userspace, instead of the default entire struct. This is needed
because FPU register state is dynamically sized, so it doesn't bypass the
hardened usercopy checks.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Cc: Borislav Petkov <bp@suse.de>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Mathias Krause <minipli@googlemail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Rik van Riel <riel@redhat.com>
arch/x86/Kconfig
arch/x86/include/asm/processor.h

index 8eed3f94bfc774de5e3f344590f8889a999dea9c..9ac4ac1a856b73c73012710b9c5c029da63a5824 100644 (file)
@@ -116,6 +116,7 @@ config X86
        select HAVE_ARCH_MMAP_RND_COMPAT_BITS   if MMU && COMPAT
        select HAVE_ARCH_COMPAT_MMAP_BASES      if MMU && COMPAT
        select HAVE_ARCH_SECCOMP_FILTER
+       select HAVE_ARCH_THREAD_STRUCT_WHITELIST
        select HAVE_ARCH_TRACEHOOK
        select HAVE_ARCH_TRANSPARENT_HUGEPAGE
        select HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD if X86_64
index cc16fa882e3e760a40351cf3e7476ac9f25ffe00..2b037b7fe0ebacd22d2950c3aad7e73dcbaf9b0c 100644 (file)
@@ -492,6 +492,14 @@ struct thread_struct {
         */
 };
 
+/* Whitelist the FPU state from the task_struct for hardened usercopy. */
+static inline void arch_thread_struct_whitelist(unsigned long *offset,
+                                               unsigned long *size)
+{
+       *offset = offsetof(struct thread_struct, fpu.state);
+       *size = fpu_kernel_xstate_size;
+}
+
 /*
  * Thread-synchronous status.
  *