[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a1691645-18ce-4e7f-846a-a5b498df948d@lucifer.local>
Date: Fri, 25 Jul 2025 18:53:54 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: Jeff Xu <jeffxu@...omium.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
"Liam R . Howlett" <Liam.Howlett@...cle.com>,
David Hildenbrand <david@...hat.com>, Vlastimil Babka <vbabka@...e.cz>,
Jann Horn <jannh@...gle.com>, Pedro Falcato <pfalcato@...e.de>,
linux-mm@...ck.org, linux-kernel@...r.kernel.org,
Kees Cook <kees@...nel.org>
Subject: Re: [PATCH v4 2/5] mm/mseal: update madvise() logic
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
Powered by blists - more mailing lists