From: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
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>,
stable@vger.kernel.org
Subject: Re: [PATCH 1/7] mm/vma: error out on invalid bounds in unmapped_area_topdown()
Date: Sun, 22 Nov 2026 19:03:06 +0100 [thread overview]
Message-ID: <725b9135-2e01-44c0-b30f-dab16d3932cc@gmail.com> (raw)
In-Reply-To: <20261121-some-more-ai-fixes-v1-1-236e925d9b64@kernel.org>
On 11/21/26 5:02 PM, Lorenzo Stoakes (ARM) wrote:
> unmapped_area_topdown() suffers from a class of bug arising from a mismatch
> between how maple tree functions and VMA iterator functions express ranges
> - the former inclusively, the latter exclusively.
>
> This is problematic with an exclusive upper bound of 0, as it translates
> to an inclusive upper bound of ULONG_MAX, that is a range which extends to
> the end of the address space, and start < end or equivalent comparisons
> evaluate false in a situation where in fact the expression should evaluate
> true.
>
> unmapped_area_topdown() calls vma_iter_area_highest() to position the VMA
> iterator into the next highest empty range spanning [low_limit,
> high_limit), iteratively reducing high_limit without checking whether it
> has reached 0.
>
> This can result in a [low_limit, 0) pair being passed to
> vma_iter_area_highest() and thus unexpected underflow. Consider:
>
> vm_start = 0x30000
> stack_guard_gap = 0x100000
> info->length = 0x1000
> high_limit = vm_start_gap() = 0
> high_limit - 1 = ULONG_MAX
> window = [low_limit, ULONG_MAX]
> vma_iter_end() = ULONG_MAX + 1 = 0
> gap = 0 - info->length = 0xfffffffffffff000
>
> The result is page aligned and below the IS_ERR_VALUE() range, so it
> does not look like an error. What follows depends on the caller:
>
> - mmap() with no hint can fail with -ENOMEM while space is free. The
> bottom-up fallback is skipped, and __get_unmapped_area() refuses the
> address as above TASK_SIZE.
> - On x86-64, find_nearest_trampoline() can pick the address for the
> uprobe trampoline. _install_special_mapping() then inserts a VMA
> whose vm_end is 0, and exit_mmap() frees kernel page tables that
> every mm shares.
> - On powerpc64 with the hash MMU, slice_get_unmapped_area() can pass
> the address to alloc_extended_context(), which then writes out of
> bounds of mm->context.extended_id[].
>
> mmap() can succeed with an address from the wrapped window where the
> range above TASK_SIZE is too short for the request and its alignment
> padding. On s390 that range is one page, so this takes no more than the
> default stack_guard_gap.
>
> Fix the issue by converting the loop into one that explicitly tests
> low_limit < high_limit.
>
> Additionally, simplify the logic by declaring the VMA iterator in the
> loop (it is reset on each iteration anyway) and exiting with the correct
> output value on success rather than performing a goto when an iteration is
> required.
>
> Reported-by: Chris Mason <mason@kernel.org>
> Fixes: 58c5d0d6d522 ("mm/mmap: regression fix for unmapped_area{_topdown}")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
LGTM:
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
--
cheers,
jose a. p-a
next prev parent reply other threads:[~2026-11-22 18:03 UTC|newest]
Thread overview: 22+ 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-22 18:03 ` Jose A. Perez de Azpillaga [this message]
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-22 18:03 ` Jose A. Perez de Azpillaga
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-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-22 18:03 ` Jose A. Perez de Azpillaga
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=725b9135-2e01-44c0-b30f-dab16d3932cc@gmail.com \
--to=azpijr@gmail.com \
--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=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
--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