powerpc: implementation for arch_override_mprotect_pkey()
arch independent code calls arch_override_mprotect_pkey() to return a pkey that best matches the requested protection. This patch provides the implementation. Signed-off-by: Ram Pai <linuxram@us.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
This commit is contained in:

committed by
Michael Ellerman

parent
013a91b39c
commit
87bbabbed8
@@ -322,3 +322,39 @@ int __execute_only_pkey(struct mm_struct *mm)
|
||||
mm->context.execute_only_pkey = execute_only_pkey;
|
||||
return execute_only_pkey;
|
||||
}
|
||||
|
||||
static inline bool vma_is_pkey_exec_only(struct vm_area_struct *vma)
|
||||
{
|
||||
/* Do this check first since the vm_flags should be hot */
|
||||
if ((vma->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) != VM_EXEC)
|
||||
return false;
|
||||
|
||||
return (vma_pkey(vma) == vma->vm_mm->context.execute_only_pkey);
|
||||
}
|
||||
|
||||
/*
|
||||
* This should only be called for *plain* mprotect calls.
|
||||
*/
|
||||
int __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot,
|
||||
int pkey)
|
||||
{
|
||||
/*
|
||||
* If the currently associated pkey is execute-only, but the requested
|
||||
* protection requires read or write, move it back to the default pkey.
|
||||
*/
|
||||
if (vma_is_pkey_exec_only(vma) && (prot & (PROT_READ | PROT_WRITE)))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* The requested protection is execute-only. Hence let's use an
|
||||
* execute-only pkey.
|
||||
*/
|
||||
if (prot == PROT_EXEC) {
|
||||
pkey = execute_only_pkey(vma->vm_mm);
|
||||
if (pkey > 0)
|
||||
return pkey;
|
||||
}
|
||||
|
||||
/* Nothing to override. */
|
||||
return vma_pkey(vma);
|
||||
}
|
||||
|
Reference in New Issue
Block a user