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]>
This commit is contained in:
Lain
2026-09-07 20:02:18 +08:00
committed by GitHub
co-authored by lain
parent 0018ebbb8f
commit e71842aa8a
163 changed files with 97525 additions and 50 deletions
@@ -0,0 +1,188 @@
=== task-15 poc-a-dynamic-elf evidence ===
started: 2026-08-31T15:28:57Z
worktree: c5d6c6ce5cd88ffa634d7a5e23268875737f905a
yaml parses; jobs: repository-gates, mpb-corpus-gates, host-clang-sanitizers, host-gcc, host-clang-tidy, host-coverage, secrets, firmware-dev, firmware-m1, firmware-poc-a, required
mpb-corpus-gates steps:
- Check out repository
- Set up uv
- Install locked Python environment
- Build and run the MPB parser corpus suite
- Regenerate the MPB corpus and compare byte for byte
- Run plugin policy checker and stem drift guard tests
pinned action SHAs: {'20cfd1bf945f4377ade1205e4dbc17946fc9a30d', '3d3c42e5aac5ba805825da76410c181273ba90b1'}
format globs line: 'poc/apps/m1_hardware/main/**' 'poc/apps/poc_a/main/**' \
format grep: 'poc/apps/poc_a/plugins/**' | grep -E '\.(c|cc|cpp|cxx|h|hh|hpp)$' | sort)
YAML-LINT OK
=== [1] lane cmd: poc/host build + ctest -R MpbParser ===
=== [1] lane cmd: poc/host build + ctest -R MpbParser ===
[100%] Built target mpb_parser_test
Start 31: MpbParser.ByteFlipFuzzNeverCrashes
28/28 Test #31: MpbParser.ByteFlipFuzzNeverCrashes ........................ Passed 0.03 sec
100% tests passed out of 28
Total Test time (real) = 0.11 sec
MpbParser.ByteFlipFuzzNeverCrashes
MpbParser.CodePositiveVerifiesAndExposesView
MpbParser.CorpusAbiMismatch
MpbParser.CorpusDuplicateRequiredTlv
MpbParser.CorpusEpochRollback
MpbParser.CorpusFeaturesExceedDevice
MpbParser.CorpusMagic
MpbParser.CorpusMixedElfInResourceOnly
MpbParser.CorpusMixedResourceInCode
MpbParser.CorpusOffsetOutOfBounds
MpbParser.CorpusPayloadHash
MpbParser.CorpusRegionOverlap
MpbParser.CorpusSignatureTamper
MpbParser.CorpusTargetMismatch
MpbParser.CorpusTotalSize
MpbParser.CorpusUnknownRequiredTlv
MpbParser.CorpusWrongKeyId
MpbParser.DoubleFaultReportsSignatureBeforeHash
MpbParser.EpochFloorEqualStillVerifies
MpbParser.EveryFixtureMatchesItsExpectedErrorCode
MpbParser.ManifestFieldAccessorRoundTrip
MpbParser.MaxPackageBytesPolicyRejectsOversize
MpbParser.NullArgumentsAreRejected
MpbParser.RandomTruncationsFailClosed
MpbParser.ResourceOnlyPositiveVerifiesWithWindowPadding
MpbParser.SignatureRecordFieldsAreStructural
MpbParser.TamperedElfPayloadByteRejectedAsHashMismatch
MpbParser.TruncationFuzzAlwaysFailsClosed
=== [2] lane cmd: regeneration check (run 1 of 2) ===
wrote 18 fixtures + corpus_manifest.inc to /tmp/tmp.nyfY9NeNLO/poc/host/tests/mpb_corpus
pos_code.mpb expected= 0 positive-code
pos_resource_only.mpb expected= 0 positive-resource-only
neg_magic.mpb expected= -18 negative-magic
neg_total_size.mpb expected= -18 negative-total-size
neg_offset_oob.mpb expected= -18 negative-offset-oob
neg_overlap.mpb expected= -18 negative-overlap
neg_dup_required.mpb expected= -18 negative-dup-required
neg_unknown_required_tlv.mpb expected= -18 negative-unknown-required-tlv
neg_mixed_elf_in_res.mpb expected= -18 negative-mixed-elf-in-res
neg_mixed_res_in_elf.mpb expected= -18 negative-mixed-res-in-elf
neg_payload_hash.mpb expected= -19 negative-payload-hash
neg_signature.mpb expected= -17 negative-signature
neg_double_fault.mpb expected= -17 negative-double-fault
neg_key_id.mpb expected= -17 negative-key-id
neg_target.mpb expected= -35 negative-target
neg_abi.mpb expected= -7 negative-abi
neg_features.mpb expected= -7 negative-features
neg_epoch.mpb expected= -34 negative-epoch
f6b9002aee6885719404b6feeb566a412a94e09d9d792bfb1b866998cac6f6dc poc/host/tests/mpb_corpus/neg_abi.mpb
b29fed6c397ed193fbc55b44cc957311d5e1e79946206f4cf51e498e3b9cde65 poc/host/tests/mpb_corpus/neg_double_fault.mpb
1441b28ea2034e122919467efa7d76b6911ed093fbf5f0931d6f0ad267893494 poc/host/tests/mpb_corpus/neg_dup_required.mpb
ec9297e6cb6507073287216e1f311e14f161fc4e711c564943005debc0c5c76b poc/host/tests/mpb_corpus/neg_epoch.mpb
87fe364bf95aeb74a3dc05d59da79e14a63a4c34a941f480755e5c1b15f152ba poc/host/tests/mpb_corpus/neg_features.mpb
aa23322034e7502a9537eaa5af800fe5cfa435503d37f32a01a8af3f859e6e70 poc/host/tests/mpb_corpus/neg_key_id.mpb
edca005c4f67db79386c136f91caf7cc2c41964eab064cea2049a4acf5eafde2 poc/host/tests/mpb_corpus/neg_magic.mpb
80cca8ba5dc83103436791913990747bfd677f0e60263de5fae1f339fc08d05e poc/host/tests/mpb_corpus/neg_mixed_elf_in_res.mpb
872ee8e818f0708bcc4be4c043ce3cb68878a2825078dfed7835ea51ea800c7e poc/host/tests/mpb_corpus/neg_mixed_res_in_elf.mpb
525065064fabe251b3ba1f96b8d6843e03c5c893e7901b99c07381e20f05ab49 poc/host/tests/mpb_corpus/neg_offset_oob.mpb
6c61b658fcdccc1ebbecaae90a81994aedad44039a9a7a90df15d205d23feec8 poc/host/tests/mpb_corpus/neg_overlap.mpb
191059b17c44e0a5c1ea52a7a17a3d7594fb37662b45e030e618a3f4d36e4fd1 poc/host/tests/mpb_corpus/neg_payload_hash.mpb
b7673bf613240bb6d596c53b83752ef4f2d0fc465bfd273ff0c4840c5c62a532 poc/host/tests/mpb_corpus/neg_signature.mpb
8703e1b8cd9bd1e3d7afc857b618b3c50b14051bf3b5a37129153fae37252000 poc/host/tests/mpb_corpus/neg_target.mpb
e5fc8d7b2bb8d13dc7839692f70eda8e62bbeb9ef664c855533fbd4dc3d3edfe poc/host/tests/mpb_corpus/neg_total_size.mpb
0a6ba33bf7a6f3bc60687f4fabb1506b34fc46cd4d6d628438474dff1728cea6 poc/host/tests/mpb_corpus/neg_unknown_required_tlv.mpb
d86937e9540d3b188d31fbd6ba67b5319694923d0210db2b4383a4724f0101ef poc/host/tests/mpb_corpus/pos_code.mpb
318872c5ac2b50747d066e572c3d815688ec5c8fe74ab2147a5bfe1d8855b399 poc/host/tests/mpb_corpus/pos_resource_only.mpb
committed corpus is byte-identical to a fresh regeneration
run1-exit=0
=== [3] regeneration check (run 2 of 2, determinism) ===
run 2: byte-identical again (deterministic 2x)
=== [4] NEGATIVE CONTROL: break one corpus byte ===
-- regen check must FAIL now:
Binary files poc/host/tests/mpb_corpus/pos_code.mpb and /tmp/tmp.5wIpnNJPXK/poc/host/tests/mpb_corpus/pos_code.mpb differ
regen-diff-exit=1 (nonzero = gate bites)
-- ctest must FAIL on tampered corpus:
1/28 Test #4: MpbParser.EveryFixtureMatchesItsExpectedErrorCode .........***Failed 0.00 sec
2/28 Test #5: MpbParser.CodePositiveVerifiesAndExposesView ..............***Failed 0.00 sec
4/28 Test #7: MpbParser.ManifestFieldAccessorRoundTrip ..................***Failed 0.00 sec
5/28 Test #8: MpbParser.NullArgumentsAreRejected ........................***Failed 0.00 sec
22/28 Test #25: MpbParser.MaxPackageBytesPolicyRejectsOversize ............***Failed 0.00 sec
-- restore:
d86937e9540d3b188d31fbd6ba67b5319694923d0210db2b4383a4724f0101ef poc/host/tests/mpb_corpus/pos_code.mpb
0
-- post-restore ctest:
Total Test time (real) = 0.12 sec
=== [5] post-restore corpus ctest (full) ===
100% tests passed out of 28
Total Test time (real) = 0.11 sec
=== [6] lane cmd: pytest policy suite -v ===
tests/test_check_plugin_policy.py::test_shape_failures_fail_closed[kwargs1] PASSED [ 86%]
tests/test_check_plugin_policy.py::test_shape_failures_fail_closed[kwargs2] PASSED [ 89%]
tests/test_check_plugin_policy.py::test_shape_failures_fail_closed[kwargs3] PASSED [ 91%]
tests/test_check_plugin_policy.py::test_shape_failures_fail_closed[kwargs4] PASSED [ 94%]
tests/test_check_plugin_policy.py::test_cli_accepts_a_policy_clean_elf PASSED [ 97%]
tests/test_check_plugin_policy.py::test_cli_rejects_a_violating_elf_and_names_the_reasons PASSED [100%]
============================== 37 passed in 0.03s ==============================
=== [7] FULL uv run pytest ===
tests/test_sbom.py .. [100%]
============================== 87 passed in 0.40s ==============================
=== [8] ruff format --check / ruff check / pyright (repository-gates scope) ===
20 files already formatted
All checks passed!
0 errors, 0 warnings, 0 informations
=== [9] widened format-glob dry-run (local clang-format 22.1.8; checked-in files verified 18-compatible per T5/T6 notes) ===
files gated: 60
=== [10] checker CLI smoke ===
usage: check-plugin-policy [-h] [--entry ENTRY] [--allow-import ALLOW_IMPORT]
[--allow-imports-file ALLOW_IMPORTS_FILE]
elfs [elfs ...]
M .github/workflows/ci.yml
M poc/apps/poc_a/components/elf_loader/include/private/elf_platform.h
M poc/apps/poc_a/components/elf_loader/include/private/elf_types.h
M poc/apps/poc_a/components/elf_loader/src/esp_elf.c
M poc/apps/poc_a/components/elf_loader/src/esp_elf_adapter.c
M poc/apps/poc_a/plugins/check_plugin_elf.cmake
M poc/apps/poc_a/plugins/plugin_abi.h
M poc/apps/poc_a/plugins/plugins.cmake
?? poc/apps/poc_a/plugins/iram_probe/
?? tests/test_check_plugin_policy.py
?? tools/frame_tools/check_plugin_policy.py
=== [9b] widened format glob with REAL clang-format 18.1.8 (uvx clang-format==18.1.8) ===
files gated: 60
=== [11] commit ===
[poc-a-dynamic-elf 796f9d2] ci(poc-a): host mpb corpus and policy lane
3 files changed, 661 insertions(+), 1 deletion(-)
create mode 100644 tests/test_check_plugin_policy.py
create mode 100644 tools/frame_tools/check_plugin_policy.py
796f9d2 ci(poc-a): host mpb corpus and policy lane
c5d6c6c feat(poc-a): cxx feature rejection matrix
M poc/apps/poc_a/components/elf_loader/include/private/elf_platform.h
M poc/apps/poc_a/components/elf_loader/include/private/elf_types.h
M poc/apps/poc_a/components/elf_loader/src/esp_elf.c
M poc/apps/poc_a/components/elf_loader/src/esp_elf_adapter.c
M poc/apps/poc_a/main/CMakeLists.txt
M poc/apps/poc_a/main/poca_plugin.cc
M poc/apps/poc_a/main/poca_plugin.hh
M poc/apps/poc_a/plugins/check_plugin_elf.cmake
M poc/apps/poc_a/plugins/plugin_abi.h
M poc/apps/poc_a/plugins/plugins.cmake
?? poc/apps/poc_a/plugins/iram_probe/
=== post-commit re-verify of drift guard against in-flight tree ===
37 passed in 0.03s
=== task-15 complete ===
finished: 2026-08-31T15:38:36Z
commit: 796f9d2 ci(poc-a): host mpb corpus and policy lane (worktree poc-a-wt, not pushed)