From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Shakeel Butt" <shakeel.butt@linux.dev>,
"Pedro Falcato" <pfalcato@suse.de>,
"David Hildenbrand" <david@kernel.org>,
"Jann Horn" <jannh@google.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Kees Cook" <kees@kernel.org>,
"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
"Ollie Wild" <aaw@google.com>, "Adrian Bunk" <bunk@stusta.de>,
"Xu Xin" <xu.xin@linux.dev>,
"Chengming Zhou" <chengming.zhou@linux.dev>,
"Mike Rapoport" <rppt@kernel.org>,
"Michal Hocko" <mhocko@suse.com>,
"Hugh Dickins" <hughd@google.com>,
"Joey Gouly" <joey.gouly@arm.com>,
"Catalin Marinas" <catalin.marinas@arm.com>
Cc: linux-mm@kvack.org, "Chris Mason" <mason@kernel.org>,
"Josef Bacik" <josef@toxicpanda.com>
Subject: Re: [PATCH 4/7] mm/vma: fix uncharge after failed stack relocation
Date: Sun, 22 Nov 2026 16:04:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-228074@kernel.org> (raw)
In-Reply-To: <20261121-some-more-ai-fixes-v1-4-236e925d9b64@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] mm/vma: unaccounted writable VMA left mapped after
relocate_vma_down() fails
--
commit 9c6f7e9f77d24dc1b72d41f3c440f1ede99ab822
Author: Chris Mason <mason@kernel.org>
mm/vma: fix uncharge after failed stack relocation
This commit uncharges the initial stack length and clears VMA_ACCOUNT_BIT
when relocate_vma_down() fails after expanding the stack VMA, avoiding a
vm_committed_as underflow in exit_mmap().
> diff --git a/mm/vma_exec.c b/mm/vma_exec.c
> index 586c521559424..84b98f1a201d7 100644
> --- a/mm/vma_exec.c
> +++ b/mm/vma_exec.c
> @@ -45,6 +45,7 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift)
> struct vm_area_struct *next;
> struct mmu_gather tlb;
> PAGETABLE_MOVE(pmc, vma, vma, old_start, new_start, length);
> + int err;
>
> BUG_ON(new_start > new_end);
>
> @@ -68,8 +69,10 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift)
> * process cleanup to remove whatever mess we made.
> */
> pmc.for_stack = true;
> - if (length != move_page_tables(&pmc))
> - return -ENOMEM;
> + if (length != move_page_tables(&pmc)) {
> + err = -ENOMEM;
> + goto err_unacct;
> + }
>
> tlb_gather_mmu(&tlb, mm);
> next = vma_next(&vmi);
> @@ -93,7 +96,20 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift)
>
> vma_prev(&vmi);
> /* Shrink the vma to just the new range */
> - return vma_shrink(&vmi, vma, new_end);
> + err = vma_shrink(&vmi, vma, new_end);
> + if (err)
> + goto err_unacct;
> +
> + return 0;
> +
> +err_unacct:
> + /*
> + * The vma now spans more than was charged, so exit_mmap() must not
> + * derive the uncharge from its size.
> + */
> + vm_unacct_memory(length >> PAGE_SHIFT);
> + vma_clear_flags(vma, VMA_ACCOUNT_BIT);
> + return err;
> }
[Severity: High]
Does clearing VMA_ACCOUNT_BIT here leave the expanded [new_start, old_end)
stack VMA writable and unaccounted if the task does not immediately exit?
When execve() fails after bprm->point_of_no_return, bprm_execve() sends
SIGSEGV via force_fatal_sig(SIGSEGV) rather than force_exit_sig(SIGSEGV),
so SA_IMMUTABLE is not set. If the task is ptraced (for example via
PTRACE_TRACEME) when a memory cgroup limit causes move_page_tables() or
vma_shrink() to fail with -ENOMEM, get_signal() intercepts the SIGSEGV in
ptrace_signal() and the tracer can suppress it by resuming with signal 0.
The task then survives in userspace with an unaccounted writable VMA of
size length + shift (up to 16 GiB for 64-bit tasks or 128 TiB for 32-bit
tasks on x86-64), allowing anonymous pages to be faulted in without
charging vm_committed_as (bypassing vm.overcommit_memory=2) and
underflowing mm->total_vm and mm->stack_vm (which remain at
length >> PAGE_SHIFT) if the VMA is later unmapped.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121-some-more-ai-fixes-v1-0-236e925d9b64@kernel.org?part=4
next prev parent reply other threads:[~2026-11-22 16:04 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-21 16:02 [PATCH 0/7] mm: reworked AI-generated VMA and mremap fixes Lorenzo Stoakes (ARM)
2026-11-21 16:02 ` [PATCH 1/7] mm/vma: error out on invalid bounds in unmapped_area_topdown() Lorenzo Stoakes (ARM)
2026-11-22 3:20 ` Suren Baghdasaryan
2026-11-22 15:55 ` Gregory Price (Meta)
2026-11-21 16:02 ` [PATCH 2/7] mm/vma: lock VMAs before taking mm_all_locks_mutex Lorenzo Stoakes (ARM)
2026-11-22 3:23 ` Suren Baghdasaryan
2026-11-22 15:53 ` Gregory Price (Meta)
2026-11-21 16:02 ` [PATCH 3/7] mm/ksm: only interrupt unmerging on a fatal signal Lorenzo Stoakes (ARM)
2026-11-22 3:27 ` Suren Baghdasaryan
2026-11-22 15:54 ` David Hildenbrand (Arm)
2026-11-22 15:56 ` Gregory Price (Meta)
2026-11-21 16:02 ` [PATCH 4/7] mm/vma: fix uncharge after failed stack relocation Lorenzo Stoakes (ARM)
2026-11-22 3:34 ` Suren Baghdasaryan
2026-11-22 15:50 ` Gregory Price (Meta)
2026-11-22 16:04 ` sashiko-bot [this message]
2026-11-21 16:02 ` [PATCH 5/7] mm/mremap: apply the mmap() offset limits on expansion Lorenzo Stoakes (ARM)
2026-11-22 3:37 ` Suren Baghdasaryan
2026-11-22 15:50 ` Gregory Price (Meta)
2026-11-21 16:02 ` [PATCH 6/7] mm/mremap: respect guard gaps on in-place expansion Lorenzo Stoakes (ARM)
2026-11-22 3:41 ` Suren Baghdasaryan
2026-11-22 15:49 ` Gregory Price (Meta)
2026-11-21 16:02 ` [PATCH 7/7] mm/vma: make brk mappings non-executable under MDWE Lorenzo Stoakes (ARM)
2026-11-22 3:46 ` Suren Baghdasaryan
2026-11-22 15:48 ` Gregory Price (Meta)
2026-11-22 15:55 ` (subset) [PATCH 0/7] mm: reworked AI-generated VMA and mremap fixes David Hildenbrand
2026-11-22 15:57 ` Gregory Price (Meta)
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=sashiko-outbox-228074@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=aaw@google.com \
--cc=akpm@linux-foundation.org \
--cc=bunk@stusta.de \
--cc=catalin.marinas@arm.com \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=hughd@google.com \
--cc=jannh@google.com \
--cc=joey.gouly@arm.com \
--cc=josef@toxicpanda.com \
--cc=kees@kernel.org \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mason@kernel.org \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=willy@infradead.org \
--cc=xu.xin@linux.dev \
/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