Article View: muc.lists.freebsd.bugs
Article #783[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
From: bugzilla-noreply
Date: Fri, 27 Nov 2026 11:22
Date: Fri, 27 Nov 2026 11:22
100 lines
6312 bytes
6312 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301182
Bug ID: 301182
Summary: vm_page_grab_zero_partial() skips zeroing a busy
partial page, leaving stale bytes after fspacectl(2),
and panics when the page is swap-backed
Product: Base System
Version: 15.1-RELEASE
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: laamalif@proton.me
vm_page_grab_zero_partial() passes VM_ALLOC_WAITFAIL into
vm_page_grab_lookup(), so when the partial page being
invalidated is resident but busy, the lookup gives up instead
of retrying and the loop body runs: for a POSIX shared
memory object, fspacectl(2) with SPACECTL_DEALLOC returns
success without zeroing the deallocated sub-page range,
leaving the old contents readable through the mapping.
7becd87c988 added the flag to the lookup; before that the grab
used VM_ALLOC_NOCREAT alone and the allocation passed
VM_ALLOC_WAITFAIL separately. tmpfs files take the same path
through tmpfs_reg_punch_hole().
Reproduced as an unprivileged user on 15.1-RELEASE-p7 (amd64),
15.1-RELEASE-p6 (arm64), and 16.0-CURRENT (amd64). vmgrab_stale.c
(attached) writes a 0x41 pattern into a shm object page, calls
fspacectl(fd, SPACECTL_DEALLOC, [100, 4096)), and reads the
range back, while a second thread loops pread(fd, buf, 100, 0);
that pread grabs the page shared-busy and holds it across the
copyout, which is the busy state the lookup sees.
$ cc -Wall -Wextra -Werror -o vmgrab_stale vmgrab_stale.c -lpthread
$ ./vmgrab_stale 3000
--- clean (control) ---
[shm] clean: stale bytes in 0 / 3000 rounds
--- concurrent ---
[shm] round 25: after fspacectl(SPACECTL_DEALLOC, [100, 4096)) p[100]=0x41
(expected 0x00)
[shm] concurrent: stale bytes in 435 / 3000 rounds
Done: clean 0/3000, concurrent 435/3000
The clean phase, same kernel and syscall, no reader thread: zero
hits. The arm64 run gave 503/3000, and 16.0-CURRENT 232/2000.
If the busy page also has swap backing, vm_pager_has_page()
is true, so the loop body calls vm_page_alloc_iter() for an
index still present in the radix tree, and the kernel panics
in pctrie_iter_insert_lookup() with "key already present" -
unconditional on GENERIC, not an INVARIANTS assertion.
vmgrab_panic.c (attached) drives it: it launders 256 dirty
pages of a shm object to swap with MADV_DONTNEED plus a
memory-pressure child, re-faults them, then races the same
pread against the same fspacectl. On the stock 15.1-RELEASE-p7
kernel this panicked the box on the first run:
panic: pctrie_iter_insert_lookup: key a is already present
#11 vm_page_alloc_iter (pindex=10) at vm_page.c:2032
#12 vm_page_grab_zero_partial (pindex=10, base=100, end=4096) at vm_page.c:5092
found = true, allocflags = 1040
#13 shm_partial_page_invalidate at uipc_shm.c:732
#14 shm_deallocate at uipc_shm.c:2077
#15 shm_fspacectl at uipc_shm.c:2135
The panic and backtrace come from the crash dump the box wrote
automatically; the relevant crash-dump trace and process
listing are attached.
The whole run, including the pressure setup, ran as an
unprivileged user; the dump lists the panicking process under
the ordinary user account.
The attached patch keeps VM_ALLOC_WAITFAIL off the lookup, so
the grab waits and retries, and restores it for the
not-resident allocation, matching the pre-7becd87c988 code. I
built and booted a releng/15.1 kernel with only this patch
applied: vmgrab_panic completes 256 rounds with no panic,
vmgrab_stale gives 0/3000 concurrent hits, the clean phase
unchanged. The same shape is in main, stable/15, releng/15.2,
15.1 and 15.0; 14.4 does not contain the function. I have
not tested 15.2 at runtime.
The tmpfs caller ran clean at runtime (0 hits in 13000
rounds); its window is the same source shape, but I did not
reproduce it there. The panic reproducer needs swap configured
and enough memory pressure to complete the laundering; no
privileges are required beyond that.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-301182-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics when the page is swap-backed Date: Fri, 27 Nov 2026 11:22:23 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301182-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="95012"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795778543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5abB9NBLtwPDwK2m+2m9kktHMjui+PXH0t4KmW4S6hw=; b=mTMdIxY1jNqqCR5+yYXV4VmPQA53bEqqu+lUnyKIUF0/fqfyHBt/pnnL5SpYPGr1s2ZWaF iW7SR4aIjR6vKel8eYO5d94ajPoBWGJoBvcfQzrh+MXOL6SQYUgGg0LiEb0qDFDd5Habf5 W3nmDnQZMmCL5BHXPT3HsFfwZWIowpNj+66WKKgNi+xVGFfwn5n3yP0W3qkWRQ0ndujGR8 G/+JRetuZ9NORfu4NiJumW+PXlGU08pWrTO0VBOcGXgtpu3NiHpRSXU0Q23XskigTzN4N2 D0Y+6g4j4Zp67+lld3pvc0hzRxyr/FZbXAHTjX8sxgz9J0s2Co6AdQrkseSrWA== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes