fix(libSceLibreSsl3): copy ASN1_get_object and d2i_ASN1_INTEGER guest pointers safely #22286
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22286"
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 Gruzzberry on 2026-11-17T11:17:28Z.
What
ASN1_get_objectandd2i_ASN1_INTEGERinIntegerDecoder.cppdereferenced guest pointers directly (*input,*output,*tag,*tagClass,*lengthand the input buffer). They now read and write them throughGuestCopyIn_nid_no_patch/GuestCopyOut_nid_no_patch, andd2i_ASN1_INTEGERcopies its input buffer once per call. An unreadable or unwritable pointer throwsstd::invalid_argument, as the null checks already do. Behaviour for valid pointers is unchanged.Tested
g++ -std=c++20 -fsyntax-onlyonIntegerDecoder.cppwith the repo include dirs: no errors. Not linked or run; submodules are not initialised.python3 tools/check_conventions.py --base upstream/main: passed.tools/guest_pointer_audit.py libSceLibreSsl3flagged these lines before the change.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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T11:33:57Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
IntegerDecoder.cpp(254 lines) atfb39cc82ca445de9c664cf7f2890025880817a86, and the diff.repo_read.py search GuestCopyIn_nid_no_patch, to check the helper's call pattern against the repository.core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp. Files reviewed: the same one. Excluded by rule: none.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp:198:d2i_ASN1_INTEGERnow allocateslengthbytes and copies all of them from guest memory before parsing. The old code only touched the bytes the ASN.1 header covers. A guest-suppliedlengthmuch larger than the object allocates that much memory. Alengththat runs past readable guest memory now throwsinvalid_argumentwhere the old code returned the integer. So the description's claim that "behaviour for valid pointers is unchanged" does not hold for these inputs. Smallest fix: parse the header in bounded reads, or cap the copy and state in a comment-free way thatlengthmust be readable.core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp:249–250: ifGuestStore(input, ...)at line 250 throws, theintegeranddataallocations (lines 230 and 241) are never freed.*outputwas already set tointegerat line 249, so the caller gets an exception withoutputpointing at a leaked object. Smallest fix: check thatinputis writable before allocating, or free on that path.core/libs/prx/libSceLibreSsl3/src/IntegerDecoder.cpp:209: the old pointer is now read throughGuestLoad, butFreeInteger(unchanged, lines 139–152) still dereferences the object it points to directly. The fix guards the pointer read, not the object. IfGuestStoreat line 210 throws after the free,*outputis left pointing at freed memory.Not verified
GuestCopyIn_nid_no_patchreturns false, rather than faulting, on unreadable or unmapped guest memory. I checked the call sites only, not the helper.std::length_errororstd::bad_allocfrom the new vector at line 198 is caught at theextern "C"boundary.*outputpoints to (point 3) lives in guest memory.check_conventions.py, duplicate check,guest_pointer_audit.py). None were run here.libSceLibreSsl3in the emulator.To get this to a good state
Nothing is required. The non-blocking points above are optional.