Repository navigation
fix(libSceLibreSsl3): copy the sk_free stack guest record safely - #24399
oneandonlydean merged 2 commits into
Conversation
sk_free now copies the stack header in through GuestCopyIn before freeing its element array, like sk_push in the same file. An unreadable stack throws std::invalid_argument with errno preserved and frees nothing.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 5b9c11f294:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_libressl3_stack_testsbuilt cleanly. - CTest (
guest_libressl3_stack):1/1 Test #4596: guest_libressl3_stack ............ Passed 0.04 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceLibreSsl3/src/Stack.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4596: guest_libressl3_stack ............***Exception: SegFault 0.48 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified sk_free_nid_postfix correctly checks for nullptr before any operations and returns safely as a no-op
- Verified CopyGuestIn(&guestStack, stack, sizeof(guestStack)) safely validates guest memory and throws std::invalid_argument on unreadable guest pointer
- Verified errno preservation pattern across CopyGuestIn matches other functions in core/libs/prx/libSceLibreSsl3/src/Stack.cpp
- Verified deallocation order of guestStack.data followed by stack using free_nid_postfix matches upstream OpenBSD sk_free semantics
- Verified unit tests in core/libs/prx/libSceLibreSsl3/tests/Stack.cpp rigorously test nullptr no-op and bad pointers (0x1, 0x10) ensuring std::invalid_argument is thrown, errno is preserved, and no memory is freed
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
Nothing blocks this change; the targeted code supports the stated safe-copy behavior, and the added test checks invalid pointers, preserved errno, and no frees.
What I ran
Read the prepared diff and changed source and test files at head 5b9c11f2943769cf7b1edcb9cbcd88f8c9518f07. Used repo_read.py search and read operations for the guest-copy implementation and allocator free helper. No test commands were run.
Results
| Check | Result | Note |
|---|---|---|
| Changed source and test review | passed | Both changed files read |
| Related copy and free helpers | passed | Targeted implementation read |
| Test execution | not run | Author reports 159/159 passed |
Findings
Blocking
None.
Non-blocking
None.
Not verified
No test suite, build, or mutation check was run during this review. Author-reported test and mutation results were not independently verified. Read files: core/libs/prx/libSceLibreSsl3/src/Stack.cpp, core/libs/prx/libSceLibreSsl3/tests/Stack.cpp, and targeted ranges of core/libs/prx/libc/src/General.cpp and core/libs/prx/libc/src/FileAndHeap.cpp. Excluded files: none; both files listed as reviewed in the manifest were read.
To get this to a good state
Nothing is required.
|
On Windows, head Existing runs:
All three ran before #26161 merged, so none of them could see the break below. What this run adds. A Windows run of this PR alone on Code.
Negative control and mutation. All of these ran on the merge with the one-line rename above. The mutations were applied to
Tests.
Host:
AI-assisted: yes |
|
@Helldiverr Thanks for catching the silent break. b590668 makes Tested on Linux (GCC 16, Release), with the head merged onto origin/main
AI-assisted: yes (Claude Code) |
|
Thanks, and thanks for the Linux run with the negative control. With
AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The changed stack cleanup now reads its guest header through the guest-copy API and preserves errno on unreadable input; I found no blocking defect in the reviewed code.
What I ran
Reviewed head b5906688542dfafff425944dbf44c1a4601997f4. No commands or tests were run in this review; repo_read.py was unavailable as a command tool, so I used the provided pinned-head reader interface. No merged-preview check was run.
Files read: core/libs/prx/libSceLibreSsl3/src/Stack.cpp, core/libs/prx/libSceLibreSsl3/tests/Stack.cpp, core/libs/prx/libc/src/General.cpp, core/libs/prx/libSceLibreSsl3/src/SslCtxCiphersuites.cpp, and core/libs/prx/libSceLibreSsl3/include/Api.hpp. Both changed files listed in the manifest were read; no files were excluded by the manifest.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Changed code and relevant callers inspected |
| Automated checks | not run | No tests or build run in this review |
| Negative control | not run | Mutation check only reported by the author |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports 159/159 tests and a mutation check passing, but I did not run these checks. Runtime behavior on console hardware and other host operating systems was not verified.
To get this to a good state
Nothing is required.
What
sk_free(src/Stack.cpp) no longer readsstack->datain place. Stacks are guest memory:sk_newallocates them with the guestmalloc, andsk_push/sk_numin the same file already copy the header throughGuestCopyIn. It is not a host-handle false positive.sk_freenow copies the stack header in through the file's existingCopyGuestInhelper before freeing the element array and the stack. Assk_pushin this file already does, an unreadable stack throwsstd::invalid_argumentwith errno preserved, and nothing is freed. A null stack is still a no-op, and valid stacks are freed exactly as before.tools/guest_pointer_audit.py libSceLibreSsl3no longer listssk_free.tools/progress.py --module libSceLibreSsl3gives 550/667 on bothmainand this branch. No debt entry describes the old behaviour, so there is no debt fragment. No listed function was a false positive.Overlap:
python3 tools/pr_overlap.py --names sk_freereports no open pull request.python3 tools/pr_overlap.py --branch fix/libressl3-stack-free-guest-pointers(re-run on 2026-11-20 againstmain0a025bd) reports no overlap with open pull requests.Tested
Arch Linux, GCC, Release, re-run on 2026-11-20 after rebasing onto
main0a025bd.ctest --test-dir build -R 'libressl3|public_headers': 159/159 passed.FreeNullincore/libs/prx/libSceLibreSsl3/tests/Stack.cppnow also passes unmapped stacks (0x1 and 0x10): each call must throwstd::invalid_argument, keep errno and free nothing.Mutation check: with
src/Stack.cppreset toorigin/main,guest_libressl3_stackcrashes with SegFault; with the change it passes.python3 tools/check_conventions.py --base origin/mainpassed.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)