Repository navigation
fix(ghidra): protect only unapplied relocation destinations, not their whole block - #11996
Merged
morluto merged 2 commits intoNov 19, 2026
Merged
Conversation
…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.
16 of 22 tasks
Contributor
[Medium impact] The PR appears safe to merge based on the reviewed code. SummaryThe PR narrows Ghidra’s protection to unapplied relocation destinations, so nearby applied GOT entries can still resolve to named calls.
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 |
morluto
marked this pull request as ready for review
November 19, 2026 01:19
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
11 of 18 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.gotbeside the GOT entries Ghidra did apply. In any shared object or PIE with an initial-exec or dynamic TLS slot, the whole.gotbecomes 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
.gotholds 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 asUNSUPPORTED.docs/providers/ghidra-provider.md): "Applied relocations such as GOT entries stay foldable, so external calls keep their names."main336054918, real Ghidra 12.1.4, a MIPS32 firmware library (libdsd2pcm.so, oneR_MIPS_TLS_TPREL32slot in.got).rea function … _initgives(*(code *)(puVar1 + 0x45e0))(); (*(code *)(puVar1 + 0x5030))();where it gaveFUN_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 hostlibstdc++.so.6has 5 unapplied TLS slots in its read-only.got.Change and scope
ReaGhidraBridge.protectLoaderInitializedRelocationsmarks 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.FileBytes.loader_relocation_semanticsis renamed fromvolatile-unapplied-relocation-blockstovolatile-unapplied-relocation-destinationsso the profile states the new behavior. The committedproduceralready changes with the bridge digest, so snapshot invalidation does not depend on this rename.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
loader_relocation_semantics.loader_relocation_semanticsvalue renamed; Ghidra profile digests and Evidence IDs change, as they do with any bridge change throughproducer.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
The launched process is the existing headless Ghidra import; target code is never run.
Evidence and regression coverage
verify:ghidra:loader-relocation: the fixture's provider library now defines an initial-exec TLS variable, and the PIE reads it. The probe requires itsR_X86_64_TPOFF64slot 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.main's bridge the updated probe fails atapplied_got_relocations_not_volatile; with this change it passes.GhidraProvider.behavior.test.ts: the renamed semantics value.main336054918and with this change.rea function libdsd2pcm.so _init --provider ghidra --jsonreturns__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 onmainalone.baseline_folds_file_constant: false), so this lane does not reproduce [Bug] Ghidra pseudocode shows musl stdio streams as NULL: copy-relocatedstderrin RELRO is folded to its on-file zero #4177's folding itself; it checks that the destination is protected and that applied GOT entries are not.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:
Validation performed
On this branch (base
maind09590dcd), 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; withmain's bridge the updated probe fails atapplied_got_relocations_not_volatile.npm run verify:ghidra: fails, and unmodifiedmaind09590dcdfails the same way on this host. Ghidra'sLaunchSupport -envvarsfails for the lane's non-ASCII runtime path, and the native-value verifier retains its workspace. This change does not touch launching.verify:ghidra:mips32-sharedpassed for LE, BE and soft-float LE; withmain'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
producer.Author readiness
Human owner: @AurelioB
Before merge
type(scope): outcome.