From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: linux-scsi@vger.kernel.org, selinux@vger.kernel.org,
"Oliver Upton" <oupton@kernel.org>,
"Christian Borntraeger" <borntraeger@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>,
linux-s390@vger.kernel.org, dri-devel@lists.freedesktop.org,
kvm@vger.kernel.org, "Alexander Gordeev" <agordeev@linux.ibm.com>,
kvmarm@lists.linux.dev, linux-trace-kernel@vger.kernel.org,
bpf@vger.kernel.org, "Marc Zyngier" <maz@kernel.org>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 03/39] mm: consistently validate VMA state after mmap[_prepare] hooks
Date: Tue, 08 Sep 2026 20:40:33 +0000 [thread overview]
Message-ID: <20260908204033.BE6501F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260908-b4-mmap-prepare-vma-flag-sanify-v1-3-dacf19cce22b@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Error cleanup path unmaps arbitrary memory if a driver illegally alters vma->vm_start.
- [High] Driver resources and file reference are leaked when mmap_prepare_validate() fails after a successful hook.
--
commit 7871b5bece83247c9fe3efaac4b928710f478390
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>
mm: consistently validate VMA state after mmap[_prepare] hooks
This commit introduces mmap_prepare_validate() and mmap_hook_validate() to
verify that mmap hooks do not perform unauthorized operations, such as
modifying the VMA start address. It applies these checks uniformly across
VMA creation paths.
> diff --git a/mm/internal.h b/mm/internal.h
> --- a/mm/internal.h
> +++ b/mm/internal.h
[ ... ]
> @@ -238,26 +259,14 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
> */
> if (unlikely(err || !vma->vm_ops))
> vma->vm_ops = &vma_dummy_vm_ops;
> + if (unlikely(err))
> + return err;
>
> + err = mmap_hook_validate(prev_start, &prev_flags, vma);
> + if (unlikely(err))
> + vma_close(vma);
>
> + return err;
> }
[Severity: High]
If a driver illegally alters vma->vm_start, mmap_hook_validate() will
correctly catch the violation and return -EINVAL. However, does this leave
the corrupted vma->vm_start in place when returning to the caller?
Looking at __mmap_new_file_vma(), the error handling path relies on
vma->vm_start:
error = mmap_file(vma->vm_file, vma);
if (error) {
UNMAP_STATE(unmap, vmi, vma, vma->vm_start, vma->vm_end,
map->prev, map->next);
...
unmap_region(&unmap);
return error;
}
If mmap_file() fails because the driver altered vma->vm_start, could
unmap_region() accidentally unmap arbitrary user memory using the corrupted
start address?
> diff --git a/mm/util.c b/mm/util.c
> --- a/mm/util.c
> +++ b/mm/util.c
[ ... ]
> @@ -1224,10 +1224,17 @@ EXPORT_SYMBOL(compat_set_desc_from_vma);
> int __compat_vma_mmap(struct vm_area_desc *desc,
> struct vm_area_struct *vma)
> {
> + struct vm_area_desc prev_desc;
> int err;
>
> + /* Derive state prior to mmap_prepare hook. */
> + compat_set_desc_from_vma(&prev_desc, desc->file, vma);
> /* Perform any preparatory tasks for mmap action. */
> err = mmap_action_prepare(desc);
> + if (err)
> + return err;
> + /* Check the caller did nothing crazy. */
> + err = mmap_prepare_validate(&prev_desc, desc);
> if (err)
> return err;
[Severity: High]
If mmap_prepare_validate() detects an invariant violation and returns an
error here, does this early return leak driver resources and the file
reference?
If the driver's mmap_prepare() hook succeeded, it may have allocated
resources (expecting them to be freed later via vm_ops->close) or placed
a new file reference in desc->vm_file. Since vma_close() is never called
and the local desc structure is discarded, it appears these resources
might be leaked.
> diff --git a/mm/vma.c b/mm/vma.c
> --- a/mm/vma.c
> +++ b/mm/vma.c
[ ... ]
> @@ -2800,10 +2855,16 @@ static int call_mmap_prepare(struct mmap_state *map,
> if (!desc->vm_ops)
> return -EINVAL;
>
> + /* Perform any preparatory tasks for mmap action. */
> err = call_action_prepare(map, desc);
> if (err)
> return err;
>
> + /* Check the caller did nothing crazy. */
> + err = mmap_prepare_validate(&prev_desc, desc);
> + if (err)
> + return err;
> +
> /* Update fields permitted to be changed. */
> map->pgoff = desc->pgoff;
[Severity: High]
This early return appears to have the same resource leak behavior as
__compat_vma_mmap() above. Would a validation failure here also skip
releasing driver resources or a newly assigned desc->vm_file before the VMA
is fully established?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260908-b4-mmap-prepare-vma-flag-sanify-v1-0-dacf19cce22b@kernel.org?part=3
next prev parent reply other threads:[~2026-09-08 20:40 UTC|newest]
Thread overview: 144+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 20:01 [PATCH 00/39] mm: make VMA flag semantics explicit, eliminate VM_SPECIAL Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` [PATCH 01/39] mm/vma: predicate setting mmap_prepare VMA fields on new vma alloc Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:42 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 02/39] mm/vma: introduce and use vma_[flags_]can_merge() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:27 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 03/39] mm: consistently validate VMA state after mmap[_prepare] hooks Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:40 ` sashiko-bot [this message]
2026-09-08 20:01 ` [PATCH 04/39] mm/vma: ensure mmap_prepare doesn't set actions on a mergeable vma Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:36 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 05/39] mm: make map_kernel_pages_[prepare,complete] internal and unexported Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:24 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 06/39] mm/vma: tidy up map kernel pages enum values Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:27 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 07/39] mm: add mmap action for discontiguous kernel page mapping Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:34 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 08/39] docs: filesystems: update mmap_prepare docs for discontig kernel pgs Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:38 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 09/39] drivers/usb/mon: update to use mmap_prepare + map kernel pages Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:35 ` sashiko-bot
2026-09-09 7:37 ` Greg Kroah-Hartman
2026-09-09 7:37 ` Greg Kroah-Hartman
2026-09-08 20:01 ` [PATCH 10/39] infiniband: update hfi1 to use remap_vmalloc_range() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:42 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 11/39] selinux: reject writable opens of policy file, drop mmap shared/write check Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:22 ` Jann Horn
2026-09-08 20:22 ` Jann Horn
2026-09-11 10:13 ` Lorenzo Stoakes (ARM)
2026-09-11 10:13 ` Lorenzo Stoakes (ARM)
2026-09-08 20:36 ` sashiko-bot
2026-09-10 18:11 ` Stephen Smalley
2026-09-10 18:11 ` Stephen Smalley
2026-09-11 10:16 ` Lorenzo Stoakes (ARM)
2026-09-11 10:16 ` Lorenzo Stoakes (ARM)
2026-09-11 15:05 ` Stephen Smalley
2026-09-11 15:05 ` Stephen Smalley
2026-09-08 20:01 ` [PATCH 12/39] ALSA: pcm: use vm_insert_page() to map PCM status page Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:45 ` sashiko-bot
2026-09-10 16:15 ` Takashi Iwai
2026-09-10 16:15 ` Takashi Iwai
2026-09-08 20:01 ` [PATCH 13/39] bpf: arena: mark arena_map_mmap() mappings VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:34 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 14/39] mm/vma: add vma[_flags]_is_kernel_owned() predicates Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:28 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 15/39] mm/vma: only allow mmap to clear VMA_MAYWRITE_BIT if kernel-owned Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:42 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 16/39] mm/vma: add and use vma_[flags]_is_fixed_mapping Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:42 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 17/39] scsi: sg: convert mmap hook to mmap_prepare and rework Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:37 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 18/39] fbdev: defio: assert FBINFO_VIRTFB, drop VM_IO, add VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:39 ` sashiko-bot
2026-09-11 11:05 ` Thomas Zimmermann
2026-09-11 11:05 ` Thomas Zimmermann
2026-09-08 20:01 ` [PATCH 19/39] HSI: cmt_speech: convert mmap hook to mmap_prepare, refactor Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:36 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 20/39] mm/gup: error out early on !VMA_MAYREAD_BIT VMAs Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:36 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 21/39] uprobes: remove VM_IO, set VM_MIXEDMAP for mapped kernel pages Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:36 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 22/39] mm/mlock: clear VMA_LOCKED_MASK over mmap callback Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:38 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 23/39] mm/mlock: eliminate weird VMA_IO_BIT abuse and simplify Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:47 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 24/39] mm/vma: enforce that only kernel-owned mappings may set VMA_IO_BIT Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:47 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 25/39] mm: remove VMA_IO_BIT check in vma[_flags]_is_kernel_owned() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:37 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 26/39] mm: remove hugetlb_inline.h Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:34 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 27/39] mm: rename is_vm_hugetlb_page() to vma_is_hugetlb() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:40 ` sashiko-bot
2026-09-09 11:09 ` Anup Patel
2026-09-09 11:09 ` Anup Patel
2026-09-09 11:22 ` Claudio Imbrenda
2026-09-09 11:30 ` Lorenzo Stoakes (ARM)
2026-09-09 13:20 ` Claudio Imbrenda
2026-09-09 12:07 ` Marc Zyngier
2026-09-09 12:07 ` Marc Zyngier
2026-09-08 20:01 ` [PATCH 28/39] mm: drop some redundant checks around hugetlb VMAs Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:39 ` sashiko-bot
2026-09-09 12:08 ` Marc Zyngier
2026-09-09 12:08 ` Marc Zyngier
2026-09-08 20:01 ` [PATCH 29/39] mm/madvise: update is_valid_guard_vma() to use vma_can_merge() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:45 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 30/39] mm/vma: introduce vma[_flags]_is_persistent() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:47 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 31/39] mm/uffd: use predicates for userfaultfd checks Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:45 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 32/39] mm/madvise: use predicates for madvise(..., MADV_DOFORK) Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:48 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 33/39] mm: eliminate VMA_SPECIAL_FLAGS usage when hugetlb explicitly tested Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:42 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 34/39] mm: eliminate VMA_SPECIAL_FLAGS check in lru_gen_look_around() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:45 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 35/39] mm: avoid use of VMA_SPECIAL_FLAGS in migrate_vma_setup() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:47 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 36/39] mm: eliminate VM_SPECIAL, VMA_SPECIAL_FLAGS Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:41 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 37/39] fuse: dax: do not set VM_MIXEDMAP Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:50 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 38/39] mm/huge_memory: remove vma_is_special_huge() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:45 ` sashiko-bot
2026-09-08 20:01 ` [PATCH 39/39] mm/vma: introduce and use vma[_flags]_can_gup() Lorenzo Stoakes (ARM)
2026-09-08 20:01 ` Lorenzo Stoakes (ARM)
2026-09-08 20:44 ` sashiko-bot
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=20260908204033.BE6501F00A3D@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-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.