loader: check DT_OS_SYMTAB against its backing buffer #1370

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

@⁠HamsterCL on GitHub · 2026-10-10 12:51 UTC · original
HamsterCL:fix/dynlib-symtab-extent → main · +40 −1 · 3 files · 2 commits · closed without merging

Summary

DT_OS_SYMTAB / DT_OS_SYMTABSZ come from the guest and were used to index the symbol table without checking that the table fits in memory.

  • Elf64 now remembers the size of the PT_OS_DYNLIBDATA segment (GetDynamicDataSize()).
  • When the dynamic info is parsed, exit unless the table lies inside that buffer (or inside the mapped program for DT_SYMTAB) and its size is a multiple of sizeof(Elf64_Sym).

Split out of the closed #1329.

**@⁠HamsterCL** on GitHub · 2026-10-10 12:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1370) `HamsterCL:fix/dynlib-symtab-extent` → `main` · +40 −1 · 3 files · 2 commits · closed without merging ## Summary `DT_OS_SYMTAB` / `DT_OS_SYMTABSZ` come from the guest and were used to index the symbol table without checking that the table fits in memory. - `Elf64` now remembers the size of the `PT_OS_DYNLIBDATA` segment (`GetDynamicDataSize()`). - When the dynamic info is parsed, exit unless the table lies inside that buffer (or inside the mapped program for `DT_SYMTAB`) and its size is a multiple of `sizeof(Elf64_Sym)`. Split out of the closed #1329.
DT_OS_SYMTAB and DT_OS_SYMTABSZ come from the guest and were used to
index the symbol table without checking that the table fits in memory.
Remember the size of the PT_OS_DYNLIBDATA segment in Elf64 and, when the
dynamic info is parsed, exit unless the table lies inside that buffer
(or inside the mapped program for DT_SYMTAB) and its size is a multiple
of sizeof(Elf64_Sym).
A standard SysV ELF has DT_SYMTAB but no DT_OS_SYMTABSZ, so
symbol_table_total_size stayed zero and relocation symbol bounds could not be
checked. Read nchain from the validated DT_HASH header and use it as the table
size before the range check.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:54:38 +00:00
github-bot closed this pull request 2026-11-26 09:54:38 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-10 12:57 UTC · original · edited 2026-10-10 14:58 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: 04446adf-015b-4992-808d-b2d45280debd


📥 Commits

Reviewing files that changed from the base of the PR and between d9a5d06802 and d31c4611a0.



📒 Files selected for processing (1)
  • src/loader/runtimeLinker.cpp


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


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




📝 Walkthrough
📝 Walkthrough

Walkthrough

The ELF loader tracks the size of its dynamic-data buffer and exposes it through a public accessor. The runtime linker checks that a present symbol table consists of whole Elf64_Sym entries and fits within its backing region. For DT_OS_SYMTAB, it checks the dynamic-data buffer. For standard DT_SYMTAB without a declared size, it can derive the symbol count from DT_HASH after checking the hash-header bounds.



Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to d31c4

The new symbol-table bounds checks do not leave an established PR-introduced issue blocking merge. Unchecked relocation indices remain a separate, pre-existing concern.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 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 Direct issue #1329 is closed and supplies historical context only. No active directly linked issue supplies coding requirements for this pull request.
Out of Scope Changes check Passed The changes remain within the stated loader scope. Elf64 records the PT_OS_DYNLIBDATA size, and RuntimeLinker::ParseProgramDynamicInfo bounds-checks the symbol table and derives the SysV size fr…
Title check Passed The title clearly and concisely describes the main change: validating DT_OS_SYMTAB against its backing buffer.
Description check Passed The description directly explains the bounds checks, dynamic-data size tracking, SysV ELF handling, and the related security issue.

  • 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-10 12:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1370#issuecomment-6097739996) · edited 2026-10-10 14:58 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/1370?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `04446adf-015b-4992-808d-b2d45280debd` <hr> </dd> </dl> <hr> </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> <dl> <dd> Reviewing files that changed from the base of the PR and between d9a5d06802a5532d705e65e8074072a5a2c9f2c6 and d31c4611a0f2d4c1159667db1482a2d93b623b0a. <hr> </dd> </dl> <hr> </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing (1)</strong></summary> <dl> <dd> <dl> <dd> * `src/loader/runtimeLinker.cpp` <hr> </dd> </dl> <hr> </dd> </dl> </details> <details> <summary><strong>🚧 Files skipped from review as they are similar to previous changes (1)</strong></summary> <dl> <dd> <dl> <dd> * src/loader/runtimeLinker.cpp <hr> </dd> </dl> <hr> </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. <hr> </dd> </dl> <hr> </dd> </dl> </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough The ELF loader tracks the size of its dynamic-data buffer and exposes it through a public accessor. The runtime linker checks that a present symbol table consists of whole `Elf64_Sym` entries and fits within its backing region. For `DT_OS_SYMTAB`, it checks the dynamic-data buffer. For standard `DT_SYMTAB` without a declared size, it can derive the symbol count from `DT_HASH` after checking the hash-header bounds. <hr> </dd> </dl> </details> <hr> </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"d31c4611a0f2d4c1159667db1482a2d93b623b0a" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **⚪ Minimal** · up to `d31c4` <!-- final_review_risk_coverage:{"sourceCommitId":"d31c4611a0f2d4c1159667db1482a2d93b623b0a","coveredCommitId":"d31c4611a0f2d4c1159667db1482a2d93b623b0a","kind":"reviewed"} --> The new symbol-table bounds checks do not leave an established PR-introduced issue blocking merge. Unchecked relocation indices remain a separate, pre-existing concern. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>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</strong></summary> <dl> <dd> ### ❌ 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 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ Passed checks (4 passed)</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Direct issue `#1329` is closed and supplies historical context only. No active directly linked issue supplies coding requirements for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changes remain within the stated loader scope. `Elf64` records the `PT_OS_DYNLIBDATA` size, and `RuntimeLinker::ParseProgramDynamicInfo` bounds-checks the symbol table and derives the SysV size fr… | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: validating DT_OS_SYMTAB against its backing buffer. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the bounds checks, dynamic-data size tracking, SysV ELF handling, and the related security issue. | </dd> </dl> </details> <hr> </dd> </dl> </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=1370)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [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> </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -1907,0 +1937,4 @@
EXIT_NOT_IMPLEMENTED(symtab_offset > region_size ||
program->dynamic_info->symbol_table_total_size >
region_size - symtab_offset);
}
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-10 12:57 UTC · original · edited 2026-10-10 13:19 UTC

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

git diff --unified=8 307fdcf7ad5d9d15b5966288fcc598ac9dbca188 d9a5d06802a5532d705e65e8074072a5a2c9f2c6 -- src/loader/elf.h src/loader/elf.cpp src/loader/runtimeLinker.cpp
sed -n '1870,1940p' src/loader/runtimeLinker.cpp
sed -n '790,840p' src/loader/runtimeLinker.cpp
rg -n 'DT_HASH|DT_GNU_HASH|DT_OS_SYMTABSZ|symbol_table_total_size|symbol_table\\[' src/loader

Repository: KytyPS5/KytyPS5

Length of output: 10529


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- relevant references ---'
rg -n -F --glob '*.cpp' --glob '*.h' -- 'DT_HASH' src/loader || test "$?" -eq 1
rg -n -F --glob '*.cpp' --glob '*.h' -- 'DT_OS_SYMTABSZ' src/loader || test "$?" -eq 1
rg -n -F --glob '*.cpp' --glob '*.h' -- 'symbol_table_total_size' src/loader || test "$?" -eq 1
rg -n -F --glob '*.cpp' --glob '*.h' -- 'CreateSymbolDatabase' src/loader || test "$?" -eq 1
printf '%s\n' '--- dynamic helpers and database ---'
sed -n '730,890p' src/loader/runtimeLinker.cpp
sed -n '2050,2145p' src/loader/runtimeLinker.cpp
printf '%s\n' '--- relocation/database call sites ---'
rg -n -F --glob '*.cpp' --glob '*.h' -- 'GetRelocationInfo' src/loader || test "$?" -eq 1
rg -n -F --glob '*.cpp' --glob '*.h' -- 'CreateSymbolDatabase(' src/loader || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 10715


Derive the standard symbol-table size before relocation.

ParseProgramDynamicInfo reads DT_HASH only as a pointer. It does not read nchain into symbol_table_total_size; that field is set only by project-specific DT_OS_SYMTABSZ. A standard SysV ELF can omit that tag, so the field remains zero and the current checks accept it.

CreateSymbolDatabase then iterates zero entries, while GetRelocationInfo directly evaluates symbol_table[symbol]. A symbol-bearing relocation can therefore read beyond the actual symbol table.

Do not reject zero in the standard DT_SYMTAB branch. Derive the symbol count from validated DT_HASH metadata, or another validated standard source, and use it for the size and bounds checks.

✅ Addressed in commit d31c461

**@⁠coderabbitai[bot]** on GitHub · 2026-10-10 12:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1370#discussion_r4237688035) · edited 2026-10-10 13:19 UTC **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash git diff --unified=8 307fdcf7ad5d9d15b5966288fcc598ac9dbca188 d9a5d06802a5532d705e65e8074072a5a2c9f2c6 -- src/loader/elf.h src/loader/elf.cpp src/loader/runtimeLinker.cpp sed -n '1870,1940p' src/loader/runtimeLinker.cpp sed -n '790,840p' src/loader/runtimeLinker.cpp rg -n 'DT_HASH|DT_GNU_HASH|DT_OS_SYMTABSZ|symbol_table_total_size|symbol_table\\[' src/loader ``` Repository: KytyPS5/KytyPS5 Length of output: 10529 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- relevant references ---' rg -n -F --glob '*.cpp' --glob '*.h' -- 'DT_HASH' src/loader || test "$?" -eq 1 rg -n -F --glob '*.cpp' --glob '*.h' -- 'DT_OS_SYMTABSZ' src/loader || test "$?" -eq 1 rg -n -F --glob '*.cpp' --glob '*.h' -- 'symbol_table_total_size' src/loader || test "$?" -eq 1 rg -n -F --glob '*.cpp' --glob '*.h' -- 'CreateSymbolDatabase' src/loader || test "$?" -eq 1 printf '%s\n' '--- dynamic helpers and database ---' sed -n '730,890p' src/loader/runtimeLinker.cpp sed -n '2050,2145p' src/loader/runtimeLinker.cpp printf '%s\n' '--- relocation/database call sites ---' rg -n -F --glob '*.cpp' --glob '*.h' -- 'GetRelocationInfo' src/loader || test "$?" -eq 1 rg -n -F --glob '*.cpp' --glob '*.h' -- 'CreateSymbolDatabase(' src/loader || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 10715 --- </details> **Derive the standard symbol-table size before relocation.** `ParseProgramDynamicInfo` reads `DT_HASH` only as a pointer. It does not read `nchain` into `symbol_table_total_size`; that field is set only by project-specific `DT_OS_SYMTABSZ`. A standard SysV ELF can omit that tag, so the field remains zero and the current checks accept it. `CreateSymbolDatabase` then iterates zero entries, while `GetRelocationInfo` directly evaluates `symbol_table[symbol]`. A symbol-bearing relocation can therefore read beyond the actual symbol table. Do not reject zero in the standard `DT_SYMTAB` branch. Derive the symbol count from validated `DT_HASH` metadata, or another validated standard source, and use it for the size and bounds checks. <!-- fingerprinting:phantom:medusa:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:33b6ea30f1e675f0a4c7c339 --> <!-- This is an auto-generated comment by CodeRabbit --> ✅ Addressed in commit d31c461
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-10 12:57 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: e16e3828-2a5f-4ddb-a3ce-e8688d763066
📥 Commits

Reviewing files that changed from the base of the PR and between 307fdcf7ad and d9a5d06802.

📒 Files selected for processing (3)
  • src/loader/elf.cpp
  • src/loader/elf.h
  • 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-10 12:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1370#pullrequestreview-5479022433) · **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**: `e16e3828-2a5f-4ddb-a3ce-e8688d763066` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 307fdcf7ad5d9d15b5966288fcc598ac9dbca188 and d9a5d06802a5532d705e65e8074072a5a2c9f2c6. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/loader/elf.cpp` * `src/loader/elf.h` * `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=f2b58cbf-55e1-4a77-8e27-6bb6be173707 attempt=347b0289-0d67-4638-adb4-0c99bc50a3ad batch=1/1 -->
Author
Owner

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

@⁠coderabbitai review

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

@⁠coderabbitai[bot] on GitHub · 2026-10-10 14:58 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-10 14:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1370#issuecomment-6098810975) <!-- This is an auto-generated reply by CodeRabbit --> <!-- CodeRabbit review command invocation: v2:58ae699fb961fd3b56f90ca44d25c08a7e469816c02b91eec28304dc1ebdfc3c --> <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.