Repository navigation
fix(libSceHttp): zero SceHttpUriElement padding written to the guest - #22121
Conversation
SceHttpUriElement has four bytes of padding after opaque and four after
reserved. sceHttpUriCopy, sceHttpUriParse and sceHttp2 build the element
with aggregate initialisation and copy the whole struct to the guest, so
the padding carried host stack bytes. GCC 15 and newer no longer clear
padding for `{}` initialisation, which made guest_http abort on the
check that sceHttpUriCopy zeroes bytes 4..7 of the output element.
Name the padding as pad0 and pad1 with default initialisers so every
element written to the guest is fully defined, and assert the layout.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 18082b32f1:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_http_testsbuilt cleanly. - CTest (
guest_http,guest_http_uri_locale):1/2 Test #3706: guest_http_uri_locale ............ Passed 0.01 sec 2/2 Test #3704: guest_http ....................... Passed 0.33 sec 100% tests passed, 0 tests failed out of 2 - Negative control: the tests still pass with the change reverted, so they do not cover it
Requesting changes for the points above.
|
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.
|
…piler
The previous checks only looked at sceHttpUriCopy, which already clears
the output with memset, so they passed with the fix reverted. Assert
std::has_unique_object_representations_v<SceHttpUriElement>, which is
false whenever the struct has implicit padding and therefore fails to
compile on every compiler without pad0 and pad1. Also pre-fill the
sceHttpUriParse output with 0xa5 and require bytes 4..7 and 76..79 to
be zero, since `*out = {}` copies members only and leaves the guest's
old padding bytes in place.
|
You're right: the old checks only looked at de8c8c3 adds two checks:
Arch Linux, GCC 16, Release: Negative control, with only With that Both pass again once the fix is back. I have no GCC 13 here. The I also updated the PR body: the earlier "Tested" text said AI-assisted: yes (Claude Code) |
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against de8c8c3858:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_http_testsbuilt cleanly. - CTest (
guest_http,guest_http_uri_locale):1/2 Test #3724: guest_http_uri_locale ............ Passed 0.01 sec 2/2 Test #3722: guest_http ....................... Passed 0.31 sec 100% tests passed, 0 tests failed out of 2 - Negative control: with
core/libs/SceTypes.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass. - Code reading:
- Checked struct SceHttpUriElement layout in core/libs/SceTypes.hpp: size remains exactly 80 bytes, with pad0 (uint32_t) at offset 4 filling the 4-byte gap before 64-bit pointers (scheme at offset 8) and pad1 (uint32_t) at offset 76 filling the 4-byte gap after reserved[10] (offset 66..76) up to 80-byte alignment.
- Verified std::has_unique_object_representations_v in core/libs/tests/GuestHttp.cpp confirms there are zero implicit compiler padding bytes in SceHttpUriElement across LP64 and LLP64 platforms.
- Audited sceHttpUriCopy and sceHttpUriParse guest-memory copying behavior: explicit initialization of pad0 = 0 and pad1 = 0 guarantees zero initialization of all struct bytes across modern GCC/Clang compilers regardless of aggregate init padding semantics.
- Checked test coverage in core/libs/tests/GuestHttp.cpp: asserts static layout requirements, tests that sceHttpUriCopy and sceHttpUriParse zero out both pad0 (+4) and pad1 (+76) when the destination struct is pre-filled with garbage bytes (0x5a and 0xa5), satisfying the negative control requirement.
- Confirmed AGENTS.md compliance: no unauthorized comments, no forbidden files, conventions passed, and no fake or unimplemented stubs introduced.
Looks Good To Me
de8c8c3 to
9e0d5e7
Compare
What
SceHttpUriElement(80 bytes) has four bytes of implicit padding afteropaque(offset 4) and four afterreserved(offset 76).sceHttpUriParsewrites the guest element with*out = {}followed by member stores. The assignment is a trivial copy, which GCC compiles member by member, so the padding bytes the guest already had stay in the struct it gets back. GCC 15 and 16 leave them there with-fzero-init-padding-bits=alltoo: in a standalone repro with the same struct shape, a destination pre-filled witha5still hasa5at byte 76 after*out = {}.The fix names the padding as
pad0andpad1with default initialisers, so every element written to the guest is fully defined regardless of compiler. The layout is unchanged (size 80,schemeat 8,portat 64), and astatic_assertchecks it. The test also assertsstd::has_unique_object_representations_v<SceHttpUriElement>, which is false whenever the struct has implicit padding, soguest_http_testsdoes not compile with the fix reverted on any compiler. A runtime check pre-fills thesceHttpUriParseoutput with0xa5and requires bytes 4..7 and 76..79 to be zero.Tested
Arch Linux (kernel 7.3, glibc 2.44), GCC 16, Release.
ctest --test-dir build -R '^guest_http(_uri_locale)?$': 2/2 passed.ctest --test-dir build -R 'guest_http': 103/103 passed.core/libs/SceTypes.hppreverted tomain:guest_http_testsfails to compile (GuestHttp.cpp:30: static assertion failed, thehas_unique_object_representations_vassert). With that assert also removed,guest_httpaborts (Subprocess aborted) on the newsceHttpUriParsepadding check. With the fix restored both pass.sceHttpUriCopypadding checks pass with the fix reverted, becausesceHttpUriCopyclears the output withmemset. The original GCC 16 abort on those checks no longer reproduces on currentmain. Those checks are kept as they describe the required output.static_assertdepends only on the struct layout, which is the same on every x86-64 compiler, so it fails there too. Whether the runtime check fails on GCC 13 depends on its codegen for*out = {}.python3 tools/check_conventions.py --base origin/main: passed.tools/progress.pyoutput is identical before and after the test commit. No debt entry is affected.Overlap
python3 tools/pr_overlap.py --branch fix/http-uri-element-padding: 6 PRs share files, 4 could not be compared automatically because they conflict with the base. Checked by hand:core/libs/SceTypes.hpp, notSceHttpUriElement.core/libs/tests/GuestHttp.cppand useSceHttpUriElement element{}; neither changes the struct, and both benefit from this fix.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)