Thread View: muc.lists.freebsd.bugs
6 messages
6 total messages
Started by bugzilla-noreply
Fri, 27 Nov 2026 11:22
[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
Author: 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
[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 11:22
Date: Fri, 27 Nov 2026 11:22
17 lines
2613 bytes
2613 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301182 --- Comment #1 from laamalif@proton.me --- Created attachment 277793 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277793&action=edit keep VM_ALLOC_WAITFAIL off the lookup, restore it for the not-resident allocation (the pre-7becd87c988 shape) -- 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
[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 11:22
Date: Fri, 27 Nov 2026 11:22
19 lines
2679 bytes
2679 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301182 --- Comment #2 from laamalif@proton.me --- Created attachment 277794 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277794&action=edit reproducer: fspacectl(SPACECTL_DEALLOC) leaves stale bytes when a reader thread holds the page busy; clean control phase then concurrent phase; -DVTMPFS for the tmpfs mode -- 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
[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 11:22
Date: Fri, 27 Nov 2026 11:22
18 lines
2665 bytes
2665 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301182 --- Comment #3 from laamalif@proton.me --- Created attachment 277795 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277795&action=edit reproducer: launders shm pages to swap, re-faults them, races pread against fspacectl; panics the unfixed kernel (needs swap configured, no privileges required) -- 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
[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 11:22
Date: Fri, 27 Nov 2026 11:22
17 lines
2620 bytes
2620 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301182 --- Comment #4 from laamalif@proton.me --- Created attachment 277796 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=277796&action=edit crash-dump excerpt: the panic header, the panicking thread's trace with found/allocflags, the fstat rows, the ps row -- 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
[Bug 301182] vm_page_grab_zero_partial() skips zeroing a busy partial page, leaving stale bytes after fspacectl(2), and panics w...
Author: bugzilla-noreply
Date: Fri, 27 Nov 2026 16:04
Date: Fri, 27 Nov 2026 16:04
16 lines
2597 bytes
2597 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301182
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |crash
--
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads