Re: [PATCH v4 2/5] mm/mseal: update madvise() logic
From: Lorenzo Stoakes
Date: Fri Jul 25 2025 - 13:54:44 EST
On Fri, Jul 25, 2025 at 10:28:57AM -0700, Jeff Xu wrote:
> > -static bool is_ro_anon(struct vm_area_struct *vma)
> > -{
> > - /* check anonymous mapping. */
> > - if (vma->vm_file || vma->vm_flags & VM_SHARED)
> > - return false;
>
> In this patch, the check for anonymous mapping are replaced with:
>
> if (!vma_is_anonymous(vma))
> return true;
>
> vma_is_anonymous() is implemented as following:
> static inline bool vma_is_anonymous(struct vm_area_struct *vma)
> {
> return !vma->vm_ops;
> }
>
> I'm curious to know if those two checks have the exact same scope.
>
> The original intention is only file-backed mapping can allow
> destructive madvise while sealed. I want to make sure that we don't
> accidentally increase the scope.
>
> Thanks and regards,
> -Jeff
Thanks, that's a good question.
So for a function to be mmap()'d and file-backed, vm_ops _must_ be
supplied.
You can see this in the fault-handler:
do_pte_mising()
-> do_fault()
if anon -> fault anon otherwise fault file-backed
So if this were not the case, you'd have file-backed mappings going into
the the anonymous fault handler logic.
This covers off MAP_PRIVATE mappings of file-backed mappings too, as this
is handled in do_fault() by:
} else if (!(vmf->flags & FAULT_FLAG_WRITE))
ret = do_read_fault(vmf);
else if (!(vma->vm_flags & VM_SHARED))
ret = do_cow_fault(vmf);
That does the CoW fault handling.
So the vma_is_anonymous_check() here should have the same semantics.
Cheers, Lorenzo