Repository navigation
feat(ghidra): admit plain MIPS32 PIC shared images - #2362
Conversation
Add an elf32-dyn-o32-arch32r2-standard-v1 lane for ET_DYN images without an ASE flag (shared libraries and ET_DYN executables), beside the MIPS16 lane. It reuses the complete dynamic-relocation inspection and admits R_MIPS_NONE, symbol-bearing R_MIPS_REL32 and the TLS loader slots DTPMOD32/DTPREL32/TPREL32, which stay unapplied with a limitation. Ghidra's default moves an image linked at 0 to 0x10000 and then shifts only nonzero local GOT entries, so page-zero GOT entries (how GNU-ld libraries call static functions) keep unshifted values and calls through them decompile to wrong addresses. The lane imports at the image's own ELF image base instead (lowest PT_LOAD in the first 20 headers, as Ghidra computes it), commits it in the analysis profile and requires the bridge handshake to report it. Images with a prelink trailer are refused. verify:ghidra:mips32-shared checks LE, BE and soft-float LLD fixtures laid out like GNU ld output against an independent readelf oracle: every REL32, local GOT entry (including a zero page entry), global GOT entry (EXTERNAL or lazy-binding stub) and unapplied TLS slot, plus named calls in the decompilation, snapshot round trip and CLI evidence. Refs morluto#2338
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@greptileai review |
|
This PR is set for a Plus review. TREX isn't supported with Plus or Apex reviews yet, so Greptile reviews this PR at Base while TREX is on. |
[Medium impact] The changes look safe to merge once the documented #11996 dependency lands. SummaryAdds a bounded Ghidra path for plain MIPS32 shared libraries, keeping analysis addresses at the ELF link addresses.
AurelioB explicitly records the known GOT-call limitation: this head needs #11996 because unapplied TLS slots make the GOT volatile. The reported real-Ghidra passes cover the combined tree. No new actionable issues found. This was a source review; tests were not run. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[ELF load and relocation facts] --> B[MIPS admission and link base]
B --> C[Committed analysis profile]
C --> D[Client checks target and profile]
D --> E[ElfLoader imports at chosen base]
E --> F[Bridge reports image base]
F --> G{Matches commitment?}
G -->|Yes| H[Analysis results]
G -->|No| I[Reject session]
Reviews (20) · Last reviewed commit: "Merge landed Ghidra relocation protectio..." · Reviewed by Greptile |
|
Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open. Handled in 37cf638. Added file-level ELF32 fixtures with multiple nonzero PT_LOAD addresses, plus a lower PT_LOAD at header index 20. They exercise readMipsElfMetadata through parseBinaryTarget and assert selection of the lowest address among only the first 20 headers, rather than supplying linkBase directly to the profile. Source inspection and git diff --check completed. Tests, builds, typechecking, lint, and real-provider verification were skipped at the user's explicit request. Handled in 37cf638. The independent assertMipsSharedLoad oracle now counts original zero-valued non-reserved local GOT entries as got_local_zero. The real-provider lane requires at least one, alongside the existing local-entry count and named-call checks, so fixture drift cannot silently remove page-zero coverage. Source inspection and git diff --check completed. Tests, builds, typechecking, lint, and real-provider verification were skipped at the user's explicit request. |
…ssion suites Add an initial-exec TLS variable so the MIPS32 shared fixture declares R_MIPS_TLS_TPREL32 beside DTPMOD32/DTPREL32, and require all three slots to stay UNSUPPORTED with unchanged bytes. Remove the soft-float and mutation handshake suites that the main reconciliation duplicated in GhidraSessionValues.test.ts.
|
Pushed The branch base Verified on
The merged head still fails static checks and tests. Each failure reproduces on
The PR adds no type errors; the merged head has exactly |
|
Merged Verified on
Local CI: 32 pass, 6 fail. None of the failures touch a file this PR changes:
|
|
Merged |
|
Merged latest |
# Conflicts: # tests/conformance/ghidra/mips-checks.mjs
parseMipsReadelf now confirms the fixture's section types from readelf -S (main added -S to the executable, relocatable and PSP oracles). Request it in the shared-library oracle too.
|
Merged current Verified on
|
|
TL;DR: Fixed: the real-Ghidra lane now passes on head 435e5dd. On head 84ab64e it failed on Node 24 and 26 with This follows my first result on head 362c1eb. I also ran head 84ab64e and did not post it. The lane failed there. Head is now 435e5dd. Its merge-base with today's main c7f6b8b (#4179) is 62bf098 (#4169). Thanks, AurelioB, for the fix.
The lane. It built three fixtures. One is little-endian. One is big-endian. One is little-endian with soft float. Each reports status passed. On 84ab64e, the lane stopped on the first fixture, so the other two never ran. The hashes start with 18aabcc5 (little), 4164f2f7 (big) and 3205ff01 (soft float). Why it passes now. One line of the shared-library lane file changed after 84ab64e. The lane now adds The command line, still fine. For each fixture,
Not run
Other test jobs may have shared the box. Timings are not benchmarks. Test setup
Commandsnpm ci && npm run build && npm run test:prepare
node scripts/run-development-tests.mjs focused src/ghidra/GhidraMipsProfile.test.ts src/ghidra/GhidraSessionValues.test.ts tests/boundary/filesystem/mipsSharedLoad.test.ts tests/boundary/providers/ghidra/ghidraLauncher.test.ts tests/conformance/ghidra/mips-shared-checks.test.ts
node scripts/verify-real-ghidra-mips32-shared.mjs
node scripts/rea.mjs function <fixture>.so rea_mips_so_entry --provider ghidra --jsonEach run sat under 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
# Conflicts: # src/ghidra/GhidraProviderClient.ts
|
Merged Verified on
|
# Conflicts: # src/ghidra/GhidraLauncher.ts # src/ghidra/GhidraProviderClient.ts # tests/boundary/filesystem/mipsSharedLoad.test.ts
Main made the Ghidra installation probe asynchronous behind the shared inspectVerifierGhidraInstallation helper, and analyze_function now returns a summary unless detail "complete" is requested. Use both, as the other MIPS lanes do.
…sing The shared MIPS ELF reader computed Ghidra's ElfHeader.getImageBase rule (lowest PT_LOAD address among the first 20 program headers) and the domain type described it as Ghidra's base. Record source facts instead: every PT_LOAD virtual address with its program-header index, plus the Android prelink trailer. ghidraMipsElfImageBase in GhidraMipsProfile now applies Ghidra's rule to those facts. The committed elf_image_base is unchanged.
# Conflicts: # src/ghidra/GhidraLauncher.ts # src/ghidra/GhidraSessionValues.test.ts
|
@morluto @gensokyo-dev, #2362 is current with main (0cd7ef4), MERGEABLE/CLEAN, all required checks green on 6e0414a. Review threads are resolved, readiness is declared, and the real Ghidra verify:ghidra:mips32-shared lane passes on this head. Could one of you merge it, or tell me what's left? If you'd rather land it yourself, say so and I'll close it and hand over the fixtures. |
# Conflicts: # src/ghidra/GhidraLauncher.ts # src/ghidra/GhidraMipsProfile.test.ts # src/ghidra/GhidraProviderClient.ts
# Conflicts: # src/ghidra/GhidraMipsProfile.ts
Summary
Fixes #2338. Now includes #11996 from main. That change restores GOT-call decompilation for libraries with TLS slots.
Ghidra refuses ordinary MIPS32 PIC shared libraries and
ET_DYNexecutables (o32, MIPS32r2, no ASE flag): "This Ghidra MIPS lane supports ET_EXEC and ET_REL only". On one real MIPS32r2 Linux firmware root filesystem, that is 87 of its 225 MIPS ELF files. This PR adds a bounded lane,elf32-dyn-o32-arch32r2-standard, that admits them and loads each image at its own ELF link base, so the GOT is read exactly as stored.Problem and expected behavior
libdsd2pcm.so,libdl-2.22.so) with the same Ghidra provider used for the firmware's executables and kernel modules.0x10000.MIPS_ElfExtension.fixupGotthen shifts local GOT entries only when they are nonzero (adjustTableEntryIfNonZero)._DT_INITshowed(*(code *)0xcf0)()when the target was at0x10cf0.Change and scope
GhidraMipsProfile.ts):R_MIPS_NONE,R_MIPS_REL32(symbol-bearing included; plain MIPS32 has no MIPS16 mode-tag hazard), and the TLS loader slotsDTPMOD32/DTPREL32/TPREL32.UNSUPPORTED), and every analysis result carries a limitation saying so.PT_LOAD).MipsElfSharedLoad.ts): records source facts only: everyPT_LOADvirtual address with its program-header index, and any Android prelink trailer. Ghidra's own image-base rule (the lowestPT_LOADamong the first 20 program headers, asElfHeader.getImageBase()computes it, else 0) is applied inGhidraMipsProfile.ts.elf_image_base, and the launcher passes-loader ElfLoader -loader-imagebase <base>.elf_image_base_scopetogether with PSP, DOS, raw-binary, GameCube DOL or RISC-V calling-convention imports and with a checkpoint restore,elf_image_base_formatfor a value that is not a bare 32-bit hex offset, andexisting_project_elf_image_basefor an existing project, like the soft-float and RISC-V options.REA_GHIDRA_CHECKPOINT_DIR) refuses this lane: a restored Program would not re-apply the loader's image base, so it is not a stock import. Existing-project and checkpoint support stay as onmain.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
readMipsElfSharedLoadproduces the new provider-neutralloadAddresses/prelinkBasefacts. Consumers:GhidraMipsProfile(admission, Ghidra's image-base rule and theelf_image_basecommitment),GhidraLauncher(ElfLoader arguments),GhidraProviderClient(commitment check) andGhidraSessionValues(handshake image base). No path is superseded.ET_DYNtargets now open, and their results carry the new lane, profile fields and limitations.ElfLoaderwith-loader-imagebase); no bridge source changes. Other targets get unchanged import arguments.elf_image_base(offset,selection: elf-link-base; unversioned, like the other lane and selection values since the profile commitsproducer), so profile-bound snapshots are invalidated when it changes. Results carry the new lane id and placement, GOT and TLS limitations.docs/public/product-catalog.json), package, or installation impact: adds theverify:ghidra:mips32-sharedscript topackage.json; no generated metadata changes.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
The process launched is the existing headless Ghidra import, now with
-loader ElfLoader -loader-imagebasefor this lane; target code is never run.Evidence and regression coverage
verify:ghidra:mips32-shared:tests/conformance/c/mips-shared.c) laid out like GNU ld output: text in page 0, GOT-indirectjalr $25, and a call through a zero-valued local GOT page entry.mips-shared-checks.mjs) checks every relocated and GOT word throughread_bytes: REL32 (local, defined, external), every local GOT entry including zero, every global GOT entry (defined, EXTERNAL, lazy-binding stub), and TLS slotsUNSUPPORTEDwith unchanged bytes.__tls_get_addr, and contain no(*(code *)0x…)orPTR_calls.PT_LOADwith its header index (including one past header 20), and Ghidra's base rule in the profile (index 19 counted, index 20 ignored, no qualifying load gives 0);main(1173c0a9d), the firmware's 87ET_DYNfiles are refused by the "ET_EXEC and ET_REL only" rule._DT_INITdecompiled to(*(code *)0xcf0)()(target0x10cf0) and libdsd2pcm_initto(*(code *)0x45e0)().rea function <lib> <fn> --provider ghidra --json, this head with fix(ghidra): protect only unapplied relocation destinations, not their whole block #11996 merged locally):libdsd2pcm.so_init:__gmon_start__(); FUN_000045e0(); iVar1 = FUN_00015030();, laneelf32-dyn-o32-arch32r2-standard,elf_image_base{"offset":"0x0","selection":"elf-link-base"}.libdl-2.22.so_DT_INIT(0xad0):__gmon_start__(); FUN_00000cf0(); FUN_00001d50();._initdecompiles to(*(code *)(puVar1 + 0x45e0))(); (*(code *)(puVar1 + 0x5030))();: since fix(ghidra): prevent loader relocations from constant folding #10483, the library's one unapplied TLS slot makes its whole.gotvolatile. fix(ghidra): protect only unapplied relocation destinations, not their whole block #11996 narrows that protection to the slot itself.d175f675b.For boundary fixes, identify the applicable boundary regressions
and lifecycle regressions
covered by the evidence above, and explain relevant gaps.
The changed boundaries are profile commitment, the handshake, launcher arguments and checkpoint eligibility. A mismatched committed profile, a session placed at a different base, an image base combined with another loader, a checkpoint restore or an existing project, and this lane in checkpoint mode are each refused, with tests above. There are no lifecycle changes.
For evidence-bearing changes:
Validation performed
On this head (merge of
main336054918), Linux x64, Node 24.22.1 (.nvmrc), Ghidra 12.1.4, JDK 21, GNU readelf 2.46:npx tsc --noEmit -p .,npx oxfmt --check .,npm run check:fast(including the architecture guards),npm run docs:check: passed.npm run test:fast: 31416 passed, 23 skipped, 1 failed. The failure,DebianPackageFile.test.ts(reads a package dpkg-deb built), fails the same way on unmodifiedmain336054918and is in a file this PR does not touch.vitest --project mcp-boundary): 2294 passed, 11 skipped.npm run verify:ghidra:mips-relocatable: passed.npm run verify:ghidra:mips-shared(MIPS16; GNU binutils 2.45.90 with--hash-style=sysv): 4 admitted controls passed, 4 refused as expected.npm run verify:ghidra:mips32-shared:delta 0x0,got_local 2,got_local_zero 1,tls 3;.gotvolatile through its TLS slots. This PR depends on fix(ghidra): protect only unapplied relocation destinations, not their whole block #11996.npm run verify:ghidra:mips: fails, and so does unmodifiedmain. test(ghidra): expect carved MIPS copies to be refused at target opening #8227'sassertMipsCarvedTargetRefusalcompares the refusal details exactly, and target opening now also reportsselection_at_failure,target_at_open_completionandprovider_id_at_open_completion. This PR doesn't touch that assertion or the lane script.Earlier heads:
d175f675b(merge ofmain1173c0a9d) passedtest:fast(18946 passed) and the three MIPS lanes above; thereverify:ghidra:mipsfailed at the carved fixture's target opening, the failure #8227 later fixed.6e0414a59(merge ofmain0cd7ef456) passedtest:fast(20923 passed) andverify:ghidra:mips32-shared.Maintainer refresh: current main changed DOS COM launcher options from a boolean to a loader selection. The ELF image-base guard now uses the current type. MIPS32 shared-library admission refuses declared PIEs via PT_INTERP or DF_1_PIE, and the verifier relies on its structured placement, relocation, GOT and snapshot checks instead of matching English limitations. The decompiler output assertions remain the direct witness for the GOT-call regression. Focused tests passed 219 with 3 skips. The full MIPS32 shared verifier includes #11996's relocation protection.
The real CLI/MCP MIPS32 shared verifier also passed on an isolated checkout combining
b5660a703awith draft #11996 at0ece810c2f, using Ghidra 12.2, Temurin JDK 25, LLVM 23 and GNU readelf on macOS arm64. All three variants passed (little- and big-endian hard float and little-endian soft float), with zero image-base delta, three TLS slots each, verified GOT-call output and snapshot replay, unchanged target bytes, and complete process cleanup. After #11996 landed, the verifier passed all three variants again on the refreshed PR headf76584d36f.Compatibility, safety, and release
verify:ghidra:mips32-sharedscript.Author readiness
Human owner: @AurelioB
Before merge
type(scope): outcome.