staticinlinebool mm_pkey_is_allocated(struct mm_struct *mm, int pkey)
{ if (pkey < 0 || pkey >= arch_max_pkey()) returnfalse;
/* Reserved keys are never allocated. */ if (__mm_pkey_is_reserved(pkey)) returnfalse;
return __mm_pkey_is_allocated(mm, pkey);
}
/* * Returns a positive, 5-bit key on success, or -1 on failure. * Relies on the mmap_lock to protect against concurrency in mm_pkey_alloc() and * mm_pkey_free().
*/ staticinlineint mm_pkey_alloc(struct mm_struct *mm)
{ /* * Note: this is the one and only place we make sure that the pkey is * valid as far as the hardware is concerned. The rest of the kernel * trusts that only good, valid pkeys come out of here.
*/
u32 all_pkeys_mask = (u32)(~(0x0)); int ret;
if (!mmu_has_feature(MMU_FTR_PKEY)) return -1; /* * Are we out of pkeys? We must handle this specially because ffz() * behavior is undefined if there are no zeros.
*/ if (mm_pkey_allocation_map(mm) == all_pkeys_mask) return -1;
ret = ffz((u32)mm_pkey_allocation_map(mm));
__mm_pkey_allocated(mm, ret);
return ret;
}
staticinlineint mm_pkey_free(struct mm_struct *mm, int pkey)
{ if (!mmu_has_feature(MMU_FTR_PKEY)) return -1;
if (!mm_pkey_is_allocated(mm, pkey)) return -EINVAL;
__mm_pkey_free(mm, pkey);
return 0;
}
/* * Try to dedicate one of the protection keys to be used as an * execute-only protection key.
*/ externint execute_only_pkey(struct mm_struct *mm); externint __arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot, int pkey); staticinlineint arch_override_mprotect_pkey(struct vm_area_struct *vma, int prot, int pkey)
{ if (!mmu_has_feature(MMU_FTR_PKEY)) return 0;
/* * Is this an mprotect_pkey() call? If so, never override the value that * came from the user.
*/ if (pkey != -1) return pkey;
externint __arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsignedlong init_val); staticinlineint arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsignedlong init_val)
{ if (!mmu_has_feature(MMU_FTR_PKEY)) return -EINVAL;
/* * userspace should not change pkey-0 permissions. * pkey-0 is associated with every page in the kernel. * If userspace denies any permission on pkey-0, the * kernel cannot operate.
*/ if (pkey == 0) return init_val ? -EINVAL : 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.