Skip to content
  • Dave Hansen's avatar
    x86/mm/pti: Clear Global bit more aggressively · eac7073a
    Dave Hansen authored
    The kernel image starts out with the Global bit set across the entire
    kernel image.  The bit is cleared with set_memory_nonglobal() in the
    configurations with PCIDs where the performance benefits of the Global bit
    are not needed.
    
    However, this is fragile.  It means that we are stuck opting *out* of the
    less-secure (Global bit set) configuration, which seems backwards.  Let's
    start more secure (Global bit clear) and then let things opt back in if
    they want performance, or are truly mapping common data between kernel and
    userspace.
    
    This fixes a bug.  Before this patch, there are areas that are unmapped
    from the user page tables (like like everything above 0xffffffff82600000 in
    the example below).  These have the hallmark of being a wrong Global area:
    they are not identical in the 'current_kernel' and 'current_user' page
    table dumps.  They are also read-write, which means they're much more
    likely to contain secrets.
    
    Before this patch:
    
    current_kernel:---[ High Kernel Mapping ]---
    current_kernel-0xffffffff80000000-0xffffffff81000000          16M                               pmd
    current_kernel-0xffffffff81000000-0xffffffff81e00000          14M     ro         PSE     GLB x  pmd
    current_kernel-0xffffffff81e00000-0xffffffff81e11000          68K     ro                 GLB x  pte
    current_kernel-0xffffffff81e11000-0xffffffff82000000        1980K     RW                 GLB NX pte
    current_kernel-0xffffffff82000000-0xffffffff82600000           6M     ro         PSE     GLB NX pmd
    current_kernel-0xffffffff82600000-0xffffffff82c00000           6M     RW         PSE     GLB NX pmd
    current_kernel-0xffffffff82c00000-0xffffffff82e00000           2M     RW                 GLB NX pte
    current_kernel-0xffffffff82e00000-0xffffffff83200000           4M     RW         PSE     GLB NX pmd
    current_kernel-0xffffffff83200000-0xffffffffa0000000         462M                               pmd
    
     current_user:---[ High Kernel Mapping ]---
     current_user-0xffffffff80000000-0xffffffff81000000          16M                               pmd
     current_user-0xffffffff81000000-0xffffffff81e00000          14M     ro         PSE     GLB x  pmd
     current_user-0xffffffff81e00000-0xffffffff81e11000          68K     ro                 GLB x  pte
     current_user-0xffffffff81e11000-0xffffffff82000000        1980K     RW                 GLB NX pte
     current_user-0xffffffff82000000-0xffffffff82600000           6M     ro         PSE     GLB NX pmd
     current_user-0xffffffff82600000-0xffffffffa0000000         474M                               pmd
    
    After this patch:
    
    current_kernel:---[ High Kernel Mapping ]---
    current_kernel-0xffffffff80000000-0xffffffff81000000          16M                               pmd
    current_kernel-0xffffffff81000000-0xffffffff81e00000          14M     ro         PSE     GLB x  pmd
    current_kernel-0xffffffff81e00000-0xffffffff81e11000          68K     ro                 GLB x  pte
    current_kernel-0xffffffff81e11000-0xffffffff82000000        1980K     RW                     NX pte
    current_kernel-0xffffffff82000000-0xffffffff82600000           6M     ro         PSE     GLB NX pmd
    current_kernel-0xffffffff82600000-0xffffffff82c00000           6M     RW         PSE         NX pmd
    current_kernel-0xffffffff82c00000-0xffffffff82e00000           2M     RW                     NX pte
    current_kernel-0xffffffff82e00000-0xffffffff83200000           4M     RW         PSE         NX pmd
    current_kernel-0xffffffff83200000-0xffffffffa0000000         462M                               pmd
    
      current_user:---[ High Kernel Mapping ]---
      current_user-0xffffffff80000000-0xffffffff81000000          16M                               pmd
      current_user-0xffffffff81000000-0xffffffff81e00000          14M     ro         PSE     GLB x  pmd
      current_user-0xffffffff81e00000-0xffffffff81e11000          68K     ro                 GLB x  pte
      current_user-0xffffffff81e11000-0xffffffff82000000        1980K     RW                     NX pte
      current_user-0xffffffff82000000-0xffffffff82600000           6M     ro         PSE     GLB NX pmd
      current_user-0xffffffff82600000-0xffffffffa0000000         474M                               pmd
    
    Fixes: 0f561fce
    
     ("x86/pti: Enable global pages for shared areas")
    Reported-by: default avatarHugh Dickins <hughd@google.com>
    Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
    Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Cc: keescook@google.com
    Cc: aarcange@redhat.com
    Cc: jgross@suse.com
    Cc: jpoimboe@redhat.com
    Cc: gregkh@linuxfoundation.org
    Cc: peterz@infradead.org
    Cc: torvalds@linux-foundation.org
    Cc: bp@alien8.de
    Cc: luto@kernel.org
    Cc: ak@linux.intel.com
    Cc: Kees Cook <keescook@google.com>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Juergen Gross <jgross@suse.com>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Andi Kleen <ak@linux.intel.com>
    Link: https://lkml.kernel.org/r/20180802225825.A100C071@viggo.jf.intel.com
    eac7073a