From: Jeff Xu <jeffxu@chromium.org>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
David Hildenbrand <david@redhat.com>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
Pedro Falcato <pfalcato@suse.de>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Kees Cook <kees@kernel.org>,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v3 0/5] mseal cleanups, fixup MAP_PRIVATE file-backed case
Date: Thu, 24 Jul 2025 11:32:26 -0700 [thread overview]
Message-ID: <CABi2SkVVswRr+H5OWRcbFQSLq_457a0eXwn0OrtkcMEbGphz6w@mail.gmail.com> (raw)
In-Reply-To: <cover.1752687069.git.lorenzo.stoakes@oracle.com>
Hi Lorenzo,
Thanks for including me in this thread. I've just returned from
vacation and am catching up on my emails. I'll respond to each patch
separately in the following emails.
Could you consider adding mm/mseal.c to the HARDENING section of
MAINTAINERS? Please include Kees and linux-hardening in future emails
about mseal - Kees has been helping me with mseal since the beginning.
Thanks and regards,
-Jeff
On Wed, Jul 16, 2025 at 10:38 AM Lorenzo Stoakes
<lorenzo.stoakes@oracle.com> wrote:
>
> Perform a number of cleanups to the mseal logic. Firstly, VM_SEALED is
> treated differently from every other VMA flag, it really doesn't make sense
> to do this, so we start by making this consistent with everything else.
>
> Next we place the madvise logic where it belongs - in mm/madvise.c. It
> really makes no sense to abstract this elsewhere. In doing so, we go to
> great lengths to explain very clearly the previously very confusing logic
> as to what sealed mappings are impacted here.
>
> In doing so, we fix an existing logical oversight - previously we permitted
> an madvise() discard operation for a sealed, read-only MAP_PRIVATE
> file-backed mapping.
>
> However this is incorrect. To see why consider:
>
> 1. A MAP_PRIVATE R/W file-backed mapping is established.
> 2. The mapping is written to, which backs it with anonymous memory.
> 3. The mapping is mprotect()'d read-only.
> 4. The mapping is mseal()'d.
>
> At this point you have data that, once sealed, a user cannot alter, but a
> discard operation can unrecoverably remove. This contradicts the semantics
> of mseal(), so should not be permitted.
>
> We then abstract out and explain the 'are there are any gaps in this range
> in the mm?' check being performed as a prerequisite to mseal being
> performed.
>
> Finally, we simplify the actual mseal logic which is really quite
> straightforward.
>
>
> v3:
> * Propagated more tags, thanks everyone!
> * Updated 5/5 to assign curr_start in a smarter way as per Liam. Adjust
> code to more sensibly handle already-sealed case at the same time.
> * Updated 4/5 to not move range_contains_unmapped() for better diff.
> * Renamed can_modify_vma() to vma_is_sealed() and inverted the logic - this
> is far clearer than the nebulous 'can modify VMA'.
>
> v2:
> * Propagated tags, thanks everyone!
> * Updated can_madvise_modify() to a more logical order re: the checks
> performed, as per David.
> * Replaced vma_is_anonymous() check (which was, in the original code, a
> vma->vm_file or vma->vm_ops check) with a vma->vm_flags & VM_SHARED
> check - to explicitly check for shared mappings vs private to preclude
> MAP_PRIVATE-mapping file-baked mappings, as per David.
> * Made range_contains_unmapped() static and placed in mm/mseal.c to avoid
> encouraging any other internal users towards this rather silly pattern,
> as per Pedro and Liam.
> https://lore.kernel.org/all/cover.1752586090.git.lorenzo.stoakes@oracle.com/
>
> v1:
> https://lore.kernel.org/all/cover.1752497324.git.lorenzo.stoakes@oracle.com/
>
> Lorenzo Stoakes (5):
> mm/mseal: always define VM_SEALED
> mm/mseal: update madvise() logic
> mm/mseal: small cleanups
> mm/mseal: Simplify and rename VMA gap check
> mm/mseal: rework mseal apply logic
>
> include/linux/mm.h | 6 +-
> mm/madvise.c | 63 +++++++++-
> mm/mprotect.c | 2 +-
> mm/mremap.c | 2 +-
> mm/mseal.c | 157 +++++-------------------
> mm/vma.c | 4 +-
> mm/vma.h | 27 +---
> tools/testing/selftests/mm/mseal_test.c | 3 +-
> tools/testing/vma/vma_internal.h | 6 +-
> 9 files changed, 107 insertions(+), 163 deletions(-)
>
> --
> 2.50.1
next prev parent reply other threads:[~2025-07-24 18:32 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-16 17:38 [PATCH v3 0/5] mseal cleanups, fixup MAP_PRIVATE file-backed case Lorenzo Stoakes
2025-07-16 17:38 ` [PATCH v3 1/5] mm/mseal: always define VM_SEALED Lorenzo Stoakes
2025-07-24 18:34 ` Jeff Xu
2025-07-24 18:44 ` Lorenzo Stoakes
2025-07-16 17:38 ` [PATCH v3 2/5] mm/mseal: update madvise() logic Lorenzo Stoakes
2025-07-24 18:39 ` Jeff Xu
2025-07-24 18:56 ` David Hildenbrand
2025-07-24 22:18 ` David Hildenbrand
2025-07-24 19:07 ` Lorenzo Stoakes
2025-07-24 21:53 ` David Hildenbrand
2025-07-25 6:17 ` Lorenzo Stoakes
2025-07-25 16:22 ` Jeff Xu
2025-07-24 21:15 ` Kees Cook
2025-07-24 21:32 ` David Hildenbrand
2025-07-24 21:41 ` David Hildenbrand
2025-07-24 22:29 ` Kees Cook
2025-07-24 22:47 ` David Hildenbrand
2025-07-25 7:41 ` David Hildenbrand
2025-07-25 5:49 ` Lorenzo Stoakes
2025-07-25 16:21 ` Jeff Xu
2025-07-24 22:12 ` David Hildenbrand
2025-07-25 7:01 ` Lorenzo Stoakes
2025-07-25 7:38 ` David Hildenbrand
2025-07-25 8:53 ` Lorenzo Stoakes
2025-07-25 9:46 ` David Hildenbrand
2025-07-25 10:05 ` Lorenzo Stoakes
2025-07-25 10:10 ` David Hildenbrand
2025-07-25 10:17 ` Lorenzo Stoakes
2025-07-16 17:38 ` [PATCH v3 3/5] mm/mseal: small cleanups Lorenzo Stoakes
2025-07-24 18:40 ` Jeff Xu
2025-07-16 17:38 ` [PATCH v3 4/5] mm/mseal: Simplify and rename VMA gap check Lorenzo Stoakes
2025-07-24 18:40 ` Jeff Xu
2025-07-25 5:33 ` Lorenzo Stoakes
2025-07-16 17:38 ` [PATCH v3 5/5] mm/mseal: rework mseal apply logic Lorenzo Stoakes
2025-07-24 18:41 ` Jeff Xu
2025-07-24 18:32 ` Jeff Xu [this message]
2025-07-24 19:10 ` [PATCH v3 0/5] mseal cleanups, fixup MAP_PRIVATE file-backed case Lorenzo Stoakes
2025-07-25 6:40 ` Lorenzo Stoakes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABi2SkVVswRr+H5OWRcbFQSLq_457a0eXwn0OrtkcMEbGphz6w@mail.gmail.com \
--to=jeffxu@chromium.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jannh@google.com \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=pfalcato@suse.de \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).