mirror of
https://github.com/RhapsodiOS/RhapsodiOS.git
synced 2026-11-03 22:01:40 -07:00
[GH-ISSUE #72] net: unp_gc calls sorflush on non-socket files and freezes the guest #64
Labels
No labels
bug
documentation
enhancement
enhancement
good first issue
help wanted
help wanted
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github-starred/RhapsodiOS#64
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @raynorpat on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/RhapsodiOS/RhapsodiOS/issues/72
Symptom
vm/work/issue-67/gccycle.csends an open regular file and a socketpair's own peer over SCM_RIGHTS, then closes everything. The guest freezes every time:unp_gcspins insbflush(gdbstub, found while debugging #67).Cause
unp_gc(bsd/kern/uipc_usrreq.c~789-803) collects every unreachable file (f_count == f_msgcount, not FMARK) and callssorflush((struct socket *)fp->f_data)on each one. For a vnode-backed filef_datais a vnode, not a socket, sosorflush/sbflushwork on garbage. The mark phase also has a window: descriptors in flight can be marked or unmarked whileunp_gcsleeps (M_WAITOK allocation) — check against 4.4BSD-Lite2/FreeBSD's version.Fix direction
Only
sorflushfiles whosef_type == DTYPE_SOCKET(as later BSDs do);closefstill drops the extra reference for the rest.Found by the #67 investigation.
@raynorpat commented on GitHub (Oct 20, 2026):
Fixed by
f2f657094and040bf8682, merged into ffs-perf in4fb1150e2, plusdcaccc812.f2f657094:unp_gconlysorflushesDTYPE_SOCKETfiles. TheM_WAITOKallocation of the extra-reference array now happens before the mark phase, so it can't sleep between mark and sweep.dcaccc812: because the array is sized fromnfilesbefore the allocation sleeps, the sweep now stops collecting at the array's size. Any files left over wait for the next gc.040bf8682, a second bug the reproducer exposed:unp_gc'sclosef(fp, 0)reachesvn_closewith no process, andunmap_vnode(kern/mapfs.c) dereferencedp->p_cred. The closing process got SIGSEGV and leaked 2 file-table entries per close until the table filled up (ENFILE).vn_closenow usescurrent_proc()when it's given none.Verified on the kernel built from
040bf8682(cksum 1995866079):gccycle 50froze the guest. Sending only a regular file got SIGSEGV and leaked files.gccycle 5000andgcmode 1000in all three modes pass, with no file-table growth.stress-net fdpass,make check-netandmake check-ipcpass.soak -t 600 -j 4: no freeze or panic, net 6/6. Itsvm pressureandipc ooltimeouts were also seen on earlier kernels, and twoproc ptyEIO failures are on paths these commits don't touch.dcaccc812will be covered by the combined ffs-perf retest.