From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, chrisl@kernel.org,
kasong@tencent.com, urezki@gmail.com, hannes@cmpxchg.org,
corbet@lwn.net, nphamcs@gmail.com, baohua@kernel.org,
youngjun.park@lge.com, shikemeng@huaweicloud.com,
yosry@kernel.org, chengming.zhou@linux.dev, kunwu.chan@gmail.com,
klarasmodin@gmail.com, "Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v7 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas
Date: Mon, 30 Nov 2026 15:09:38 +0000 [thread overview]
Message-ID: <sashiko-outbox-241460@kernel.org> (raw)
In-Reply-To: <20261129150755.191662-2-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/vmalloc: UAF of area->pages in vm_area_grow_pages() under
/proc/vmallocinfo
--
commit 2e45495fef5d4025d05ff1c330990787ce60eee4
Author: Baoquan He <hebaoquan@kylinos.cn>
mm/vmalloc: support vmalloc-backed VM_SPARSE areas
This commit introduces vm_area_grow_pages() and vm_area_shrink_pages() to
lazily allocate and release backing pages for VM_SPARSE | VM_ALLOC areas.
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index ee722162da7c9..4a8c35b958bb9 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
[ ... ]
> @@ -4174,6 +4176,136 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
> return NULL;
> }
>
> +/**
> + * vm_area_grow_pages - back more of a sparse area with pages
> + * @area: area created with %VM_SPARSE | %VM_ALLOC
> + * @end: end of the range to back, %PAGE_SIZE aligned
> + * @gfp: gfp flags for the page allocation
> + *
> + * Allocate and map pages for [@area->nr_pages << PAGE_SHIFT, @end). The
> + * pages are zeroed when %__GFP_ZERO is set. Pages are always backed from
> + * the start of the area, so a grow only extends that range. An @end that
> + * is already backed is a no-op. On failure nothing is mapped and
> + * @area->nr_pages is unchanged.
> + *
> + * The area must be released with vfree(@area->addr). Callers must
> + * serialize calls to this function.
> + *
> + * Return: 0 on success, -errno on failure.
> + */
> +int vm_area_grow_pages(struct vm_struct *area, unsigned long end, gfp_t gfp)
> +{
> + unsigned long start = (unsigned long)area->nr_pages << PAGE_SHIFT;
> + unsigned long addr = (unsigned long)area->addr;
> + unsigned long nr_pages, nr_allocated, nr_end, cap;
> + gfp_t nested_gfp = (gfp & GFP_RECLAIM_MASK) | __GFP_ZERO;
> + struct vmap_node *vn;
> + struct page **pages;
> + unsigned int flags;
> + int ret;
> +
> + might_sleep();
> +
> + if (WARN_ON_ONCE(!(area->flags & VM_ALLOC) ||
> + !(area->flags & VM_SPARSE)))
> + return -EINVAL;
> + if (WARN_ON_ONCE(!IS_ALIGNED(end, PAGE_SIZE)))
> + return -EINVAL;
> + if (WARN_ON_ONCE(end > get_vm_area_size(area)))
> + return -EINVAL;
> + if (end <= start)
> + return 0;
> + if ((end - start) >> PAGE_SHIFT > totalram_pages())
> + return -E2BIG;
> +
> + nr_end = end >> PAGE_SHIFT;
> + cap = roundup_pow_of_two(nr_end);
> + pages = kvrealloc(area->pages, cap * sizeof(*area->pages),
> + nested_gfp);
> + if (!pages)
> + return -ENOMEM;
> + area->pages = pages;
[Severity: Medium]
Can a concurrent /proc/vmallocinfo reader dereference freed memory in
area->pages when a partially backed area grows across a capacity boundary?
Once the first vm_area_grow_pages() sets area->nr_pages, show_busy_info()
and show_numa_info() walk area->pages[0 .. area->nr_pages - 1] under
vn->busy.lock:
mm/vmalloc.c:show_numa_info() {
...
for (i = 0; i < v->nr_pages; i += step)
counters[page_to_nid(v->pages[i])] += step;
...
}
On a later grow that reallocates the array, kvrealloc() frees the old
area->pages buffer via kfree() or vfree() before returning, while
area->nr_pages is still non-zero and vn->busy.lock is not held:
CPU0 CPU1
vm_area_grow_pages()
kvrealloc(area->pages, ...)
/* allocates new buffer */
/* frees old area->pages */
vmalloc_info_show()
show_busy_info()
spin_lock(&vn->busy.lock)
show_numa_info(m, v)
page_to_nid(v->pages[i])
<-- use-after-free
area->pages = pages;
Allocating the new array separately, copying the existing pointers,
swapping area->pages under vn->busy.lock, and only then freeing the old
array would avoid freeing area->pages under concurrent readers.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129150755.191662-1-baoquan.he@linux.dev?part=1
next prev parent reply other threads:[~2026-11-30 15:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 15:07 [PATCH v7 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-11-29 15:07 ` [PATCH v7 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-11-30 15:09 ` sashiko-bot [this message]
2026-11-29 15:07 ` [PATCH v7 02/14] mm: xswap support for zswap Baoquan He
2026-11-29 15:07 ` [PATCH v7 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-11-29 15:07 ` [PATCH v7 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-11-29 15:07 ` [PATCH v7 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-11-29 15:07 ` [PATCH v7 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-11-29 15:07 ` [PATCH v7 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-11-29 15:07 ` [PATCH v7 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-11-29 15:07 ` [PATCH v7 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-11-29 15:07 ` [PATCH v7 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-11-30 15:09 ` sashiko-bot
2026-11-29 15:07 ` [PATCH v7 14/14] mm, swap: skip the overcommit probe when removing xswap Baoquan He
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-241460@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baoquan.he@linux.dev \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hebaoquan@kylinos.cn \
--cc=kasong@tencent.com \
--cc=klarasmodin@gmail.com \
--cc=kunwu.chan@gmail.com \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shikemeng@huaweicloud.com \
--cc=urezki@gmail.com \
--cc=yosry@kernel.org \
--cc=youngjun.park@lge.com \
/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