Re: [PATCH v3 5/9] mm/mprotect: add MM_CP_PERM_UPGRADE
From: Carlos López
Date: Wed Dec 02 2026 - 05:27:10 EST
On 11/26/26 3:12 PM, David Hildenbrand (Arm) wrote:
> On 11/15/26 23:03, Carlos López wrote:
>> On 11/13/26 7:51 PM, David Hildenbrand (Arm) wrote:
>>>> diff --git a/mm/mprotect.c b/mm/mprotect.c
>>>> index 84bcfe0281d3..8c0fcd10f5a3 100644
>>>> --- a/mm/mprotect.c
>>>> +++ b/mm/mprotect.c
>>>> @@ -767,6 +767,17 @@ static const struct mm_walk_ops prot_none_walk_ops = {
>>>> .walk_lock = PGWALK_WRLOCK,
>>>> };
>>>>
>>>> +static bool vma_flags_is_perm_upgrade(vma_flags_t old_vma_flags,
>>>> + vma_flags_t new_vma_flags)
>>>
>>> Two tab indent.
>>
>> Will fix
>>
>>>> +{
>>>> + vm_flags_t old = vma_flags_to_legacy(old_vma_flags);
>>>> + vm_flags_t new = vma_flags_to_legacy(new_vma_flags);
>>>> + /* VM_ACCOUNT does not affect page tables */
>>>> + vm_flags_t mask = VM_READ | VM_WRITE | VM_EXEC | VM_ACCOUNT;
>>>
>>> Why is VM_ACCOUNT a permission upgrade? At best it's "no change".
>>>
>>> What am I missing?
>>
>> It isn't, this just means to cover the case where mprotect(PROT_READ |
>> PROT_WRITE) on a private read-only VMA sets VM_ACCOUNT as well. Without
>> this, the change is not detected as an upgrade.
>
> Why is setting VM_ACCOUNT and upgrade for permissions?!
The mask contains the bits that may be added on a protection change that
is an upgrade. PROT_READ -> PROT_READ | PROT_WRITE | VM_ACCOUNT is an
upgrade, so VM_ACCOUNT needs to be in the mask to be detected as such.
> I'm sorry but this is all way to shaky and confusing.
>
> Take a step back and think how to do all of this cleanly without making this
> code here unmaintainable :)
>