hw_oracle/drm: harden ELF64 bounds, subprocess timeouts, and temp cleanup #2328

Open
github-bot wants to merge 1 commit from github-bot/gh-2328 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 13:51 UTC · original
kirigayakazima:fix/hw-oracle-drm-elf-safety → main · +209 −21 · 2 files · 1 commits · open

Claimed in the coordination issue as: HW-ORACLE-DRM-ELF-BOUNDS-TIMEOUT-AND-TEMP-CLEANUP (#1608)

What and why

  • Add ELF64 section header, string table, symbol table, .text slice, and kernel descriptor bounds checks (including value < address underflow protection) in tools/hw_oracle/drm.py so truncated or corrupt objects raise ValueError instead of struct.error or out-of-range indexing.
  • Reject blank LEONIDA_HW_DRM_NODE values in find_node() with Unavailable.
  • Add SUBPROCESS_TIMEOUT = 120 to pkg-config, compiler, launcher device probe, assembler, and _launch() subprocess invocations, converting (OSError, subprocess.TimeoutExpired) into Unavailable, (None, str(e)), or (-1, "", str(e)).
  • Stage compiled hw_oracle_drm binaries in _build_launcher() with tempfile.mkstemp() and unlink temporary binaries on build or replace failure.
  • Add standard-library unit tests in tests/test_hw_oracle_drm_safety.py.

Tested

  • python -I tests/test_hw_oracle_drm_safety.py -v: 3 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 2 errors).
  • python -I tests/test_hw_oracle.py -v: 59 tests (OK, 3 skipped without AMD clang / libdrm gcc on host).
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tools/hw_oracle/drm.py tests/test_hw_oracle_drm_safety.py, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠kirigayakazima** on GitHub · 2026-11-26 13:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2328) `kirigayakazima:fix/hw-oracle-drm-elf-safety` → `main` · +209 −21 · 2 files · 1 commits · open Claimed in the coordination issue as: HW-ORACLE-DRM-ELF-BOUNDS-TIMEOUT-AND-TEMP-CLEANUP (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why - Add ELF64 section header, string table, symbol table, `.text` slice, and kernel descriptor bounds checks (including `value < address` underflow protection) in `tools/hw_oracle/drm.py` so truncated or corrupt objects raise `ValueError` instead of `struct.error` or out-of-range indexing. - Reject blank `LEONIDA_HW_DRM_NODE` values in `find_node()` with `Unavailable`. - Add `SUBPROCESS_TIMEOUT = 120` to `pkg-config`, compiler, launcher device probe, assembler, and `_launch()` subprocess invocations, converting `(OSError, subprocess.TimeoutExpired)` into `Unavailable`, `(None, str(e))`, or `(-1, "", str(e))`. - Stage compiled `hw_oracle_drm` binaries in `_build_launcher()` with `tempfile.mkstemp()` and unlink temporary binaries on build or replace failure. - Add standard-library unit tests in `tests/test_hw_oracle_drm_safety.py`. ### Tested - `python -I tests/test_hw_oracle_drm_safety.py -v`: 3 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 2 errors). - `python -I tests/test_hw_oracle.py -v`: 59 tests (`OK`, 3 skipped without AMD clang / libdrm gcc on host). - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tools/hw_oracle/drm.py tests/test_hw_oracle_drm_safety.py`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:55:52 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:42 UTC · original · approved these changes

Approving 6455daffe.

The ELF64 reader now checks the header size, the section table, shstrndx, each string table and string, the symbol table and the kernel descriptor against the file's length, so a truncated or hostile file raises a ValueError instead of indexing past the end. The helper build writes to a mkstemp name next to the executable and removes it on failure, and the subprocesses have timeouts that end as Unavailable.

Merged onto main d1dff7949 in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. tests/test_hw_oracle_drm_safety.py: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠tiguan26** on GitHub · 2026-11-27 04:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2328#pullrequestreview-6083576439) · **approved these changes** Approving 6455daffe. The ELF64 reader now checks the header size, the section table, `shstrndx`, each string table and string, the symbol table and the kernel descriptor against the file's length, so a truncated or hostile file raises a `ValueError` instead of indexing past the end. The helper build writes to a `mkstemp` name next to the executable and removes it on failure, and the subprocesses have timeouts that end as `Unavailable`. Merged onto `main` `d1dff7949` in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13. `tests/test_hw_oracle_drm_safety.py`: 3 passed (new). AI-assisted (Claude Code, Claude Opus 5.5).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2328/head:github-bot/gh-2328'
git switch 'github-bot/gh-2328'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2328'
git switch 'github-bot/gh-2328'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2328'
git switch 'github-bot/gh-2328'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2328'
git switch 'main'
git merge --squash 'github-bot/gh-2328'
git switch 'main'
git merge --ff-only 'github-bot/gh-2328'
git switch 'main'
git merge 'github-bot/gh-2328'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.