Skip to content

fix(ghidra): protect only unapplied relocation destinations, not their whole block - #11996

Merged
morluto merged 2 commits into
morluto:mainfrom
AurelioB:fix/loader-relocation-slot-volatility
Nov 19, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
AurelioB:fix/loader-relocation-slot-volatility

Conversation

@AurelioB

Copy link
Copy Markdown
Contributor

Summary

Since #10483, an unapplied loader relocation in a non-writable block makes that whole block volatile. TLS slots are such relocations, and they sit in .got beside the GOT entries Ghidra did apply. In any shared object or PIE with an initial-exec or dynamic TLS slot, the whole .got becomes volatile and every GOT-indirect call stops decompiling to its target. This PR keeps #10483's protection but sets volatility on each unapplied destination's own data item, so the applied GOT entries beside it stay foldable.

Problem and expected behavior

  • Trigger: an ELF shared object or PIE whose read-only .got holds both applied entries and an unapplied TLS slot (R_MIPS_TLS_DTPMOD32/DTPREL32/TPREL32, R_X86_64_TPOFF64). Ghidra 12.1.4 imports the TLS slot as UNSUPPORTED.
  • Violated invariant (stated in fix(ghidra): prevent loader relocations from constant folding #10483 and docs/providers/ghidra-provider.md): "Applied relocations such as GOT entries stay foldable, so external calls keep their names."
  • Observed on main 336054918, real Ghidra 12.1.4, a MIPS32 firmware library (libdsd2pcm.so, one R_MIPS_TLS_TPREL32 slot in .got). rea function … _init gives (*(code *)(puVar1 + 0x45e0))(); (*(code *)(puVar1 + 0x5030))(); where it gave FUN_000045e0(); FUN_00015030(); before fix(ghidra): prevent loader relocations from constant folding #10483. 16 of the 85 MIPS shared libraries in that firmware carry TLS relocations (libc, libpthread, libstdc++, libasound…). On x86-64 the host libstdc++.so.6 has 5 unapplied TLS slots in its read-only .got.
  • Expected: the unapplied destination is not folded, and applied GOT entries in the same block still resolve.

Change and scope

  • ReaGhidraBridge.protectLoaderInitializedRelocations marks each unapplied destination volatile through its data item's Mutability setting (MutabilitySettingsDefinition.VOLATILE), which the decompiler reads per address before the block flag. Where nothing is defined, it creates an undefined data item of the relocation's length; an existing item that starts at the destination and covers it is reused. Only when an instruction, or a data item starting before the destination, occupies it does the bridge fall back to marking the whole block volatile, as today.
  • Unchanged: eligibility (unapplied status, loaded, initialized, non-writable block, ELF shared objects and PIEs only), the limitation text, the read-only path for Windows P0 and existing projects, block permissions and source FileBytes.
  • loader_relocation_semantics is renamed from volatile-unapplied-relocation-blocks to volatile-unapplied-relocation-destinations so the profile states the new behavior. The committed producer already changes with the bridge digest, so snapshot invalidation does not depend on this rename.
  • Not included: resolving TLS accesses to variables.

Follow the contribution scope.
Unresolved scope, authority, side effects, or required verification block
integration. Link the required maintainer scope decision for new providers or
capabilities involving target execution, injection, mutation, or protection
recovery; ordinary fixes within existing boundaries may state "not applicable".
Draft PRs may leave the scope decision pending and the readiness and merge checklists
unchecked. Maintainers can help resolve open questions.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the Ghidra bridge's loader-relocation protection, before the decompiler opens. Consumers: decompiled pseudocode, and the profile's loader_relocation_semantics.
  • Contribution scope fit and linked maintainer decision: not applicable; narrows an existing read-only mitigation.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: Ghidra bridge only. The data items it creates live in the ephemeral database.
  • Evidence, artifact, provenance, or reconstruction contract: loader_relocation_semantics value renamed; Ghidra profile digests and Evidence IDs change, as they do with any bridge change through producer.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

The launched process is the existing headless Ghidra import; target code is never run.

Evidence and regression coverage

  • Tests added or updated:
    • verify:ghidra:loader-relocation: the fixture's provider library now defines an initial-exec TLS variable, and the PIE reads it. The probe requires its R_X86_64_TPOFF64 slot to be unapplied and in the same block as the applied GOT entries, the block and those entries to stay non-volatile, and both unapplied destinations (the copy relocation and the TLS slot) to have volatile data items. The existing full-RELRO GOT caller must still decompile identically before and after protection.
    • On main's bridge the updated probe fails at applied_got_relocations_not_volatile; with this change it passes.
    • GhidraProvider.behavior.test.ts: the renamed semantics value.
  • Base reproduction or other evidence: the firmware output above, on main 336054918 and with this change.
  • User-visible CLI/MCP output: rea function libdsd2pcm.so _init --provider ghidra --json returns __gmon_start__(); FUN_000045e0(); iVar1 = FUN_00015030(); again. That library needs feat(ghidra): admit plain MIPS32 PIC shared images #2362 to open; without it, MIPS shared objects are refused before this code runs. The x86-64 fixture above is the evidence on main alone.
  • Remaining proof gaps:

For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.

The changed boundary is the bridge's database mutation before decompiling; the probe covers the protected and the preserved sides. No lifecycle changes.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

On this branch (base main d09590dcd), Linux x64, Node 24.22.1, Ghidra 12.1.4, JDK 21:

  • npm run check:fast, npx oxfmt --check ., npm run docs:check: passed.
  • npx vitest run src/ghidra tests/boundary/providers/ghidra: 1529 passed, 5 skipped.
  • npm run verify:ghidra:loader-relocation: passed; with main's bridge the updated probe fails at applied_got_relocations_not_volatile.
  • npm run verify:ghidra: fails, and unmodified main d09590dcd fails the same way on this host. Ghidra's LaunchSupport -envvars fails for the lane's non-ASCII runtime path, and the native-value verifier retains its workspace. This change does not touch launching.
  • Together with feat(ghidra): admit plain MIPS32 PIC shared images #2362 (merged locally): verify:ghidra:mips32-shared passed for LE, BE and soft-float LE; with main's bridge it fails at "Calls to the import through the GOT and through its REL32 pointer", because the GOT entries decompile as pointer calls. The firmware calls above decompile by name.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Ghidra snapshots from earlier builds are already refused through producer.
  • Real Hopper/Ghidra, browser, or OS coverage: real Ghidra 12.1.4 on Linux x64; macOS and Windows not run.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: changes only the ephemeral analysis database; no target execution.

Author readiness

Human owner: @AurelioB

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

…r whole block

Since morluto#10483, an unapplied loader relocation in a non-writable block made
that whole block volatile. TLS slots are such relocations and sit in .got
beside the entries Ghidra did apply, so in any shared object or PIE with
initial-exec or dynamic TLS every GOT-indirect call decompiled as pointer
arithmetic instead of a named call.

Mark each unapplied destination volatile through its data item's Mutability
setting, creating an undefined item of the relocation's length where nothing
is defined. Fall back to the whole block only when an instruction or a data
item starting before the destination occupies it. Eligibility, limitations,
the read-only path, permissions and source FileBytes are unchanged.

The loader-relocation fixture now reads an initial-exec TLS variable whose
R_X86_64_TPOFF64 slot shares .got with the applied entries. The probe
requires that block and its applied entries to stay non-volatile and both
unapplied destinations to have volatile data items; on the previous bridge
it fails at applied_got_relocations_not_volatile.

Rename loader_relocation_semantics to
volatile-unapplied-relocation-destinations to state the new behavior.
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge based on the reviewed code.

Summary

The PR narrows Ghidra’s protection to unapplied relocation destinations, so nearby applied GOT entries can still resolve to named calls.

  • Ghidra keeps applied GOT entries foldable while protecting unapplied relocation destinations.

No new actionable issues or security defects were established. Real Ghidra tests were not rerun during this review.

Reviews (3) · Last reviewed commit: "fix(ghidra): preserve decoded instructio..." · Reviewed by Greptile

Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
@morluto
morluto marked this pull request as ready for review November 19, 2026 01:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T01:26:08.955376Z 0ece810 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@morluto
morluto merged commit 9b1ffa1 into morluto:main Nov 19, 2026
50 checks passed
@morluto morluto added bug Something isn't working provider: ghidra Analysis provider / engine: ghidra labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants