diff options
-rw-r--r-- | arch/x86/include/asm/pkeys.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/arch/x86/include/asm/pkeys.h b/arch/x86/include/asm/pkeys.h index 34684adb6899..b3b09b98896d 100644 --- a/arch/x86/include/asm/pkeys.h +++ b/arch/x86/include/asm/pkeys.h | |||
@@ -46,6 +46,15 @@ extern int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, | |||
46 | static inline | 46 | static inline |
47 | bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) | 47 | bool mm_pkey_is_allocated(struct mm_struct *mm, int pkey) |
48 | { | 48 | { |
49 | /* | ||
50 | * "Allocated" pkeys are those that have been returned | ||
51 | * from pkey_alloc(). pkey 0 is special, and never | ||
52 | * returned from pkey_alloc(). | ||
53 | */ | ||
54 | if (pkey <= 0) | ||
55 | return false; | ||
56 | if (pkey >= arch_max_pkey()) | ||
57 | return false; | ||
49 | return mm_pkey_allocation_map(mm) & (1U << pkey); | 58 | return mm_pkey_allocation_map(mm) & (1U << pkey); |
50 | } | 59 | } |
51 | 60 | ||
@@ -82,12 +91,6 @@ int mm_pkey_alloc(struct mm_struct *mm) | |||
82 | static inline | 91 | static inline |
83 | int mm_pkey_free(struct mm_struct *mm, int pkey) | 92 | int mm_pkey_free(struct mm_struct *mm, int pkey) |
84 | { | 93 | { |
85 | /* | ||
86 | * pkey 0 is special, always allocated and can never | ||
87 | * be freed. | ||
88 | */ | ||
89 | if (!pkey) | ||
90 | return -EINVAL; | ||
91 | if (!mm_pkey_is_allocated(mm, pkey)) | 94 | if (!mm_pkey_is_allocated(mm, pkey)) |
92 | return -EINVAL; | 95 | return -EINVAL; |
93 | 96 | ||