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

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/hw-oracle-drm-elf-safety into main 2026-11-28 10:58:31 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 13:51:06 +00:00

Claimed in the coordination issue as: HW-ORACLE-DRM-ELF-BOUNDS-TIMEOUT-AND-TEMP-CLEANUP (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193870891)

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.
Claimed in the coordination issue as: HW-ORACLE-DRM-ELF-BOUNDS-TIMEOUT-AND-TEMP-CLEANUP (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193870891) ### 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.
tiguan26 approved these changes 2026-11-27 04:42:29 +00:00
tiguan26 left a comment

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).

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).
zmasi commented 2026-11-28 10:03:42 +00:00

#2328 | head 6455daffeef71ab7f06c3a1a6023e1d774eeac42 (merged cleanly with main 33db04a70) | python -I tests/test_hw_oracle_drm_safety.py | red on main: FAILED (errors=2) (malformed ELF64 headers/sections fail with struct.error / out-of-bounds reads instead of ValueError, and SUBPROCESS_TIMEOUT is absent) | green on PR+main: 3 tests OK (-k test_elf64_bounds_reject_malformed_headers_and_descriptors: 1 test OK) | Windows 11, Python 3.12.10 | AI-assisted: yes

Audited _symbols, text_section, kernel_registers, and DrmOracle subprocess timeout / mkstemp cleanup handling in tools/hw_oracle/drm.py, and verified both PR + main (33db04a70) and a combined main + #2328 + #2326 merge (0 conflicts; 3 OK + 3 OK). Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py.

#2328 | head 6455daffeef71ab7f06c3a1a6023e1d774eeac42 (merged cleanly with main 33db04a70) | `python -I tests/test_hw_oracle_drm_safety.py` | red on main: `FAILED (errors=2)` (malformed ELF64 headers/sections fail with `struct.error` / out-of-bounds reads instead of `ValueError`, and `SUBPROCESS_TIMEOUT` is absent) | green on PR+main: `3 tests OK` (`-k test_elf64_bounds_reject_malformed_headers_and_descriptors`: `1 test OK`) | Windows 11, Python 3.12.10 | AI-assisted: yes Audited `_symbols`, `text_section`, `kernel_registers`, and `DrmOracle` subprocess timeout / `mkstemp` cleanup handling in `tools/hw_oracle/drm.py`, and verified both `PR + main` (`33db04a70`) and a combined `main + #2328 + #2326` merge (`0` conflicts; `3 OK` + `3 OK`). Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py`.
DadaCap commented 2026-11-28 10:58:34 +00:00

Merged, thank you @kirigayakazima! This PR (hw_oracle/drm: harden ELF64 bounds, subprocess timeouts, and temp cleanup) was checked by zmasi or sodove and then by our own local run of its tests with main merged in, and it passed cleanly, so it went in with its reviewed batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @kirigayakazima! This PR (hw_oracle/drm: harden ELF64 bounds, subprocess timeouts, and temp cleanup) was checked by zmasi or sodove and then by our own local run of its tests with main merged in, and it passed cleanly, so it went in with its reviewed batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.