Repository navigation
fix(libc): validate the guest exception_ptr in _M_addref and _M_release before dereference - #23921
amazedturnip wants to merge 1 commit into
Conversation
…se before dereference
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against fb70eef260:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_unwind_accessors_testsbuilt cleanly. - CTest (
guest_unwind_accessors):1/1 Test #1403: guest_unwind_accessors ........... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/exception/ExceptionPointer.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1403: guest_unwind_accessors ...........***Exception: SegFault 1.84 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Checked _ZNSt15__exception_ptr13exception_ptr9_M_addrefEv_nid_postfix and _M_releaseEv_nid_postfix in both libstdc++ and libc++ (#else) branches in core/libs/prx/libc/src/exception/ExceptionPointer.cpp for nullptr guard semantics
- Verified that null self pointer check in ExceptionPointer.cpp:24,31,107,113 matches void return type and prevents SIGSEGV/null dereference when guest code manipulates a null or uninitialized exception pointer object
- Verified ABI compatibility and calling convention: APS5_VABI and noexcept attributes are preserved across both function signatures in ExceptionPointer.cpp
- Verified test coverage in core/libs/tests/GuestUnwindAccessors.cpp:132-137 (CheckExceptionPointerNullSelf) calling both addref and release exports with nullptr and verifying errno preservation
- Checked AGENTS.md compliance: no comments introduced, no prohibited stubs or fake returns, clean conventions gate pass
Looks Good To Me
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The reviewed change adds null-self guards to both exception pointer exports in both implementation branches, with a focused regression check at head fb70eef26006684ba1ab779dd35ff7b3b023145f.
What I ran
No commands or tests were run. I inspected the prepared diff and read both changed files at the pinned head.
Results
| Check | Result | Note |
|---|---|---|
| Diff and source review | passed | Both implementation branches inspected |
| Tests | not run | Author reports Linux runs; not independently verified |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author's reported Linux test runs and negative control were not independently run. Console behavior and Windows/MSYS2 and macOS libc++ builds were not verified. Both files listed as reviewed in the manifest were read; no excluded changed files were listed.
To get this to a good state
Nothing is required.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
ligmaSec
left a comment
There was a problem hiding this comment.
Built the submitted exception-pointer implementation and ran the exact GuestUnwindAccessors fixture on Linux. It passed the null-self cases for _M_addref and _M_release, the errno preservation check, and the existing unwind-accessor checks.
AI-assisted: yes.
What
_ZNSt15__exception_ptr13exception_ptr9_M_addrefEv_nid_postfixand_M_releaseEv_nid_postfixdereferencedself->object(and, in the libc++ branch, wrote back toself) with no null check, so a guest code path holding a nullstd::exception_ptrcrashed the host process with SIGSEGV. Added anif (!self) return;guard at the top of both exports, in both preprocessor branches (the libstdc++ forwarder branch used by Linux g++/Windows MSYS2 CI and the libc++GuestExceptionPointerbranch), mirroring the existing null-self convention already used by sibling export__cxa_exception_typein the same file.Game impact: guest code that copies or destroys a default-constructed (null)
std::exception_ptrno longer segfaults the emulator; both calls become safe no-ops, matching how the sibling accessor treats null self.Tested
ctest -R '^guest_unwind_accessors$'passes 3 of 3 runs, plus unwind/exception neighbours (guest_libc_internal_exception_*,unwind_callback_abi_*,unwind_cursor_*) all pass.0x0inside libc.prx (not an uncaught C++ exception).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)