Skip to content

feat(ghidra): admit RISC-V position-independent executables (#4487) - #4811

Merged
morluto merged 7 commits into
morluto:mainfrom
abhay-2108:feat/ghidra-riscv-pie-4487
Nov 19, 2026
Merged

morluto merged 7 commits into
morluto:mainfrom
abhay-2108:feat/ghidra-riscv-pie-4487

Conversation

@abhay-2108

@abhay-2108 abhay-2108 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #4487

Admits little-endian RISC-V ELF32 and ELF64 position-independent executables (ET_DYN with PT_INTERP) into the pinned generic Ghidra lane (RISCV:LE:{32,64}:default + gcc). Most Linux distribution userlands (such as Debian trixie riscv64) build almost all executables as PIE and were previously refused by the lane's ET_EXEC-only check.

Shared libraries (ET_DYN without PT_INTERP) remain refused with a dedicated reason noting that shared libraries require separate load verification.

Key Changes

  • Target Resolution: Detects PT_INTERP in ELF program headers and flags hasInterpreter: true in ElfFamilyMetadata (src/domain/binaryTarget.ts, src/application/BinaryTargetResolver.ts).
  • Ghidra RISC-V Profile: Admits little-endian ET_DYN images having hasInterpreter: true under lane identities elf32-pie-le-double-float-generic-v1 and elf64-pie-le-double-float-generic-v1 (src/ghidra/GhidraRiscvProfile.ts).
  • Profile Parameters: Emits has_interpreter: true, load_model: "pie", and the load base Ghidra applied ("0x10000" for RV32, "0x100000" for RV64) in riscv_elf.
  • Refusal Preservation: Explicitly refuses ET_DYN targets lacking PT_INTERP with a distinct refusal reason.
  • Documentation: Updated docs/ghidra-riscv.md with PIE admission boundary, refusal table, and Evidence semantics.

Validation Performed

  • vitest run src/domain/binaryTarget.riscv.test.ts src/ghidra/GhidraRiscvProfile.test.ts (31 tests passed)
  • vitest run src/domain/binaryTarget.test.ts (48 tests passed)
  • tsc --noEmit (0 errors)
  • node scripts/ci/static-check-report.mjs lint (0 errors)
  • node scripts/verify-module-boundaries.mjs (2054 files passed)
  • oxfmt --check (All matched files pass)

Author readiness

Human owner: @abhay-2108

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-17T14:18:51.244309Z 8ed241e PR opened
ℹ️ 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The latest changes appear safe to merge and fix the numbered soft-float PIE finding.

Summary

Adds RISC-V double-float PIE admission at both widths while keeping shared libraries and soft-float PIE refused.

  • Ghidra now opens double-float RISC-V PIEs with an interpreter.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read ELF declarations] --> B[Retain PT_INTERP presence]
  B --> C{Load model and float ABI}
  C -->|ET_EXEC with admitted ABI| D[Pinned generic RISC-V language]
  C -->|ET_DYN with PT_INTERP and double-float| D
  C -->|ET_DYN without PT_INTERP| E[Refuse shared library]
  C -->|Soft-float PIE| F[Refuse unverified combination]
  D --> G[Commit lane and analysis profile]
Loading

Reviews (12) · Last reviewed commit: "fix(ghidra): restrict PIE admission to v..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraRiscvProfile.ts Resolved
@greptile-apps

greptile-apps Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@abhay-2108
abhay-2108 force-pushed the feat/ghidra-riscv-pie-4487 branch from 3942474 to 1239195 Compare October 19, 2026 12:36
Comment thread src/application/BinaryTargetResolver.ts Resolved
@abhay-2108

Copy link
Copy Markdown
Contributor Author

The review feedback has been addressed and verified with unit tests in 9bdbfa3. The PR is ready for review.

Note on CI: The failures in Test shard (3/5) (hermesClientSetup and jadxConfiguration) are unrelated to this PR. They stem from the recent upstream change in main (49e67aa1d), where Linux process cleanup fails closed with process identity was unavailable during token validation. All PR-scoped checks, static tests, and RISC-V unit tests are passing cleanly.

@Rinkia

Rinkia commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

TL;DR: It admits a real Debian riscv64 PIE and the load looks right. Shared libraries are still refused, as the PR says. Thanks, abhay-2108. Note that GitHub currently shows the branch as conflicting with main.

Build: this PR's head 9bdbfa3bd (base 3ea0d9489), npm ci --ignore-scripts && npm run compile on Linux, Node 24.22.1, Ghidra 12.1.4.

Target: /usr/bin/b2sum from Debian trixie coreutils_9.7-3_riscv64.deb (the package from #4487); readelf: DYN (Position-Independent Executable file), entry 0x32e4.

6.8.0 This PR
rea inspect b2sum --provider ghidra capability_unavailable: "supports fixed-address ET_EXEC only" opens: image_base: 0x100000, 311 procedures, 229 strings
.text / .rodata — 0x102040 / 0x108f70 = readelf -S 0x2040 / 0x8f70 + image base
first LOAD segment — sections run from 0x100000 to 0x10c070 = readelf -l first LOAD (vaddr 0x0, memsz 0xc070) + image base
rea instructions b2sum 0x1032e4 — function entry, 34 bytes, starting jal ra, … (entry 0x32e4 + base)
/usr/libexec/coreutils/libstdbuf.so (shared library, no PT_INTERP) refused still refused: "shared libraries without PT_INTERP need separate load verification"

Not checked: other coreutils binaries, decompilation quality, and relocation application beyond the section placement above.

@abhay-2108
abhay-2108 force-pushed the feat/ghidra-riscv-pie-4487 branch from 9bdbfa3 to df1a47b Compare October 26, 2026 17:13
Comment thread src/application/BinaryTargetResolver.ts Resolved
@Rinkia

Rinkia commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TL;DR: Retested the new head 382abe239: same results as my earlier test of 9bdbfa3bd, plus three more coreutils binaries. GitHub still shows the branch as conflicting with main.

Build: this PR's head 382abe239 (parent 60b55be7e), npm ci --ignore-scripts && npm run compile on Linux, Node 24.22.1, Ghidra 12.1.4. GhidraRiscvProfile.test.ts and elfDeclaredRanges.test.ts: 37/37 pass.

Targets: Debian trixie coreutils_9.7-3_riscv64.deb, all DYN (Position-Independent Executable file) per readelf -h.

Binary rea inspect --provider ghidra .text (REA) readelf -S .text + 0x100000
b2sum opens, image_base: 0x100000, 311 procedures, 229 strings 0x102040 0x2040
ls opens, 668 procedures, 535 strings 0x1042c0 0x42c0
cat opens, 293 procedures, 194 strings 0x101f10 0x1f10
sort opens, 617 procedures, 402 strings 0x103770 0x3770
  • b2sum .rodata at 0x108f70 (= 0x8f70 + base); sections start at 0x100000, the first LOAD segment.
  • rea instructions b2sum 0x1032e4: function entry, 34 bytes, starting jal ra, 0x00103306 (entry 0x32e4 + base).
  • /usr/libexec/coreutils/libstdbuf.so is still refused: "shared libraries without PT_INTERP need separate load verification", as the PR intends.

Not checked: decompilation quality and relocation application beyond section and entry placement.

…4487)

Admit little-endian RISC-V ELF32 and ELF64 position-independent executables
(ET_DYN with PT_INTERP) into the pinned generic Ghidra lane.

- Collect `PT_INTERP` during the existing validated ELF table walk in
  `validateElfDeclaredRanges` and record `hasInterpreter` in target metadata,
  supporting arbitrary table offsets and extended program counts without duplicate scanning.
- Admit ET_DYN images when `hasInterpreter` is present under lane identities
  `elf32-pie-le-double-float-generic-v1` and `elf64-pie-le-double-float-generic-v1`.
- Preserve refusal for non-PIE ET_DYN targets (shared libraries without PT_INTERP)
  explaining that shared libraries require separate load verification.
- Record load model facts (`load_model: "pie"`, `expected_default_image_base: "0x10000"`
  or `"0x100000"`, `has_interpreter: true`) in `riscv_elf` analysis profile parameters.
- Record default image base analysis coordinates limitation for PIE targets.
- Update `docs/ghidra-riscv.md` with PIE admission boundary and evidence semantics.
- Add unit tests for PT_INTERP collection, high-offset program headers, and PIE profile resolution.
- Add PIE fixture generation capability to `tests/conformance/ghidra/riscv-fixture.mjs` and
  pass `-Wl,-pie` to ensure bare-metal drivers generate ET_DYN.
- Extend `scripts/verify-real-ghidra-riscv.mjs` to test both ET_EXEC and ET_DYN.

Fixes morluto#4487
@abhay-2108
abhay-2108 force-pushed the feat/ghidra-riscv-pie-4487 branch from 382abe2 to a948219 Compare October 28, 2026 14:18
@abhay-2108

Copy link
Copy Markdown
Contributor Author

TL;DR: Retested the new head 382abe239: same results as my earlier test of 9bdbfa3bd, plus three more coreutils binaries. GitHub still shows the branch as conflicting with main.

Build: this PR's head 382abe239 (parent 60b55be7e), npm ci --ignore-scripts && npm run compile on Linux, Node 24.22.1, Ghidra 12.1.4. GhidraRiscvProfile.test.ts and elfDeclaredRanges.test.ts: 37/37 pass.

Targets: Debian trixie coreutils_9.7-3_riscv64.deb, all DYN (Position-Independent Executable file) per readelf -h.

Binary rea inspect --provider ghidra .text (REA) readelf -S .text + 0x100000
b2sum opens, image_base: 0x100000, 311 procedures, 229 strings 0x102040 0x2040
ls opens, 668 procedures, 535 strings 0x1042c0 0x42c0
cat opens, 293 procedures, 194 strings 0x101f10 0x1f10
sort opens, 617 procedures, 402 strings 0x103770 0x3770

  • b2sum .rodata at 0x108f70 (= 0x8f70 + base); sections start at 0x100000, the first LOAD segment.
  • rea instructions b2sum 0x1032e4: function entry, 34 bytes, starting jal ra, 0x00103306 (entry 0x32e4 + base).
  • /usr/libexec/coreutils/libstdbuf.so is still refused: "shared libraries without PT_INTERP need separate load verification", as the PR intends.

Not checked: decompilation quality and relocation application beyond section and entry placement.

Thanks for testing across the Debian coreutils binaries (b2sum, ls, cat, sort) and confirming the section offsets, procedure counts, and shared library refusal behavior!

I've rebased the branch onto latest main (b9a8f8e9f), resolving the conflicts with upstream's verifier harness refactor. All type checks, lints, format checks, and test suites (GhidraRiscvProfile.test.ts, binaryTarget.riscv.test.ts, and elfDeclaredRanges.test.ts) are passing cleanly.

@morluto

morluto commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Hey @abhay-2108, thanks for putting this together, the addition looks useful. What's left: it has merge conflicts with main in docs/ghidra-riscv.md, scripts/verify-real-ghidra-riscv.mjs, src/application/BinaryTargetResolver.ts and 3 other files (merging main into the branch is fine). Happy to merge once that's sorted.

…-4487

# Conflicts:
#	docs/ghidra-riscv.md
#	scripts/verify-real-ghidra-riscv.mjs
#	src/application/BinaryTargetResolver.ts
#	src/ghidra/GhidraRiscvProfile.test.ts
#	src/ghidra/GhidraRiscvProfile.ts
#	tests/conformance/ghidra/riscv-fixture.mjs
Comment thread src/ghidra/GhidraRiscvProfile.test.ts Resolved
@abhay-2108

Copy link
Copy Markdown
Contributor Author

Hi @morluto , main has been merged into the branch, all conflicts are resolved, and review feedback on test assertions/errors has been addressed. All CI checks are green-ready for your final review and merge!

Comment thread src/ghidra/GhidraRiscvProfile.ts Resolved
@morluto
morluto merged commit 8d22625 into morluto:main Nov 19, 2026
49 checks passed
@morluto morluto added enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Ghidra RISC-V lane: admit position-independent executables (ET_DYN); distro riscv64 binaries are almost all PIE

3 participants