From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
selinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
bpf@vger.kernel.org, dri-devel@lists.freedesktop.org,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Oliver Upton" <oupton@kernel.org>,
kvmarm@lists.linux.dev, "Vasily Gorbik" <gor@linux.ibm.com>,
linux-perf-users@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>,
linux-scsi@vger.kernel.org, kvm@vger.kernel.org,
linux-s390@vger.kernel.org,
"Alexander Gordeev" <agordeev@linux.ibm.com>,
linux-rdma@vger.kernel.org
Subject: Re: [PATCH v3 04/40] mm: consistently validate VMA state after mmap[_prepare] hooks
Date: Thu, 17 Sep 2026 17:38:22 +0000 [thread overview]
Message-ID: <20260917173822.CB85A1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260917-b4-mmap-prepare-vma-flag-sanify-v3-4-4583d8a23bca@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mm: UAF window caused by premature vma_close() before unmap_region()
- [Medium] mm: resource leak on mmap_prepare validation failure
- [Medium] mm: file reference leak when validation fails after mmap hook file swap
--
commit e5484b6aabe21d13a57f4db7fafb6d19bb0c0c97
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Subject: mm: consistently validate VMA state after mmap[_prepare] hooks
This commit centralises and extends validation of VMA state after executing
a driver's f_op->mmap or f_op->mmap_prepare hooks. It enforces restrictions
such as immutable VMA boundaries and prevents upgrading mappings to writable
if previously read-only.
> diff --git a/mm/internal.h b/mm/internal.h
> --- a/mm/internal.h
> +++ b/mm/internal.h
[ ... ]
> @@ -225,8 +243,12 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
> {
[ ... ]
> + err = mmap_hook_validate(prev_start, prev_end, &prev_flags, vma);
> + if (unlikely(err)) {
> + vma->vm_start = prev_start;
> + vma->vm_end = prev_end;
> + vma_close(vma);
> }
[Severity: High]
Could calling vma_close() here create a use-after-free window?
If a driver's f_op->mmap hook succeeds and populates PTEs (for example, via
remap_pfn_range()), but mmap_hook_validate() subsequently fails, the
driver's .close hook will free its backing resources immediately.
However, the PTEs are not cleared until __mmap_new_file_vma() later handles
the error:
mm/vma.c:__mmap_new_file_vma() {
...
error = mmap_file(vma->vm_file, vma);
map->vm_file = vma->vm_file;
if (error) {
...
/* Undo any partial mapping done by a device driver. */
unmap_region(&unmap);
return error;
}
...
}
Does this leave the freed memory accessible to concurrent threads or lockless
GUP_fast walks through the stale PTEs until unmap_region() is reached?
[Severity: Medium]
Does this error path also leak the new file reference if a driver swaps the
file but then fails validation?
If a driver's mmap hook successfully replaces vma->vm_file (transferring a
new reference), mmap_file() updates map->vm_file. If mmap_hook_validate()
then fails, the error path in __mmap_new_file_vma() has this logic:
mm/vma.c:__mmap_new_file_vma() {
...
if (error) {
...
if (map_same_file(map))
fput(map->vm_file);
vma->vm_file = NULL;
...
}
}
Because map->vm_file was updated to the newly swapped file, map_same_file()
will evaluate to false. This skips fput(map->vm_file) and clears
vma->vm_file to NULL, which appears to leak the new file reference.
> diff --git a/mm/util.c b/mm/util.c
> --- a/mm/util.c
> +++ b/mm/util.c
[ ... ]
> @@ -1224,19 +1224,28 @@ EXPORT_SYMBOL(compat_set_desc_from_vma);
> int __compat_vma_mmap(struct vm_area_desc *desc,
> struct vm_area_struct *vma)
> {
[ ... ]
> + /* Perform any preparatory tasks for mmap action. */
> err = mmap_action_prepare(desc);
> - if (err) {
> - if (desc->vm_file != vma->vm_file)
> - fput(desc->vm_file);
> - return err;
> - }
> + if (err)
> + goto err_put;
> + /* Check the caller did nothing crazy. */
> + err = mmap_prepare_validate(&prev_desc, desc);
> + if (err)
> + goto err_put;
[Severity: Medium]
If mmap_prepare_validate() fails here, does this skip tearing down the
driver's prepared state?
The driver successfully executed its mmap_prepare hook prior to this check.
By jumping directly to err_put, the function returns an error without
invoking the descriptor's vm_ops->close hook, which might permanently leak
any resources or hardware state allocated during vfs_mmap_prepare().
> diff --git a/mm/vma.c b/mm/vma.c
> --- a/mm/vma.c
> +++ b/mm/vma.c
[ ... ]
> @@ -2862,6 +2882,11 @@ static int call_mmap_prepare(struct mmap_state *map,
> struct vm_area_desc *desc)
> {
[ ... ]
> + /* Check the caller did nothing crazy. */
> + err = mmap_prepare_validate(&prev_desc, desc);
> + if (err)
> + return err;
[Severity: Medium]
Similar to the compatibility layer above, does returning directly on
validation failure leak the resources allocated by vfs_mmap_prepare()?
Without calling the driver's close hook, it seems the driver has no way to
clean up its established state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917-b4-mmap-prepare-vma-flag-sanify-v3-0-4583d8a23bca@kernel.org?part=4
next prev parent reply other threads:[~2026-09-17 17:38 UTC|newest]
Thread overview: 186+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 16:22 [PATCH v3 00/40] mm: make VMA flag semantics explicit, eliminate VM_SPECIAL Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 01/40] mm/vma: fix mmap_prepare file handling, remove file_doesnt_need_get Lorenzo Stoakes (ARM)
2026-09-17 16:54 ` sashiko-bot
2026-09-23 15:21 ` Suren Baghdasaryan
2026-09-23 15:46 ` Lorenzo Stoakes (ARM)
2026-09-23 15:59 ` Suren Baghdasaryan
2026-09-24 2:20 ` Zi Yan
2026-09-24 10:03 ` Lorenzo Stoakes (ARM)
2026-09-24 19:00 ` Liam R. Howlett
2026-09-25 9:12 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 02/40] mm/vma: predicate setting mmap_prepare VMA fields on new vma alloc Lorenzo Stoakes (ARM)
2026-09-17 17:07 ` sashiko-bot
2026-09-23 15:32 ` Suren Baghdasaryan
2026-09-23 15:53 ` Lorenzo Stoakes (ARM)
2026-09-23 16:09 ` Suren Baghdasaryan
2026-09-23 17:07 ` Lorenzo Stoakes (ARM)
2026-09-23 17:33 ` Lorenzo Stoakes (ARM)
2026-09-24 2:25 ` Zi Yan
2026-09-17 16:22 ` [PATCH v3 03/40] mm/vma: introduce and use vma_[flags_]can_merge() Lorenzo Stoakes (ARM)
2026-09-17 17:11 ` sashiko-bot
2026-09-23 16:23 ` Suren Baghdasaryan
2026-09-24 2:27 ` Zi Yan
2026-09-24 16:38 ` Gregory Price
2026-10-01 12:03 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 04/40] mm: consistently validate VMA state after mmap[_prepare] hooks Lorenzo Stoakes (ARM)
2026-09-17 17:38 ` sashiko-bot [this message]
2026-09-23 16:47 ` Suren Baghdasaryan
2026-09-23 17:00 ` Lorenzo Stoakes (ARM)
2026-09-24 2:52 ` Zi Yan
2026-09-24 10:06 ` Lorenzo Stoakes (ARM)
2026-09-24 17:17 ` Gregory Price
2026-09-25 12:51 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 05/40] mm/vma: ensure mmap_prepare doesn't set actions on a mergeable vma Lorenzo Stoakes (ARM)
2026-09-17 17:32 ` sashiko-bot
2026-09-24 18:00 ` Gregory Price
2026-09-25 9:51 ` Lorenzo Stoakes (ARM)
2026-09-24 19:28 ` Zi Yan
2026-09-25 9:55 ` Lorenzo Stoakes (ARM)
2026-09-25 7:28 ` Suren Baghdasaryan
2026-09-25 9:53 ` Lorenzo Stoakes (ARM)
2026-10-01 12:11 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 06/40] mm: make map_kernel_pages_[prepare,complete] internal and unexported Lorenzo Stoakes (ARM)
2026-09-17 17:17 ` sashiko-bot
2026-09-24 19:30 ` Zi Yan
2026-09-25 7:35 ` Suren Baghdasaryan
2026-09-29 15:58 ` Gregory Price
2026-10-01 12:11 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 07/40] mm/vma: tidy up map kernel pages enum values Lorenzo Stoakes (ARM)
2026-09-17 17:17 ` sashiko-bot
2026-09-24 19:30 ` Zi Yan
2026-09-25 7:37 ` Suren Baghdasaryan
2026-09-29 15:59 ` Gregory Price
2026-10-01 12:12 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 08/40] mm: add mmap action for discontiguous kernel page mapping Lorenzo Stoakes (ARM)
2026-09-17 17:25 ` sashiko-bot
2026-09-25 20:53 ` Zi Yan
2026-09-27 21:44 ` Suren Baghdasaryan
2026-09-29 11:11 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 09/40] docs: filesystems: update mmap_prepare docs for discontig kernel pgs Lorenzo Stoakes (ARM)
2026-09-17 17:32 ` sashiko-bot
2026-09-25 21:01 ` Zi Yan
2026-09-29 11:21 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 10/40] drivers/usb/mon: update to use mmap_prepare + map kernel pages Lorenzo Stoakes (ARM)
2026-09-17 17:29 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 11/40] infiniband: update hfi1 to use remap_vmalloc_range() Lorenzo Stoakes (ARM)
2026-09-17 17:36 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 12/40] selinux: reject writable opens of policy file, drop mmap shared/write check Lorenzo Stoakes (ARM)
2026-09-17 17:25 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 13/40] ALSA: pcm: use vm_insert_page() to map PCM status page Lorenzo Stoakes (ARM)
2026-09-17 17:34 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 14/40] bpf: arena: mark arena_map_mmap() mappings VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-09-17 17:25 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 15/40] mm/vma: add vma[_flags]_is_kernel_owned() predicates Lorenzo Stoakes (ARM)
2026-09-17 17:21 ` sashiko-bot
2026-09-26 1:37 ` Zi Yan
2026-10-01 12:36 ` David Hildenbrand (Arm)
2026-10-02 14:56 ` Lorenzo Stoakes (ARM)
2026-10-02 21:19 ` David Hildenbrand (Arm)
2026-10-03 9:03 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 16/40] mm/vma: only allow mmap to clear VMA_MAYWRITE_BIT if kernel-owned Lorenzo Stoakes (ARM)
2026-09-17 17:28 ` sashiko-bot
2026-09-26 2:07 ` Zi Yan
2026-09-26 2:17 ` Zi Yan
2026-09-26 10:06 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 17/40] mm/vma: add and use vma_[flags]_is_fixed_mapping Lorenzo Stoakes (ARM)
2026-09-17 17:27 ` sashiko-bot
2026-09-26 2:27 ` Zi Yan
2026-09-26 10:03 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 18/40] scsi: sg: convert mmap hook to mmap_prepare and rework Lorenzo Stoakes (ARM)
2026-09-17 17:34 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 19/40] fbdev: defio: assert FBINFO_VIRTFB, drop VM_IO, add VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-09-17 17:27 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 20/40] HSI: cmt_speech: convert mmap hook to mmap_prepare, refactor Lorenzo Stoakes (ARM)
2026-09-17 17:31 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 21/40] mm/gup: error out early on !VMA_MAYREAD_BIT VMAs Lorenzo Stoakes (ARM)
2026-09-17 17:30 ` sashiko-bot
2026-09-26 2:30 ` Zi Yan
2026-09-17 16:22 ` [PATCH v3 22/40] uprobes: remove VM_IO, set VM_MIXEDMAP for mapped kernel pages Lorenzo Stoakes (ARM)
2026-09-17 17:30 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 23/40] mm/mlock: clear VMA_LOCKED_MASK over mmap callback Lorenzo Stoakes (ARM)
2026-09-17 17:32 ` sashiko-bot
2026-10-01 15:20 ` Zi Yan
2026-10-02 12:26 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 24/40] mm/mlock: eliminate weird VMA_IO_BIT abuse and simplify Lorenzo Stoakes (ARM)
2026-09-17 17:43 ` sashiko-bot
2026-09-23 20:06 ` Zi Yan
2026-09-24 10:21 ` Lorenzo Stoakes (ARM)
2026-09-24 15:50 ` Zi Yan
2026-09-25 9:35 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 25/40] mm/vma: enforce that only kernel-owned mappings may set VMA_IO_BIT Lorenzo Stoakes (ARM)
2026-09-17 17:31 ` sashiko-bot
2026-09-29 2:12 ` Zi Yan
2026-09-17 16:22 ` [PATCH v3 26/40] mm: remove VMA_IO_BIT check in vma[_flags]_is_kernel_owned() Lorenzo Stoakes (ARM)
2026-09-17 17:34 ` sashiko-bot
2026-09-17 16:22 ` [PATCH v3 27/40] mm: remove hugetlb_inline.h Lorenzo Stoakes (ARM)
2026-09-17 17:31 ` sashiko-bot
2026-09-29 2:13 ` Zi Yan
2026-10-02 6:52 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 28/40] mm: rename is_vm_hugetlb_page() to vma_is_hugetlb() Lorenzo Stoakes (ARM)
2026-09-17 17:30 ` sashiko-bot
2026-09-29 2:14 ` Zi Yan
2026-10-02 6:53 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 29/40] mm: drop some redundant checks around hugetlb VMAs Lorenzo Stoakes (ARM)
2026-09-17 17:32 ` sashiko-bot
2026-09-29 2:36 ` Zi Yan
2026-10-02 6:54 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 30/40] mm/madvise: update is_valid_guard_vma() to use vma_can_merge() Lorenzo Stoakes (ARM)
2026-09-17 17:37 ` sashiko-bot
2026-09-29 2:38 ` Zi Yan
2026-10-02 6:57 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 31/40] mm/vma: introduce vma[_flags]_is_persistent() Lorenzo Stoakes (ARM)
2026-09-17 17:35 ` sashiko-bot
2026-09-30 2:00 ` Zi Yan
2026-10-02 6:59 ` David Hildenbrand (Arm)
2026-10-02 7:02 ` David Hildenbrand (Arm)
2026-10-02 7:05 ` David Hildenbrand (Arm)
2026-10-02 12:08 ` Lorenzo Stoakes (ARM)
2026-10-02 12:35 ` David Hildenbrand (Arm)
2026-10-02 12:48 ` Lorenzo Stoakes (ARM)
2026-10-02 13:11 ` David Hildenbrand (Arm)
2026-10-02 13:59 ` Lorenzo Stoakes (ARM)
2026-10-02 21:43 ` David Hildenbrand (Arm)
2026-10-03 13:16 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 32/40] mm/uffd: use predicates for userfaultfd checks Lorenzo Stoakes (ARM)
2026-09-17 17:38 ` sashiko-bot
2026-09-30 2:02 ` Zi Yan
2026-10-02 7:04 ` David Hildenbrand (Arm)
2026-10-02 12:35 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 33/40] mm/madvise: use predicates for madvise(..., MADV_DOFORK) Lorenzo Stoakes (ARM)
2026-09-17 17:37 ` sashiko-bot
2026-09-30 2:28 ` Zi Yan
2026-09-17 16:22 ` [PATCH v3 34/40] mm: eliminate VMA_SPECIAL_FLAGS usage when hugetlb explicitly tested Lorenzo Stoakes (ARM)
2026-09-17 17:45 ` sashiko-bot
2026-09-30 2:42 ` Zi Yan
2026-09-30 9:32 ` Lorenzo Stoakes (ARM)
2026-09-17 16:22 ` [PATCH v3 35/40] mm: eliminate VMA_SPECIAL_FLAGS check in lru_gen_look_around() Lorenzo Stoakes (ARM)
2026-09-17 17:41 ` sashiko-bot
2026-09-30 2:42 ` Zi Yan
2026-10-02 7:06 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 36/40] mm: avoid use of VMA_SPECIAL_FLAGS in migrate_vma_setup() Lorenzo Stoakes (ARM)
2026-09-17 17:40 ` sashiko-bot
2026-09-30 2:47 ` Zi Yan
2026-10-02 7:07 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 37/40] mm: eliminate VM_SPECIAL, VMA_SPECIAL_FLAGS Lorenzo Stoakes (ARM)
2026-09-17 17:44 ` sashiko-bot
2026-09-30 2:48 ` Zi Yan
2026-10-02 7:07 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 38/40] fuse: dax: do not set VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-09-17 17:38 ` sashiko-bot
2026-10-02 7:09 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 39/40] mm/huge_memory: remove vma_is_special_huge() Lorenzo Stoakes (ARM)
2026-09-17 17:38 ` sashiko-bot
2026-10-01 15:21 ` Zi Yan
2026-10-02 7:11 ` David Hildenbrand (Arm)
2026-09-17 16:22 ` [PATCH v3 40/40] mm/vma: introduce and use vma[_flags]_can_gup() Lorenzo Stoakes (ARM)
2026-09-17 17:36 ` sashiko-bot
2026-10-01 15:23 ` Zi Yan
2026-10-02 7:48 ` David Hildenbrand (Arm)
2026-10-02 16:11 ` Lorenzo Stoakes (ARM)
2026-09-17 21:23 ` [PATCH v3 00/40] mm: make VMA flag semantics explicit, eliminate VM_SPECIAL Andrew Morton
2026-09-23 8:57 ` Lorenzo Stoakes (ARM)
2026-09-25 22:06 ` Arnd Bergmann
2026-09-26 9:40 ` Lorenzo Stoakes (ARM)
2026-09-26 13:06 ` Arnd Bergmann
2026-09-26 13:22 ` Lorenzo Stoakes (ARM)
2026-09-26 17:14 ` Arnd Bergmann
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=20260917173822.CB85A1F00899@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@vger.kernel.org \
/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