From: sashiko-bot@kernel.org
To: "Baoquan He" <baoquan.he@linux.dev>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, david@kernel.org, urezki@gmail.com,
chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com,
baohua@kernel.org, youngjun.park@lge.com,
shikemeng@huaweicloud.com, hannes@cmpxchg.org, yosry@kernel.org,
chengming.zhou@linux.dev, corbet@lwn.net, kunwu.chan@gmail.com,
klarasmodin@gmail.com, "Baoquan He" <hebaoquan@kylinos.cn>
Subject: Re: [PATCH v6 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas
Date: Mon, 23 Nov 2026 12:48:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-229251@kernel.org> (raw)
In-Reply-To: <20261122123918.3486916-2-baoquan.he@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/vmalloc: vread_iter() ignores nr_pages == 0 on VM_SPARSE |
VM_ALLOC areas
--
commit 06f2dfa4d38fcaa037aa36eab4a7c644b49409c4
Author: Baoquan He <hebaoquan@kylinos.cn>
mm/vmalloc: support vmalloc-backed VM_SPARSE areas
This commit adds vm_area_grow_pages() and vm_area_shrink_pages() to allow
VM_SPARSE | VM_ALLOC areas to be dynamically backed by pages from the page
allocator and freed with vfree().
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 320e981188c98..0fe2f1c39b96e 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
[ ... ]
> @@ -4983,12 +5114,18 @@ long vread_iter(struct iov_iter *iter, const char *addr, size_t count)
> if (n > remains)
> n = remains;
>
> - if (flags & VMAP_RAM)
> + if (flags & VMAP_RAM) {
> copied = vmap_ram_vread_iter(iter, addr, n, flags);
> - else if (!(vm && (vm->flags & (VM_IOREMAP | VM_SPARSE))))
> - copied = aligned_vread_iter(iter, addr, n);
> - else /* IOREMAP | SPARSE area is treated as memory hole */
> + } else if (vm && (vm->flags & VM_IOREMAP)) {
> + /* Not backed by struct pages. */
> + copied = zero_iter(iter, n);
> + } else if (vm && (vm->flags & VM_SPARSE) &&
> + !(vm->flags & VM_ALLOC)) {
> + /* Populated by the caller; treat as a memory hole. */
> copied = zero_iter(iter, n);
> + } else {
> + copied = aligned_vread_iter(iter, addr, n);
> + }
>
> addr += copied;
> remains -= copied;
[Severity: Medium]
Can vread_iter() read pages that are being freed when a VM_SPARSE | VM_ALLOC
area has nr_pages == 0?
Earlier in vread_iter(), the backed size is computed as:
mm/vmalloc.c:vread_iter() {
...
if (vm)
size = (vm->flags & VM_ALLOC && vm->nr_pages) ?
(vm->nr_pages << PAGE_SHIFT) :
get_vm_area_size(vm);
...
}
Unlike regular vmalloc() allocations, a VM_SPARSE | VM_ALLOC area does not
set VM_UNINITIALIZED and legitimately has nr_pages == 0 before the first
vm_area_grow_pages() call and after vm_area_shrink_pages(area, 0). When
nr_pages is 0, the ternary expression falls back to get_vm_area_size(vm)
instead of 0, so vread_iter() calls aligned_vread_iter() across the entire
virtual range while holding vn->busy.lock.
When vm_area_shrink_pages(area, 0) runs concurrently with /proc/kcore reads,
setting nr_pages to 0 under vn->busy.lock no longer prevents vread_iter()
from entering aligned_vread_iter():
CPU0 CPU1
vm_area_shrink_pages(area, 0)
spin_lock(&vn->busy.lock)
WRITE_ONCE(area->nr_pages, 0)
spin_unlock(&vn->busy.lock)
vread_iter()
find_vmap_area_exceed_addr_lock()
/* vm->nr_pages == 0 */
size = get_vm_area_size(vm)
aligned_vread_iter()
page = vmalloc_to_page(addr)
vunmap_range(...)
vm_area_free_pages(...)
copy_page_to_iter_nofault(page, ...)
<-- use-after-free page read
The same race occurs on the error cleanup path of an initial
vm_area_grow_pages() call while nr_pages is still 0. Even without a
concurrent grow or shrink, vread_iter() walks the page tables across the
entire unbacked area under vn->busy.lock instead of skipping it.
Checking (vm->flags & (VM_ALLOC | VM_SPARSE)) == (VM_ALLOC | VM_SPARSE) when
computing size so that nr_pages == 0 yields size = 0 (or skipping to next_va)
would avoid this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261122123918.3486916-1-baoquan.he@linux.dev?part=1
next prev parent reply other threads:[~2026-11-23 12:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 12:39 [PATCH v6 00/14] mm, swap: extendable swap devices (xswap phase I) Baoquan He
2026-11-22 12:39 ` [PATCH v6 01/14] mm/vmalloc: support vmalloc-backed VM_SPARSE areas Baoquan He
2026-11-23 12:48 ` sashiko-bot [this message]
2026-11-22 12:39 ` [PATCH v6 02/14] mm: xswap support for zswap Baoquan He
2026-11-22 12:39 ` [PATCH v6 03/14] mm, swap: refactor free_swap_cluster_info to take swap_info_struct Baoquan He
2026-11-22 12:39 ` [PATCH v6 04/14] mm, swap: use a VM_SPARSE cluster array for xswap devices Baoquan He
2026-11-22 12:39 ` [PATCH v6 05/14] mm, swap: widen swap_info_struct max/pages to unsigned long Baoquan He
2026-11-22 12:39 ` [PATCH v6 06/14] mm, swap: create the xswap device from swapon(2) Baoquan He
2026-11-22 12:39 ` [PATCH v6 07/14] mm, swap: refactor swapoff and add xswap_destroy Baoquan He
2026-11-22 12:39 ` [PATCH v6 08/14] mm, swap: require zswap for xswap devices Baoquan He
2026-11-22 12:39 ` [PATCH v6 09/14] mm, swap: let the command line set the xswap device size Baoquan He
2026-11-23 12:48 ` sashiko-bot
2026-11-22 12:48 ` [PATCH v6 10/14] mm, swap: add CONFIG_XSWAP_DEFAULT_MAX Baoquan He
2026-11-22 12:48 ` [PATCH v6 11/14] mm, swap: add xswap grow trigger on cluster allocation Baoquan He
2026-11-23 12:49 ` sashiko-bot
2026-11-22 12:48 ` [PATCH v6 12/14] mm, swap: add debugfs counters for xswap Baoquan He
2026-11-22 12:48 ` [PATCH v6 13/14] mm, swap: do not give an xswap slot to a cgroup that cannot zswap Baoquan He
2026-11-23 12:49 ` sashiko-bot
2026-11-22 12:48 ` [PATCH v6 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-229251@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