Files
frame/poc/apps/poc_a/plugins/REJECT-MATRIX.md
T
Lainandlain e71842aa8a feat(poc-a): gate-a dynamic elf proof of concept (#13)
## Summary

PoC-A proved that dynamically loaded ELF plugins are workable on
ESP32-S3: plugins ship as signed MPB packages, are parsed by a strict
single-type parser shared between host and target, and execute from
PSRAM+IRAM within a measured admission budget. A 1000-cycle load/unload
soak passed 18/18 trend gates with stable heaps, the capacity ladder
settled at 8 coexisting plugin instances with a 3356B per-instance
budget, and the fail-closed corpus executed zero attacker-controlled
bytes across 14 rejection classes. Scheduler semantics (strand FIFO
ordering, completion-cancel CAS, quiesce-as-noop ABI) were validated on
both host (TSan suite) and target. **Gate-A verdict: PASS** — ADR-0002
moves to **Accepted** with the capacity value 8 and global-sum admission
rule as PoC-derived proposals.

## Changes by area

Grouped from `git log main..HEAD --oneline` (18 commits):

- **Vendored loader + patches**: `4bb53f2` vendor elf_loader 1.3.3 +
harness scaffold; `2f67b4f` plugin_iram loader patch with budget
consistency (p1-p5 patch series in `PATCHES.md`).
- **MPB toolchain**: `4793cc2` deterministic MPB manifest builder with
test signing; `408df44` strict single-type MPB parser shared
host/target; `796f9d2` host MPB corpus + policy CI lane.
- **Plugin pipeline + probes**: `21d2842` plugin pipeline and first
PSRAM execution on target; `cab9664` relocation/import allowlist matrix
with probes; `c5d6c6c` C++ feature rejection matrix.
- **Harness commands**: `e0e7159` generation coexistence with measured
admission budget; `2a37556` thousand-cycle lifecycle soak with heap
trend gate; `093a72b` on-target scheduler semantics validation (+
`eea3876` clang-format-18 sweep); `a302151` capacity ladder with signed
budget; `f34dc72` fail-closed corpus with execution sentinel.
- **Host prototypes**: `6198bca` strand FIFO prototype with TSan suite;
`1c3ad59` completion-cancel CAS and cleanup semantics.
- **Evidence + ADR/docs**: `887d0f7` Gate-A manifest and report;
`1c29e8a` ADR-0002 outcome + frozen PoC values.

## QA evidence

- `poc/evidence/poc-a-20260901/manifest.json` — 67-artifact hash index,
every sha256 recomputed at assembly.
- `poc/evidence/poc-a-20260901/GATE-A-REPORT.md` — full nine-item
development-plan §4 mapping; TEST-003 10/10 clauses.
- 14 verbatim per-task transcripts (`task-1` … `task-15-*.log`) + fresh
build artifacts (`build/frame_poc_a.map`, size components).
- Frozen in-repo references: `ALLOWLIST.md`, `REJECT-MATRIX.md`,
`ADMISSION-BUDGET.md`, `soak_samples_1000.csv`, fc corpus (33 committed
`.mpb` containers).
- F1-F4 final-wave verdicts: **APPROVE**.
- Key numbers: soak **18/18** trend gates over 1000 cycles; capacity
**8/8** instances, **3356B** per-instance; fc corpus **14 rejection
classes, zero attacker bytes executed**; **4 upstream loader defects
found and patched** (p1-p5).

## Requirement IDs (GOV-006)

ADR-0002; TEST-002, TEST-003; PLUG-001, PLUG-004, PLUG-008, PLUG-009;
MEM-001, MEM-003, MEM-007, MEM-008; LIFE-001, LIFE-002, LIFE-005,
LIFE-007; SEC-002, SEC-003, SEC-004, SEC-005; GH-003; GOV-004, GOV-005.

## Risks / known limitations

From `GATE-A-REPORT.md` §(f) plus the trade-off table:

1. **Capacity descent path 7-5 unexercised** — rung 8 passed first
attempt; rungs 7/6/5 and retry-once logic never ran on hardware
(untested against real OOM).
2. **No Wi-Fi in the harness (MEM-001 caveat)** — all PSRAM/IRAM budget
numbers are radio-off harness-class; product admission budgets must be
re-measured with the network stack active.
3. **On-target scheduler vectors are a subset of the host suite**
(256-node pool / 2e4 storm posts vs host 31000 / 1e5); consistency
declaration covers only the vectors actually run.
4. **Quiesce is a no-op by ABI semantics** — plugin ABI 1.2 has no
quiesce slot; NULL entry is defined as trivial success; real quiesce
coordination is later-gate work.
5. **MEMPROT=n trade-off** — `CONFIG_ESP_SYSTEM_MEMPROT=n` is required
for the IDF exec heap (`MALLOC_CAP_EXEC`) that `.plugin_iram` needs;
software-only PMP config, no eFuse burned (documented in `PATCHES.md`
p5); production must re-decide security vs plugin IRAM.
6. **Owner sign-off PENDING** — Gate-A PASS is the PoC team's verdict;
formal acceptance of ADR-0002 awaits the owner.

## Not in scope

- Product components (GOV-004) — this PR is PoC evidence only; no
product code paths change.
- **Merge is the owner's call** — do not merge without owner sign-off on
ADR-0002.

---------

Co-authored-by: ania-lain <[email protected]>
2026-09-07 20:02:18 +08:00

103 lines
8.2 KiB
Markdown

# PoC-A C++ feature rejection matrix (frozen, Gate-A output)
Task T6 of `poc-a-dynamic-elf`. Appendix C 11.2 declares these C++ runtime
features **default-forbidden** for loadable plugins; this matrix proves, per
feature, that the artifact is rejected at every layer that can see it. PoC-A
proves REJECTION only — no row is whitelisted, and no row may ever be.
Layers:
- **L1 pipeline/CI** — `check_plugin_elf.cmake` runs inside every positive
`poca_plugin()` build AND inside the poc_a CI lane. Gate 1 = dynamic
relocation allowlist (T5), gate 4 = forbidden C++ feature sections (T6,
new), gate 2 = closed-world imports (T5), gate 3 = ELF shape (T4). The
probe variants are built by `poca_cxx_probe()`
(plugins/cxx_probes/*.cpp) and each one is run through the REAL gate
script by the expected-failure wrapper `check_probe_rejection.cmake`:
acceptance of any probe fails the build ("NOT REJECTED" is fatal), and
the verbatim gate error text lands in the build log.
- **L2 loader (fail-before-execute)** — vendored elf_loader with registered
patches: p1 (relocation allowlist propagation, `-EINVAL`), p2 (ELF
identity), **p4 (forbidden-section scan, T6, new — see decision below)**.
p4 mirrors the gate 4 section list on target so a hand-crafted signed
container (the T5 `hostile_signed` path) cannot slip a feature section
past the build layers.
| # | Feature | Emitter (this toolchain) | Forbidden artifact(s) | Rejection layer(s) | Evidence (task-6 log) | Whitelisted? |
| - | ------- | ------------------------ | --------------------- | ------------------ | --------------------- | ------------ |
| v1 | static constructor | file-scope object w/ non-trivial ctor (no extra flag) | `.ctors` section (this gcc's `.init_array` spelling) + its `R_XTENSA_RELATIVE` entries | L1 gate 4 (`.ctors`); L2 p4 (section scan, `-EINVAL` before copy) | build: "forbidden C++ feature section(s) [.ctors]"; board: `cxx_ctor` row, `Forbidden C++ feature section '.ctors'`, errno -22, canary unchanged | **NO** |
| v2 | static destructor | object w/ non-trivial dtor + `__attribute__((destructor))`, `-fno-use-cxa-atexit` | `.dtors` section (this gcc's `.fini_array` spelling) | L1 gate 4 (`.dtors`) | build: "forbidden C++ feature section(s) [.dtors]" (verbatim gate output) | **NO** |
| v3 | dynamic TLS | `__thread` vars written+read at runtime (never-written thread-locals are constant-folded away by gcc — the runtime store is load-bearing for the probe) | `.tdata`/`.tbss` sections + `R_XTENSA_TLSDESC_FN`/`R_XTENSA_TLSDESC_ARG` dynamic relocs in `.rela.dyn` | L1 gate 1 (TLS reloc types out of allowlist); L1 gate 4 (sections, latent — gate 1 fires first); L2 p4 (`.tdata` scan, `-EINVAL`); L2 p1 (TLSDESC reloc types, `-EINVAL` — proven independently by the `neg_tls_nosect` row whose sections were renamed away) | build: "relocation allowlist violated (R_XTENSA_TLSDESC_ARG;R_XTENSA_TLSDESC_FN)"; board: `cxx_tls` (p4 log line) + `neg_tls_nosect` ("Failed to relocate type=51"), both errno -22, canary unchanged | **NO** |
| v4 | exceptions | `-fexceptions -funwind-tables` (toolchain needs the unwind-tables flag to emit landing pads at -Os) | `.eh_frame` + `.gcc_except_table` sections; undeclared EH runtime imports (`__cxa_*`, `_Unwind_Resume`, `__gxx_personality_v0`, `_ZTIi`) | L1 gate 4 (`.eh_frame`/`.gcc_except_table`); L2 p4 (same list); (gate 2 / loader `-ENOSYS` would additionally catch the imports) | build: "forbidden C++ feature section(s) [.eh_frame;.gcc_except_table] present" | **NO** |
| v5 | RTTI | `-frtti` (probe baseline keeps `-fno-rtti`), polymorphic `typeid` + `dynamic_cast` | no dedicated section on this toolchain: local typeinfo in `.data.rel.ro` (allowlisted relocs) + undeclared C++ ABI imports `__dynamic_cast`, `_ZTVN10__cxxabiv1...`, `_ZdlPvj` | L1 gate 2 (closed-world imports); L2 loader `-ENOSYS` for unregistered imports (same mechanism proven on board by T5 `import_neg`) | build: "import gate failed, undeclared undefined symbols: __dynamic_cast; _ZdlPvj; _ZTVN10__cxxabiv117__class_type_infoE; _ZTVN10__cxxabiv120__si_class_type_infoE" | **NO** |
| v6 | unwind tables | `-funwind-tables -fasynchronous-unwind-tables`, `noinline` function | `.eh_frame` section (pure emitter: no exception code, no EH imports) | L1 gate 4 (`.eh_frame`); L2 p4 | build: "forbidden C++ feature section(s) [.eh_frame]" | **NO** |
On-board corpus rows (packaged via `cxx_probes/build_cxx_probes.py`, the T5
hostile_signed pattern — structure/signature/hash all PASS on device, so the
rejection necessarily comes from the loader): `cxx_ctor` (v1) and `cxx_tls`
(v3) must fail `esp_elf_relocate` with `-EINVAL` **before any plugin byte
executes** (entry-query canary unchanged); `neg_tls_nosect` isolates the p1
relocation-layer rejection by renaming `.tdata`/`.tbss` to `.xdata`/`.xbss`
in `.shstrtab` (same-length byte patch).
## p4 decision — ADD (loader-side section rejection): justification
The plan text for T6 mandates the loader half ("loader 侧 fail-before-execute
(若链接器仍产出则解析 ELF section 于执行前拒绝)"), and TEST-003 / §4 item 4
("未知项目 fail before execute") is only satisfiable with it. The empirical
pre-p4 board run (task-6 evidence log, phase 2) settles the policy question:
- A signed `cxx_ctor` container (valid mpb structure, signature, hash; only
allowlisted `R_XTENSA_RELATIVE` relocations) made the unpatched loader
write through `esp_elf_map_sym()==0` for the never-loaded `.ctors`
pointer: `Guru Meditation Error: Core 1 panic'ed (LoadProhibited)`,
`EXCVADDR: 0x00000000`, firmware reboot. That is a fail-open crash (DoS),
not a fail-before-execute rejection — a hostile producer with any valid
signing key path (or a leaked CI key) crashes the device.
- "Constructor never runs" silent misbehavior is the *benign* branch of the
same gap; the observed branch was worse.
- Build gates cannot be the last line: the T5 corpus methodology (and this
task's packaging) demonstrates signed containers bypass builder/pipeline
checks by construction. p2 established the same lesson for ELF identity.
- With p4, the same container is rejected pre-allocation with
`-EINVAL` ("Forbidden C++ feature section '.ctors'"), canary unchanged.
Registered as patch p4 in `components/elf_loader/PATCHES.md` (diff + sha256
+ rationale). The section list mirrors gate 4 exactly (prefix match covers
numbered subsections like `.init_array.00001`).
## v2/v4/v5/v6 board coverage note
By design (and per the task contract) only v1 and v3 have on-board corpus
rows: v2 (`.dtors`), v4 (`.eh_frame`/`.gcc_except_table`) and v6
(`.eh_frame`) share p4's section-scan mechanism, whose on-target behavior is
proven by v1's row; v5's loader-side layer is the import `-ENOSYS` path
proven on board by T5's `import_neg` row. Their L1 gate rejection is proven
in the build log (verbatim gate error for each). If Gate-A review wants belt
and braces, packaging them is a 5-line extension of `build_cxx_probes.py`.
## Notes for T15 (CI corpus lane)
- The expected-failure probes already run inside the poc_a CI build lane
(`poca_cxx_probe_*` targets are dependencies of the main component): each
lane build fails unless all six probes are rejected with the recorded
reason. The lane log carries each rejection verbatim.
- To script appendix C 11.3 static checks in the host corpus job: gate 4's
forbidden-stem list (`check_plugin_elf.cmake`) and p4's loader list
(`esp_elf.c` patch p4) must stay in sync — both are single sources,
mirror by convention; a corpus test should assert the two lists are
identical (parse both) so drift is caught.
- `neg_tls_nosect` shows the pattern for relocation-layer-only probes:
rename the section names in `.shstrtab` (same-length overwrite) and the
reloc allowlist is the only remaining layer.
## Evidence pointers
- Build-side rejection (verbatim gate errors, all six), determinism hashes,
probe ELF sha256s, artifact map: `.omo/evidence/poca/task-6-poc-a-dynamic-elf.log`.
- Pre-p4 gap demo (LoadProhibited crash + reboot): same log, phase 2.
- Post-p4 matrix (3 positives + 10 negatives, canary unchanged, runs
1/4/5 PASS; runner-side flakes of runs 2/3 disambiguated in-log): same
log, phase 3. Raw board output archived under `poc/evidence/poc-a-<date>/`
by T16.