feat(libSceNKWebKit): implement constant-time memory comparison #13770

Closed
hyvvs wants to merge 2 commits from upstream-pr/13770 into main
hyvvs commented 2026-10-31 05:12:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hyvvs on 2026-10-31T05:12:15Z.


What

Implement previously throwing WTF::constantTimeMemcmp(const void*, const void*, size_t) in libSceNKWebKit, preserving the Itanium symbol, System V guest calling convention, and full 0/nonzero byte-comparison behavior. Based on Sony PS5 WebKit 11.x's CryptographicUtilities.cpp. Accumulates XOR differences across the entire input range; does not stop at the first mismatch. The published source's NEVER_INLINE is retained as [[gnu::noinline]]. Nonempty invalid null pointers throw rather than dereferencing invalid memory.

The export is removed from the throwing inventory and implemented in a separate WtfCryptoUtilities.cpp with its typed public declaration. A focused CTest target and debt note document source and limits. No new dependencies or third-party binaries.

Tested

  • PASS: Ubuntu WSL GCC C++20 -O2 -Wall -Wextra -Werror -fsanitize=address,undefined, execution with ASAN_OPTIONS=detect_leaks=1 (empty, identical, prefix, different high bytes, multiple different bytes, unaligned).
  • PASS: Windows MinGW GCC C++20 -O0 -Wall -Wextra -Werror, linked and executed guest SysV ABI standalone test.
  • PASS: python tools/tests/test_progress.py (56 tests), public header audit (393 libraries / 24536 exports), python tools/check_conventions.py --base upstream/main and git diff --check.
  • Progress scanner at base 18f5949788: 7229/27404 -> 7230/27404 (+1 genuine implemented export; inventory unchanged).
  • Not tested: complete CMake/CTest in isolated worktree (third-party SDL2 and FFmpeg submodules not initialized); native PS5 firmware behavior/timing is unmeasured. The source has a HAVE(TIMINGSAFE_BCMP) conditional, whose console setting has not been observed; timing constancy is not established solely by functional tests.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none introduced)
  • Generic behaviour, not specific to one title
  • Depends on: none (other WebKit PRs may require textual merge coordination)
  • Fixes: none
  • Unblocks: none currently demonstrated
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5094788793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13770). Originally posted by [hyvvs](https://github.com/hyvvs) on 2026-10-31T05:12:15Z. --- ### What Implement previously throwing `WTF::constantTimeMemcmp(const void*, const void*, size_t)` in `libSceNKWebKit`, preserving the Itanium symbol, System V guest calling convention, and full 0/nonzero byte-comparison behavior. Based on Sony PS5 WebKit 11.x's [CryptographicUtilities.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/CryptographicUtilities.cpp#L31-L42). Accumulates XOR differences across the *entire* input range; does not stop at the first mismatch. The published source's `NEVER_INLINE` is retained as `[[gnu::noinline]]`. Nonempty invalid null pointers throw rather than dereferencing invalid memory. The export is removed from the throwing inventory and implemented in a separate `WtfCryptoUtilities.cpp` with its typed public declaration. A focused CTest target and debt note document source and limits. No new dependencies or third-party binaries. ### Tested - **PASS**: Ubuntu WSL GCC C++20 `-O2 -Wall -Wextra -Werror -fsanitize=address,undefined`, execution with `ASAN_OPTIONS=detect_leaks=1` (empty, identical, prefix, different high bytes, multiple different bytes, unaligned). - **PASS**: Windows MinGW GCC C++20 `-O0 -Wall -Wextra -Werror`, linked and executed guest SysV ABI standalone test. - **PASS**: `python tools/tests/test_progress.py` (56 tests), public header audit (393 libraries / 24536 exports), `python tools/check_conventions.py --base upstream/main` and `git diff --check`. - Progress scanner at base `18f5949788`: **7229/27404 -> 7230/27404** (+1 genuine implemented export; inventory unchanged). - **Not tested**: complete CMake/CTest in isolated worktree (third-party SDL2 and FFmpeg submodules not initialized); native PS5 firmware behavior/timing is unmeasured. The source has a `HAVE(TIMINGSAFE_BCMP)` conditional, whose console setting has not been observed; timing constancy is not established solely by functional tests. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none introduced) - [x] Generic behaviour, not specific to one title - [x] Depends on: none (other WebKit PRs may require textual merge coordination) - [x] Fixes: none - [x] Unblocks: none currently demonstrated - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-31 06:23:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-31T06:23:46Z.

Review: COMMENTED


Linux run of head 4d9e58c8d2, merged (--no-commit) onto main 6a691f69ee. Ubuntu 26.04 (kernel 7.0), GCC 15.2.0, CMake 4.2.3, Ninja, Release, BUILD_TESTING=ON, i7-8700. The description lists the full CMake/CTest run as not done, so this is that run.

  • guest_nkwebkit_constant_time: passes 3/3.
  • Full build ok. Related subset nkwebkit: 3/3.
  • public_headers: 65/65.
  • Red: throwing at the top of _ZN3WTF18constantTimeMemcmpEPKvS1_m (a stand-in for the main stub) makes guest_nkwebkit_constant_time abort 3/3.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5721622374 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13770#pullrequestreview-5721622374). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-31T06:23:46Z. **Review:** COMMENTED --- Linux run of head `4d9e58c8d2`, merged (`--no-commit`) onto `main` `6a691f69ee`. Ubuntu 26.04 (kernel 7.0), GCC 15.2.0, CMake 4.2.3, Ninja, Release, `BUILD_TESTING=ON`, i7-8700. The description lists the full CMake/CTest run as not done, so this is that run. - `guest_nkwebkit_constant_time`: passes 3/3. - Full build ok. Related subset `nkwebkit`: 3/3. - `public_headers`: 65/65. - Red: throwing at the top of `_ZN3WTF18constantTimeMemcmpEPKvS1_m` (a stand-in for the `main` stub) makes `guest_nkwebkit_constant_time` abort 3/3. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13770
No description provided.