• Dave Hansen's avatar
    x86/mm/pkeys: Allow kernel to modify user pkey rights register · 84594296
    Dave Hansen authored
    The Protection Key Rights for User memory (PKRU) is a 32-bit
    user-accessible register.  It contains two bits for each
    protection key: one to write-disable (WD) access to memory
    covered by the key and another to access-disable (AD).
    
    Userspace can read/write the register with the RDPKRU and WRPKRU
    instructions.  But, the register is saved and restored with the
    XSAVE family of instructions, which means we have to treat it
    like a floating point register.
    
    The kernel needs to write to the register if it wants to
    implement execute-only memory or if it implements a system call
    to change PKRU.
    
    To do this, we need to create a 'pkru_state' buffer, read the old
    contents in to it, modify it, and then tell the FPU code that
    there is modified data in there so it can (possibly) move the
    buffer back in to the registers.
    
    This uses the fpu__xfeature_set_state() function that we defined
    in the previous patch.
    Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
    Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Andy Lutomirski <luto@amacapital.net>
    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Brian Gerst <brgerst@gmail.com>
    Cc: Dave Hansen <dave@sr71.net>
    Cc: Denys Vlasenko <dvlasenk@redhat.com>
    Cc: H. Peter Anvin <hpa@zytor.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Rik van Riel <riel@redhat.com>
    Cc: linux-mm@kvack.org
    Link: http://lkml.kernel.org/r/20160212210236.0BE13217@viggo.jf.intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    84594296
xstate.c 25.3 KB