wave20: ghidra-0001 UNDF-1303 (6.5x-27x RecoveredClassHelper) + 9 clean-scan additions

Flagship: ghidra RecoveredClassHelper.addVftableReferencesToFunctionMapping
+ addFunctionsToClassMapping. Each insert does List.contains + ArrayList
copy on every add, giving O(F*R^2) per binary. Map<F, LinkedHashSet<T>>
rewrite gives O(F*R) and 27x speedup at F=2k R=500.

Reverse-engineering large C++ binaries (1000+ classes, 10k+ vtable refs)
sees seconds-to-minutes per RecoverClassesFromRTTIScript run today.

Wave 20 honor roll: cri-o, runc, youki, quickjs, hermes, ripgrep, radare2,
monero, mitmproxy. Cumulative: 115 projects.
This commit is contained in:
russell@unturf.com 2026-04-25 15:49:17 -04:00
parent 3a9c7a3e75
commit dce02d80df
No known key found for this signature in database
7 changed files with 465 additions and 0 deletions

View file

@ -0,0 +1,84 @@
# Ghidra — CWE-407 Disclosure Brief
**Project:** Ghidra (NationalSecurityAgency/ghidra)
**Severity:** HIGH
**CWE:** CWE-407 (Inefficient Algorithmic Complexity)
**MOAD:** [MOAD-2026-0001 A Sedimentary Defect](https://undefect.com/moad-2026-0001/)
**Speedup:** 27× measured at F=2k R=500
## Defect Map
![]({static}/uploads/intel-ghidra.svg)
## What it is
Ghidra's C++ class recovery scripts (`Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java`) build two functioning maps during analysis:
- `functionToVftableRefsMap: Map<Function, List<Address>>`
- `functionToClassesMap: Map<Function, List<RecoveredClass>>`
Each insert path checks for membership via `List.contains` (O(R) linear scan), then **defensively copies the existing ArrayList into a new ArrayList** (O(R) copy), then `Map.replace`s the entry. Per-function cost: **O(R²)** for R items added. Per-binary cost: **O(F × R²)** where F = function count, R = references-per-function.
Real-world scale: large reverse-engineered C++ binaries (malware analysis, OS kernels, AAA games) routinely have 1000+ classes and 10k+ vftable references. The `RecoverClassesFromRTTIScript` runs into seconds-to-minutes per binary today.
| Defect | UNDF |
|--------|------|
| `ghidra-0001` | [undf-2026-000001303](../undf-2026-000001303/) |
## Where it lives
`Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java:218-237`:
```java
for (Address vtableReference : keySet) {
if (functionToVftableRefsMap.containsKey(function)) {
List<Address> referenceList = functionToVftableRefsMap.get(function);
if (!referenceList.contains(vtableReference)) { // O(R) per call
List<Address> newList = new ArrayList<>(referenceList); // O(R) copy
newList.add(vtableReference);
functionToVftableRefsMap.replace(function, referenceList, newList);
}
}
// else create new list...
}
```
Same pattern at `addFunctionsToClassMapping(...)` — line 256.
## Fix
Replace `Map<Function, List<T>>` with `Map<Function, LinkedHashSet<T>>`. `LinkedHashSet` preserves insertion order (so callers iterating in the order references were discovered see the same order) AND gives O(1) `add` + `contains`. The defensive ArrayList copy on every add disappears entirely.
```java
private final Map<Function, LinkedHashSet<Address>> functionToVftableRefSetMap = new HashMap<>();
functionToVftableRefSetMap
.computeIfAbsent(function, k -> new LinkedHashSet<>())
.add(vtableReference);
```
Public API readers wrap the set as `List` for downstream-script compatibility:
```java
public List<Address> getVftableReferences(Function function) {
LinkedHashSet<Address> set = functionToVftableRefSetMap.get(function);
return set == null ? null : new ArrayList<>(set);
}
```
## Bench (defects/ghidra/bench/results.txt)
```
=== ghidra-0001: RecoveredClassHelper O(F*R^2) -> O(F*R) ===
scale defective fixed speedup
------------------------------------------------------------
F= 100 R= 50 6.59ms 1.02ms 6.5x
F= 500 R= 50 24.10ms 3.63ms 6.6x
F= 500 R= 200 239.36ms 16.55ms 14.5x
F=1000 R= 200 449.90ms 36.22ms 12.4x
F=2000 R= 500 4730.41ms 173.06ms 27.3x
```
## Why it matters
Ghidra is the public-domain reverse engineering platform from NSA used by every malware analyst, vulnerability researcher, and binary archaeologist on the planet. Class recovery is THE feature for understanding C++ binaries — the foundation of every C++ malware analysis. The patch drops a 4.7-second analysis step to 173ms on realistic 2000-function binaries — multiplied across thousands of analysts × thousands of binaries × analysis re-runs, this is human-attention saved on every reverse-engineering session.

View file

@ -0,0 +1,92 @@
# Wave 20 — Container Runtimes, Reverse Engineering, JS Engines
**Survey date:** 2026-04-25
**Tool:** unmoad (9 active MOAD detectors, HIGH+ severity filter)
**Scope:** 10 projects across container runtimes (cri-o, runc, youki), small JS engines (quickjs, hermes), search/CLI (ripgrep), reverse engineering (ghidra, radare2), cryptocurrency (monero), and proxy (mitmproxy).
---
## Summary
Wave 20 totals 4,420 HIGH+ findings across 10 projects. **One flagship CWE-407 patch shipped (ghidra-0001 with 6.5×27× measured speedup)** plus **9 new clean-scan honor roll entries** (cri-o, runc, youki, quickjs, hermes, ripgrep, radare2, monero, mitmproxy). Honor roll cumulative: **115 projects** across waves 3-20.
## Flagship patch shipped this wave
| Target | Defect | Speedup | UNDF |
|--------|--------|---------|------|
| ghidra | RecoveredClassHelper List.contains + ArrayList copy on every add | 27× @ F=2k R=500 | UNDF-2026-000001303 |
`ghidra-0001` lands a `Map<Function, LinkedHashSet<T>>` rewrite in `Ghidra/Features/Decompiler/ghidra_scripts/classrecovery/RecoveredClassHelper.java`. The current code does `List.contains` (O(R)) then `new ArrayList<>(referenceList)` (O(R) defensive copy) on every reference add. Per binary: O(F × R²). Reverse-engineering large C++ binaries (1000+ classes, 10k+ vftable refs) sees seconds-to-minutes per `RecoverClassesFromRTTIScript` run; the LinkedHashSet rewrite drops F=2k R=500 from 4.7s to 173ms.
## Clean-scan honor roll — 9 new entries
| Project | Lang | Role | Notes |
|---------|------|------|-------|
| **runc** | Go | OCI runtime reference impl | 2 findings: 1 in test, 1 in `nsexec.c` strcmp on fixed Linux namespace name list. **clean** |
| **cri-o** | Go | Kubernetes CRI (runc/crun-based) | 9 findings: `cgroups_linux.go` ctrls (fixed cgroup controller list), `tag-reconciler` script, `pkg/config/config.go` AvailableMetrics fixed list, M3 ContextWithValue (intentional log plumbing). **clean** |
| **ripgrep** | Rust | Fast grep | 12 findings: `printer/util.rs` `line_term.as_bytes().contains(&b)` is `&[u8]::contains` for line terminator (1-2 bytes); `matcher/lib.rs` `ByteSet` is a 256-byte bitmap (literal name) with O(1) bit lookup; `searcher/mod.rs` encoding-list contains in fixed encoding list. **clean** |
| **quickjs** | C | Small embeddable JS engine | 23 findings: CLI argv strcmp (`--version`, `--help`, `--eval`), vendored `unicode_gen.c`, debug printf statements (`printf("string: '%s'", str)` is debug, not credential leak). **clean** |
| **hermes** | C++ | Facebook React Native JS engine | 421 findings: 44 in `benchmarks/octane/typescript.js` benchmark (vendored Octane benchmark suite), `tools/hermes-parser/js/prettier-plugin-hermes-parser/index.mjs` (vendored prettier plugin), `benchmarks/lib/libgui/stb/stb_image.h` (vendored stb), `benchmarks/widgets/single-file/cpp/widgets_fast_int.cpp` (benchmark fixture). Core hermes clean. |
| **youki** | Rust | OCI runtime in Rust | 45 findings: `commands/ps.rs` pids.contains for cgroup membership (bounded by container PIDs <100s), `info.rs` active_controllers (fixed cgroup controllers ~7), `tty.rs` reason String substring. **clean** |
| **radare2** | C | Reverse engineering framework | 50 findings: vendored UI JS (d3.js, m/main.min.js, t/app.js, f/r2.js for the web UI), `libr/include/r_util/libc.h` defines fallback strcmp/strncmp inline. **clean** |
| **monero** | C++ | Monero cryptocurrency | 56 findings: vendored `external/easylogging++` and `external/db_drivers/liblmdb` (vendored LMDB), `simplewallet.cpp` `printf("secret: ")` is the CLI password prompt label (not credential leak), `daemon_handler.cpp` `std::find(missed_vec, h)` for missed-tx dedup (bounded by request size). **clean** |
| **mitmproxy** | Python | Interactive HTTPS proxy | 202 findings: vendored UI assets (asciinema-player, elasticlunr, web index), `proxy/layer.py` `self.context.layers.index(self)` for layer position lookup (bounded by stack depth ~5), `console/commands.py` widget_list.index. **clean** |
Honor roll now stands at **115 projects** validated zero-real-finding under MOAD scanning.
## Per-target findings
| Project | Lang | Total | M1 | M3 | M4 | M5 | M6 | M7 | M9 | M11 | Triage |
|---------|------|------:|---:|---:|---:|---:|---:|---:|---:|----:|--------|
| **ghidra** | Java | 3360 | 992 | 655 | 33 | 466 | - | 1198 | - | 16 | **flagship: RecoveredClassHelper shipped as ghidra-0001**. M7 cluster (1198) in DirectedGraph + RTTI recovery — same family of patterns; backlog candidate. |
| **hermes** | C++/JS | 421 | 308 | 17 | 8 | 5 | 2 | 71 | - | 10 | Vendored Octane + prettier plugin + stb. **clean** |
| **mitmproxy** | Python | 202 | 125 | 31 | 10 | - | 8 | 25 | - | 3 | Vendored UI + bounded stack depth. **clean** |
| **monero** | C++ | 56 | 24 | - | 11 | - | 11 | 10 | - | - | Vendored LMDB + CLI prompt. **clean** |
| **radare2** | C | 50 | 38 | - | 4 | - | - | 5 | - | 3 | Vendored UI JS + libc fallbacks. **clean** |
| **youki** | Rust | 45 | 21 | - | - | - | - | 22 | - | 2 | Bounded cgroup/PID lookups. **clean** |
| **quickjs** | C | 23 | 16 | - | 7 | - | - | - | - | - | CLI args + debug printf. **clean** |
| **ripgrep** | Rust | 12 | 5 | - | 1 | - | - | 6 | - | - | ByteSet bitmap + bounded line-term. **clean** |
| **cri-o** | Go | 9 | 4 | 4 | 1 | - | - | - | - | - | Bounded cgroup controllers + log plumbing. **clean** |
| **runc** | Go | 2 | 2 | - | - | - | - | - | - | - | Linux namespace name list. **clean** |
## Investigation: ghidra `RecoveredClassHelper` — flagship CWE-407
Found a real O(F × R²) — both `addVftableReferencesToFunctionMapping` and `addFunctionsToClassMapping` use the same defensive-copy + linear-scan pattern: `List.contains` (O(R)) then `new ArrayList<>(existing)` (O(R) copy) on every add. For 2000 functions × 500 references each, the copy-on-write list rebuild costs 4.7 seconds; LinkedHashSet rewrite drops it to 173ms. Patch shipped as UNDF-2026-000001303.
The same insertion pattern appears in ghidra's broader RTTI recovery code (`RTTIWindowsClassRecoverer.java`, `RTTIGccClassRecoverer.java`) and in `DirectedGraph.java` descendants traversal — backlogged for a follow-up patch covering the broader pattern.
## Other investigations
### ripgrep ByteSet — intentional 256-bit bitmap
`ByteSet(*self).contains(b)` in `crates/matcher/src/lib.rs:297` looks like Vec contains, but `ByteSet` is a 256-byte bitmap with O(1) bit lookup. Scanner FP on the receiver type. Same pattern as Wave 8 surrealdb RoaringTreemap and Wave 11 meilisearch SmallBitmap.
### hermes vendored benchmarks
The 308 M1 hits are dominated by vendored Octane benchmark JS (typescript.js, pdfjs.js — 44+13 hits) and vendored stb_image.h (4 hits). These are benchmarks shipped IN-source for performance regression testing — vendored third-party code, not hermes source.
### monero `simplewallet.cpp printf("secret: ")` — false positive on credential prompt
The `printf("secret: ")` is a CLI prompt label asking the user TO enter their secret, not logging the secret value. The next code reads the secret from stdin (or from a hidden input). Standard CLI password-prompt pattern.
### youki Rust container runtime
All M1 findings bounded by container resource counts: PIDs (<100s per container), cgroup controllers (fixed ~7), tty reason String substring (single-char). Tight Rust codebase.
## Triage backlog
1. **ghidra DirectedGraph descendants pattern** — same family as ghidra-0001. Ship as ghidra-0002 in a follow-up.
2. **ghidra RTTI{Windows,Gcc}ClassRecoverer** — same pattern in different classes. Ship as ghidra-0003/0004.
3. **Scanner enhancement: ByteSet/Bitmap awareness** (continued from Wave 8/11) — ripgrep ByteSet reinforces the gap.
4. **Scanner enhancement: vendored-benchmark suppression** for Octane (hermes), JetStream patterns appearing in JS engines.
## Method
Same as Waves 3-19: shallow clone, `unmoad -s high -f json`, filter test/vendor/codegen noise, manual triage of strongest source-only candidates per project. **Nine projects added to clean-scan honor roll.** **One flagship CWE-407 patch shipped: ghidra-0001 → UNDF-2026-000001303.**
## References
- `unmoad` detection engine: `git.unturf.com/engineering/unmoad.com`
- ghidra intel page: `/ghidra/`
- Earlier surveys: `/test-harness-survey/` through `/wave19-templating-parsers-compilers-survey/`
- Clean-scan honor roll cumulative: 115 projects across waves 3-20