On 11/03/2024 10:28, Amit Daniel Kachhap wrote:
+user_ptr_perms_t user_ptr_perms_from_prot(int prot, bool has_tag_access) +{
- user_ptr_perms_t perms = 0;
- if (!reserv_is_supported(current->mm))
return perms;
- if (mapping_may_have_prot_flag(prot, PROT_READ)) {
perms |= CHERI_PERM_LOAD;
if (has_tag_access)
perms |= CHERI_PERM_LOAD_CAP;
- }
- if (mapping_may_have_prot_flag(prot, PROT_WRITE)) {
perms |= CHERI_PERM_STORE;
if (has_tag_access)
perms |= (CHERI_PERM_STORE_CAP | CHERI_PERM_STORE_LOCAL_CAP);
- }
- if (mapping_may_have_prot_flag(prot, PROT_EXEC))
perms |= CHERI_PERM_EXECUTE;
- /* Fetch any extra architecture specific permissions */
- perms |= arch_user_ptr_perms_from_prot(PROT_MAX_EXTRACT(prot) ?
PROT_MAX_EXTRACT(prot) : prot, has_tag_access);
I got confused for a moment looking at arch_user_ptr_perms_from_prot(), I thought PROT_MAX() was not being taken into account. I think doing it this way is fine, but then we might as well do the same in this function: calculate a local prot value first and then directly test PROT_{READ,WRITE,EXEC} in it, without the mapping_may_have_prot_flag() helper. This way it will look more similar to the arch_ helper and there is less risk of confusion.
Kevin
- perms |= CHERI_PERMS_ROOTCAP;
- return perms;
+}