loader/libs: validate guest-controlled ELF, AJM and socket-option inputs #1329

Closed
github-bot wants to merge 2 commits from gh-pr/1329/head into gh-pr/1329/base
Owner

@⁠HamsterCL on GitHub · 2026-10-09 20:44 UTC · original
HamsterCL:fix/loader-libs-input-validation → main · +89 −8 · 6 files · 2 commits · closed without merging

Split out of #1313 (closed).

  • runtimeLinker / elf: bounds-check SELF program-header ids, relocation symbol indices and the guest-declared symbol table (extent, whole entries); reject p_filesz > p_memsz.
  • gamePatch: overflow-safe range check against the mapped program size.
  • ajm: reject split-buffer sizes that overflow.
  • network: convert SO_RCVTIMEO/SO_SNDTIMEO between guest and host units and validate the option size.

Built and ran all 53 ctest tests locally (Windows, clang-cl).

**@⁠HamsterCL** on GitHub · 2026-10-09 20:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329) `HamsterCL:fix/loader-libs-input-validation` → `main` · +89 −8 · 6 files · 2 commits · closed without merging Split out of #1313 (closed). - **runtimeLinker / elf**: bounds-check SELF program-header ids, relocation symbol indices and the guest-declared symbol table (extent, whole entries); reject `p_filesz > p_memsz`. - **gamePatch**: overflow-safe range check against the mapped program size. - **ajm**: reject split-buffer sizes that overflow. - **network**: convert `SO_RCVTIMEO`/`SO_SNDTIMEO` between guest and host units and validate the option size. Built and ran all 53 ctest tests locally (Windows, clang-cl).
- runtimeLinker/elf: bounds-check SELF program-header ids, relocation symbol
  indices and the guest-declared symbol table (extent and whole entries);
  reject p_filesz > p_memsz.
- gamePatch: overflow-safe range check against the mapped program size.
- ajm: reject split-buffer sizes that overflow.
- network: convert SO_RCVTIMEO/SO_SNDTIMEO between guest and host units and
  validate the option size.
OS symbol tables live in the separate PT_OS_DYNLIBDATA allocation, not in the mapped program, so the base_vaddr-relative check rejected valid files. Track the dynamic-data size and bound-check against it; keep the mapped-program check for DT_SYMTAB.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:53:18 +00:00
github-bot closed this pull request 2026-11-26 09:53:18 +00:00
Author
Owner

@⁠HamsterCL on GitHub · 2026-10-09 20:45 UTC · original

@⁠coderabbitai review

**@⁠HamsterCL** on GitHub · 2026-10-09 20:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#issuecomment-6088956484) @⁠coderabbitai review
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:47 UTC · original · edited 2026-10-09 21:10 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6a0ed77b-ccbe-4a6f-a380-fde6bcee6e4a

📥 Commits

Reviewing files that changed from the base of the PR and between 153b3d892e and b6b4b62710.


📒 Files selected for processing (3)
  • src/loader/elf.cpp
  • src/loader/elf.h
  • src/loader/runtimeLinker.cpp

🚧 Files skipped from review as they are similar to previous changes (2)
  • src/loader/elf.cpp
  • src/loader/runtimeLinker.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.



📝 Walkthrough

Walkthrough

The changes add overflow checks to split-buffer decoding and bounds checks to ELF loading, mapped address ranges, segments, and symbol tables. Elf64 now stores and exposes the loaded dynamic-data size. Socket-option handling adds receive-timeout mapping and conversion between guest milliseconds and host units. Unsupported socket-level options now return an error.

Suggested reviewers: nmzik


Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to b6b4b

No confirmed regression warrants blocking merge. The target-specific socket timeout layout could not be verified, so no ABI mismatch is established.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly summarizes the main change: validation of guest-controlled inputs across loader libraries, AJM, and socket options.
Description check Passed The description directly covers the changes in the pull request and reports the local test results.


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#issuecomment-6088987003) · edited 2026-10-09 21:10 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1329?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `6a0ed77b-ccbe-4a6f-a380-fde6bcee6e4a` <hr> </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 153b3d892edee41529e190197c042fc39fd5ec63 and b6b4b62710c2f47aa720a637917b136b273378f0. <hr> </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/loader/elf.cpp` * `src/loader/elf.h` * `src/loader/runtimeLinker.cpp` <hr> </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * src/loader/elf.cpp * src/loader/runtimeLinker.cpp <hr> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review. <hr> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The changes add overflow checks to split-buffer decoding and bounds checks to ELF loading, mapped address ranges, segments, and symbol tables. `Elf64` now stores and exposes the loaded dynamic-data size. Socket-option handling adds receive-timeout mapping and conversion between guest milliseconds and host units. Unsupported socket-level options now return an error. **Suggested reviewers:** `nmzik` <hr> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"b6b4b62710c2f47aa720a637917b136b273378f0" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `b6b4b` <!-- final_review_risk_coverage:{"sourceCommitId":"b6b4b62710c2f47aa720a637917b136b273378f0","coveredCommitId":"b6b4b62710c2f47aa720a637917b136b273378f0","kind":"reviewed"} --> No confirmed regression warrants blocking merge. The target-specific socket timeout layout could not be verified, so no ABI mismatch is established. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>Pre-merge checks | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v1.svg" width="14" height="17" align="middle" alt="Passed" title="Passed"></picture></sup> 4 | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v1.svg" width="14" height="17" align="middle" alt="Failed" title="Failed"></picture></sup> 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 6 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------ | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main change: validation of guest-controlled inputs across loader libraries, AJM, and socket options. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly covers the changes in the pull request and reports the local test results. | <hr> </details> <hr> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1329)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) <hr> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:47 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4ee9aa5e-9842-43e5-80b5-06b8aa4359ad
📥 Commits

Reviewing files that changed from the base of the PR and between 59183dbfa8 and 153b3d892e.

📒 Files selected for processing (5)
  • src/libs/ajm.cpp
  • src/libs/network.cpp
  • src/loader/elf.cpp
  • src/loader/gamePatch.cpp
  • src/loader/runtimeLinker.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#pullrequestreview-5475200766) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `4ee9aa5e-9842-43e5-80b5-06b8aa4359ad` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 59183dbfa81ed7efdff6069177fed50de0552725 and 153b3d892edee41529e190197c042fc39fd5ec63. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `src/libs/ajm.cpp` * `src/libs/network.cpp` * `src/loader/elf.cpp` * `src/loader/gamePatch.cpp` * `src/loader/runtimeLinker.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=ed0704f2-a138-4466-b034-86b90a01a00e attempt=54e62293-2f29-445b-9a6b-d222b807470d batch=1/1 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:47 UTC · original · edited 2026-10-09 20:57 UTC
On src/loader/runtimeLinker.cpp line 1919 (outdated):

@@ -1904,6 +1910,20 @@ void RuntimeLinker::ParseProgramDynamicInfo(Program* program) {
 	GetDynDataOs(elf, &program->dynamic_info->symbol_table, DT_OS_SYMTAB);
 	GetDynData(elf, program->base_vaddr, &program->dynamic_info->symbol_table, DT_SYMTAB);
 	GetDynValue(elf, &program->dynamic_info->symbol_table_total_size, DT_OS_SYMTABSZ);
+
+	// DT_OS_SYMTAB/DT_OS_SYMTABSZ are guest-controlled; make sure the declared
+	// symbol table actually lies within this program's mapped memory before
+	// anything (GetRelocationInfo, CreateSymbolDatabase) indexes into it.
+	if (program->dynamic_info->symbol_table != nullptr) {
+		const auto symtab_addr = reinterpret_cast<uint64_t>(program->dynamic_info->symbol_table);
+		EXIT_NOT_IMPLEMENTED(symtab_addr < program->base_vaddr);

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Validate DT_OS_SYMTAB against its own buffer.

When an ELF uses DT_OS_SYMTAB, GetDynDataOs obtains the symbol table from Elf64::GetDynamicData. Elf64::Open loads that data into the separate m_dynamic_data allocation. This check instead requires the pointer to be at or above program->base_vaddr, so a valid OS symbol table causes ParseProgramDynamicInfo to terminate. Validate OS symbol tables against the dynamic-data allocation. Keep the program-mapping check for DT_SYMTAB.

✅ Addressed in commit b6b4b62

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:47 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#discussion_r4234417710) · edited 2026-10-09 20:57 UTC On `src/loader/runtimeLinker.cpp` line 1919 (outdated): ```diff @@ -1904,6 +1910,20 @@ void RuntimeLinker::ParseProgramDynamicInfo(Program* program) { GetDynDataOs(elf, &program->dynamic_info->symbol_table, DT_OS_SYMTAB); GetDynData(elf, program->base_vaddr, &program->dynamic_info->symbol_table, DT_SYMTAB); GetDynValue(elf, &program->dynamic_info->symbol_table_total_size, DT_OS_SYMTABSZ); + + // DT_OS_SYMTAB/DT_OS_SYMTABSZ are guest-controlled; make sure the declared + // symbol table actually lies within this program's mapped memory before + // anything (GetRelocationInfo, CreateSymbolDatabase) indexes into it. + if (program->dynamic_info->symbol_table != nullptr) { + const auto symtab_addr = reinterpret_cast<uint64_t>(program->dynamic_info->symbol_table); + EXIT_NOT_IMPLEMENTED(symtab_addr < program->base_vaddr); ``` **🎯 Functional Correctness** | **🟠 Major** | **🏗️ Heavy lift** **Validate `DT_OS_SYMTAB` against its own buffer.** When an ELF uses `DT_OS_SYMTAB`, `GetDynDataOs` obtains the symbol table from `Elf64::GetDynamicData`. `Elf64::Open` loads that data into the separate `m_dynamic_data` allocation. This check instead requires the pointer to be at or above `program->base_vaddr`, so a valid OS symbol table causes `ParseProgramDynamicInfo` to terminate. Validate OS symbol tables against the dynamic-data allocation. Keep the program-mapping check for `DT_SYMTAB`. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:03f5675b1714bf018def4fdb --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit b6b4b62
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 20:49 UTC · original

⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 20:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#issuecomment-6089018024) <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: v2:30be813ba450ff6a8fe33df0720315f902ba66104785f07a48d04269dc3a9ceb --> <details> <summary>⚠️ Action not completed</summary> Already reviewed the last commit. Use `@coderabbitai full review` to rerun a review of the entire changeset. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused. </details>
Author
Owner

@⁠HamsterCL on GitHub · 2026-10-09 20:58 UTC · original

@⁠coderabbitai review

**@⁠HamsterCL** on GitHub · 2026-10-09 20:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#issuecomment-6089140002) @⁠coderabbitai review
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-09 21:10 UTC · original

⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-09 21:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1329#issuecomment-6089321670) <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: v2:fb7413f8569ea7786736863428d7ccbd4fa2bace394aa0410cc4f951b4c4beb4 --> <details> <summary>⚠️ Action not completed</summary> Already reviewed the last commit. Use `@coderabbitai full review` to rerun a review of the entire changeset. > Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused. </details>

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.