Skip to content

Commit dcf8729

Browse files
Ram Paimpe
authored andcommitted
powerpc: ability to create execute-disabled pkeys
powerpc has hardware support to disable execute on a pkey. This patch enables the ability to create execute-disabled keys. Signed-off-by: Ram Pai <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 2ddc53f commit dcf8729

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

arch/powerpc/include/uapi/asm/mman.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@
3030
#define MAP_STACK 0x20000 /* give out an address that is best suited for process/thread stacks */
3131
#define MAP_HUGETLB 0x40000 /* create a huge page mapping */
3232

33+
/* Override any generic PKEY permission defines */
34+
#define PKEY_DISABLE_EXECUTE 0x4
35+
#undef PKEY_ACCESS_MASK
36+
#define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\
37+
PKEY_DISABLE_WRITE |\
38+
PKEY_DISABLE_EXECUTE)
3339
#endif /* _UAPI_ASM_POWERPC_MMAN_H */

arch/powerpc/mm/pkeys.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ int pkey_initialize(void)
2424
{
2525
int os_reserved, i;
2626

27+
/*
28+
* We define PKEY_DISABLE_EXECUTE in addition to the arch-neutral
29+
* generic defines for PKEY_DISABLE_ACCESS and PKEY_DISABLE_WRITE.
30+
* Ensure that the bits a distinct.
31+
*/
32+
BUILD_BUG_ON(PKEY_DISABLE_EXECUTE &
33+
(PKEY_DISABLE_ACCESS | PKEY_DISABLE_WRITE));
34+
2735
/*
2836
* Disable the pkey system till everything is in place. A subsequent
2937
* patch will enable it.
@@ -177,10 +185,18 @@ int __arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
177185
unsigned long init_val)
178186
{
179187
u64 new_amr_bits = 0x0ul;
188+
u64 new_iamr_bits = 0x0ul;
180189

181190
if (!is_pkey_enabled(pkey))
182191
return -EINVAL;
183192

193+
if (init_val & PKEY_DISABLE_EXECUTE) {
194+
if (!pkey_execute_disable_supported)
195+
return -EINVAL;
196+
new_iamr_bits |= IAMR_EX_BIT;
197+
}
198+
init_iamr(pkey, new_iamr_bits);
199+
184200
/* Set the bits we need in AMR: */
185201
if (init_val & PKEY_DISABLE_ACCESS)
186202
new_amr_bits |= AMR_RD_BIT | AMR_WR_BIT;

0 commit comments

Comments
 (0)