fix(libkernel): deliver past-end file faults as SIGSEGV on Linux #28013
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/28013"
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?
Imported from boykopovar/AnyPS5. Originally posted by Ducengarth on 2026-11-28T04:09:15Z.
What
Follow-up to #28006, which this PR is based on. Its own change is the last commit.
On Linux, when a guest touches a page of a mapped file or shared memory object that lies past the object's end, the host kernel raises
SIGBUSwithBUS_ADRERR, and the guest's handler receivedSIGBUS. FreeBSD 11.4 reports that fault differently:vm_fault_holdrefuses a page index at or past the object's size withKERN_PROTECTION_FAILURE;trap_pfaultturns that intoSIGBUS, andtrap(), under the defaultmachdep.prot_fault_translation(0) and for a binary whoseosrelis at leastP_OSREL_SIGSEGV, delivers it asSIGSEGVwithSEGV_ACCERR.#28006 makes Windows deliver it that way. This PR does the same on Linux: in
DeliverFault, a hostSIGBUSwithBUS_ADRERRon the page-fault vector reaches the guest asSIGSEGVwithSEGV_ACCERR, keeping the trap number, address and error code. A hostSIGBUSwith another code, such as a machine-check memory error (BUS_MCEERR_*), still reaches the guest asSIGBUS. macOS is not changed.The tests from #28006 now expect
SIGSEGVon every platform, and theSA_SIGINFOcheck ofSEGV_ACCERRruns on Linux too. #28006's debt fragment drops the Linux difference it recorded.debt_foldrefuses two fragments that change one entry, so this PR edits that fragment instead of adding one.Tested
Linux: Ubuntu 24.04 under WSL 2, GCC 13.3, Release,
BUILD_TESTING=ON, a separate worktree at this branch's head.guest_exception_fault,guest_siginfo_faultandguest_memorypass.Exception.cppas in #28006 and these tests:guest_exception_faultfails on the signal number (it getsSIGBUS) andguest_siginfo_faultdies withBus error, since its handler coversSIGSEGVonly.68d9706675b) also passes the three tests on Linux with itsSIGBUSexpectation, which covers the Linux part that PR left to CI.Windows 11 (26300), WinLibs GCC 15.2, Release:
guest_exception_fault,guest_siginfo_faultandguest_memorypass. The Windows code is unchanged from #28006.python tools/check_conventions.py: no errors. The one warning is the length of the existing debt entry.python tools/debt_fold.py --check: passes.tools/pr_overlap.py --branch: line overlaps with #27906 and #27303 (both through #28006's changes) and with #26069, which changes the line before the new one inDeliverFault; none changes the same behaviour.main6b222c7ccd, which moved the reservation placement inDoMapFileBacked_nid_no_patchinto itstry(a conflict, kept with the past-end pages), on #28013's merge82ba394e1e:guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executableandguest_siginfo_faultpass.APS5_NO_PROCMAP_QUERY=1, as on a kernel older than 6.11,guest_memoryaborts withGuestWritable: failed to open /proc/self/maps, and it aborts the same way onmain6b222c7ccd.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-28T04:16:42Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
cafbd1ae86:tools/check_conventions.pypassed.guest_exception_fault_tests,guest_memory_tests,guest_siginfo_fault_testsbuilt cleanly.guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable,guest_siginfo_fault):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T09:06:50Z.
Review: APPROVED
Reviewed — looks good
The inspected implementation and tests show no verified blocking defect; the author reports passing targeted tests, which I did not run.
What I ran
Reviewed head
cafbd1ae86efc1e16809e9e44ed5854218f8ca50. I read the prepared description, commit list, manifest, diff, and changed code using the pinnedrepo_read.pyreader. No tests or build commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not run tests or a build. The author reports Linux and Windows test passes; these results were not independently verified. I read all added lines in the changed files listed by the review manifest. No files were excluded by the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-28T10:52:48Z.
Review: APPROVED
Checked head
cafbd1ae86on Windows 11 with WinLibs GCC 15.2 (Release), applied tomainc6331cc61btogether with 14 other open PRs.tools/check_conventions.py --headandtools/debt_fold.py --checkpass, and the full build succeeds.guest_exception_fault,guest_siginfo_faultandguest_memorypass.windows_read_trap_unknown, which fails onmaintoo (fixed in #28028), and theframe_capture_minimizeload timeout.Linux, WSL 2 Ubuntu 24.04 (kernel 6.18), GCC 13.3, Release, with this head applied to
mainc6331cc61b. It ranguest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executableandguest_siginfo_fault, twice in each mode:APS5_NO_PROCMAP_QUERY=1guest_memoryaborts: "GuestWritable: failed to open /proc/self/maps"guest_memory_maps_scan)The
guest_memoryabort PrivacyOnion reported ismain's/proc/self/mapsfallback, not this PR. Kernels before 6.11 have noPROCMAP_QUERYand always take that path, Ubuntu 24.04's stock 6.8 among them.guest_memorylowersRLIMIT_NOFILE, and the fallback opens the maps file again for every pointer check.mainaborts the same way withAPS5_NO_PROCMAP_QUERY=1, and #28045 fixes it.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-29T13:50:26Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
82ba394e1e:tools/check_conventions.pypassed.guest_exception_fault_tests,guest_memory_tests,guest_siginfo_fault_testsbuilt cleanly.guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable,guest_siginfo_fault):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-29T13:57:38Z.
Review: COMMENTED
Reviewed — comments
The reviewed head is
82ba394e1eaf652571f9d40f1c34a9f8ed14e343; no concrete blocking defect was verified, but the review remains incomplete because one Windows bookkeeping path needs further lifecycle inspection.What I ran
Read the prepared description, commit list, diff, and manifest, then inspected the changed fault handling, mapping logic, and selected tests through
repo_read.py. No commands or tests were run by me; the test results below were reported by the author.Results
Findings
Blocking
None verified in the code inspected.
Non-blocking
munmapandRemapFixedIntoRegistered, but I did not trace every caller that can discard or replace a mapping. The map is consulted by fault classification andmprotect. Changed lines:core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:86-88,core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:181,core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:1112-1116.Not verified
The full text of all eight files listed as reviewed in the manifest was read only selectively; surrounding functions and callers not shown here were not verified. No tests were run by me. Author-reported results include Linux and Windows test passes, a negative control, and convention/debt checks. No independent check of those results was possible.
To get this to a good state
Nothing is required. Please share the Windows mapping lifecycle check as an optional point.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-29T14:01:28Z.
Review: COMMENTED
789136f3-9333-42a0-b400-b18130e48543Reviewing files that changed from the base of the PR and between
cafbd1ae86and82ba394e1e.core/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/prx/libkernel/DirectMemory/PosixMemory.cppcore/libs/tests/GuestMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-11-30T00:49:11Z.
Review: APPROVED
Re-checked head
82ba394e1e, which mergesmainand #28006's updated branch. This PR's own lines are the same as atcafbd1ae86, which I approved. InDoMapFileBackedonly the surrounding code frommainchanged, which now callsPlaceHintInReservation(&placed, ..., alignment).Windows 11, WinLibs GCC 15.2, Release, merged onto
mainb3856362f3:guest_exception_fault,guest_memory,guest_mmap_fixed_anonymous,guest_mmap_executable,guest_siginfo_fault,windows_write_watchandwindows_write_watch_verify_directpass onmainand on this PR.windows_write_watch("cannot restore full resident run protection"). It isn't from this PR. Run 20 times alone, it fails once onmainand once on this PR, with the same message.WSL 2 Ubuntu 24.04 (kernel 6.18), GCC 13.3, Release, merged onto
mainb3856362f3, running the fiveguest_*tests:APS5_NO_PROCMAP_QUERY=1mainguest_memoryaborts: "GuestWritable: failed to open /proc/self/maps"@PrivacyOnion your second run hits the same thing as the first, and it isn't this PR. On kernels before 6.11, which have no
PROCMAP_QUERY(Ubuntu 24.04's stock 6.8 among them),main's/proc/self/mapsfallback opens the file again for every pointer check.guest_memorylowersRLIMIT_NOFILEfirst, so the open fails.mainaborts the same way, as the table shows, and #28045 fixes it.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T08:45:23Z.
Review: COMMENTED
I ran guest_memory, guest_siginfo_fault and guest_exception_fault with the patch on Linux. All three passed. The cases exercise reads past the backing file’s end and delivery through the mapped-file fault path, including a handler that permits the guest read to resume.
AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.