Repository navigation
fix(libSceNKWebKit): read and write WTFGetBacktrace's frame count through checked guest copies - #22783
fix(libSceNKWebKit): read and write WTFGetBacktrace's frame count through checked guest copies#22783milescoviello wants to merge 1 commit into
Conversation
…ough checked guest copies WTFGetBacktrace read and wrote the caller's frame count through the guest pointer, and on Windows captured frames straight into the caller's buffer, so an unmapped count or buffer crashed the host. The count is now read with GuestCopyIn_nid_no_patch, and the captured count is written back with one GuestCopyOut_nid_no_patch. A count that can't be read returns at once, as a null one does. On Windows, a buffer that isn't writable for the requested count captures no frames and reports 0, the count the other hosts always report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against bc5d4ad327:
- Conventions:
tools/check_conventions.pypassed. - Build:
nkwebkit_wtf_testsbuilt cleanly. - CTest (
nkwebkit_wtf):1/1 Test #4581: nkwebkit_wtf ..................... Passed 0.14 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceNKWebKit/src/WtfAssert.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4581: nkwebkit_wtf .....................***Exception: SegFault 0.18 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Checked WtfAssert.cpp WTFGetBacktrace for null pointer checks and guest copy safety: stack and size pointers are checked before dereferencing, and count is read via GuestCopyIn_nid_no_patch
- Checked boundary conditions: requested <= 0 returns immediately, preserving existing negative/zero frame count behavior
- Checked Windows CaptureStackBackTrace integration: verifies GuestWritable_nid_no_patch for requested * sizeof(void*) before capturing frames directly into stack buffer
- Checked output copying: captured count is written back through GuestCopyOut_nid_no_patch, safely handling unmapped or read-only size pointers
- Checked AGENTS.md compliance: no disallowed comments introduced, technical debt fragment correctly placed in docs/dev/debt/changes/, and tests verify valid, invalid size, and invalid stack pointers
Looks Good To Me
|
@milescoviello this fixes the same function and the same lines as #22780, which was opened a few minutes earlier and already has a review pass and a negative-control test on its head. Both make WTFGetBacktrace read the size and write the frames through checked guest copies, so only one can merge without a rebase. #22780 also clamps the Windows frame count to the USHORT maximum and has a dedicated test file for read-only pages, INT32_MAX, null pointers and errno. I am closing this one as a duplicate to keep a single fix. If you see a case #22780 does not cover, please comment on it there. |
|
Agreed, thanks Dean. #22780 came first and covers more (the USHORT clamp and the read-only page cases). My duplicate check ran against an open-PR list from before it was opened. I'll refresh that list right before opening a PR from now on. |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
|
What
WTFGetBacktraceread the requested frame count through the caller'ssizepointer and wrote the captured count back through it. On Windows it also captured frames withCaptureStackBackTracestraight into the caller'sstackbuffer. An unmapped count or buffer crashed the host.Changes:
GuestCopyIn_nid_no_patch. A count that can't be read returns at once, as a null pointer or a non-positive count does.stackis writable for the requested count. Otherwise no frames are captured and the count is 0, the value every other host already reports.GuestCopyOut_nid_no_patch.Results for valid pointers are unchanged.
WTFReportBacktracepasses its own host buffers and behaves as before.Tested
Linux (Ubuntu 26.04.1, kernel 7.0), GCC 15.2, Ninja, Release,
-DBUILD_TESTING=ON:nkwebkit_wtfgains three checks:0x10) returns without touching anything;nkwebkit_wtfpasses, 3 runs.main'sWtfAssert.cppand the new checks,nkwebkit_wtfends infatal SIGSEGV (code 1) at address 0x0000000000000010.git merge-treeagainstmainis clean. feat(libSceNKWebKit): implement WTF FileSystemImpl hardLink, createSymbolicLink and appendFileContentsToFileHandle #19823, feat(libSceNKWebKit): implement WTF FileSystemImpl existence, delete and volume helpers over the guest filesystem #19822 and feat(libSceNKWebKit): implement WTF::GregorianDateTime constructors #14478 also edittests/Wtf.cpp, and my fix(libSceNKWebKit): read WTF::sixCharacterHashStringToInteger's characters through checked guest copies #22781 edits it too, all in other places;git merge-treeof this branch with each of them is clean.tools/check_conventions.pypasses on the branch and this body.tools/debt_fold.py --checkreports nothing for this fragment.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)