Skip to content

Commit 66d3757

Browse files
hansendcIngo Molnar
authored andcommitted
mm/core, x86/mm/pkeys: Add arch_validate_pkey()
The syscall-level code is passed a protection key and need to return an appropriate error code if the protection key is bogus. We will be using this in subsequent patches. Note that this also begins a series of arch-specific calls that we need to expose in otherwise arch-independent code. We create a linux/pkeys.h header where we will put *all* the stubs for these functions. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Thomas 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/20160212210232.774EEAAB@viggo.jf.intel.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent e6bfb70 commit 66d3757

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ config X86
156156
select X86_DEV_DMA_OPS if X86_64
157157
select X86_FEATURE_NAMES if PROC_FS
158158
select ARCH_USES_HIGH_VMA_FLAGS if X86_INTEL_MEMORY_PROTECTION_KEYS
159+
select ARCH_HAS_PKEYS if X86_INTEL_MEMORY_PROTECTION_KEYS
159160

160161
config INSTRUCTION_DECODER
161162
def_bool y

arch/x86/include/asm/pkeys.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _ASM_X86_PKEYS_H
2+
#define _ASM_X86_PKEYS_H
3+
4+
#define arch_max_pkey() (boot_cpu_has(X86_FEATURE_OSPKE) ? 16 : 1)
5+
6+
#endif /*_ASM_X86_PKEYS_H */

include/linux/pkeys.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef _LINUX_PKEYS_H
2+
#define _LINUX_PKEYS_H
3+
4+
#include <linux/mm_types.h>
5+
#include <asm/mmu_context.h>
6+
7+
#ifdef CONFIG_ARCH_HAS_PKEYS
8+
#include <asm/pkeys.h>
9+
#else /* ! CONFIG_ARCH_HAS_PKEYS */
10+
#define arch_max_pkey() (1)
11+
#endif /* ! CONFIG_ARCH_HAS_PKEYS */
12+
13+
/*
14+
* This is called from mprotect_pkey().
15+
*
16+
* Returns true if the protection keys is valid.
17+
*/
18+
static inline bool validate_pkey(int pkey)
19+
{
20+
if (pkey < 0)
21+
return false;
22+
return (pkey < arch_max_pkey());
23+
}
24+
25+
#endif /* _LINUX_PKEYS_H */

mm/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,5 @@ config FRAME_VECTOR
672672

673673
config ARCH_USES_HIGH_VMA_FLAGS
674674
bool
675+
config ARCH_HAS_PKEYS
676+
bool

0 commit comments

Comments
 (0)