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:
@@ -0,0 +1,242 @@
|
||||
=== task-2 poc-a-dynamic-elf: manifest_builder.py + test signing ===
|
||||
date: 2026-08-31T20:59:11+08:00 worktree: /home/lain/Projects/esp_study/poc-a-wt branch: poc-a-dynamic-elf HEAD: 4bb53f2
|
||||
|
||||
--- dependency carve-out (plan-sanctioned): cryptography ---
|
||||
+ "cryptography>=50.0.1",
|
||||
+frame-manifest-builder = "frame_tools.manifest_builder:main"
|
||||
122:name = "cryptography"
|
||||
128:sdist = { url = "https://files.pythonhosted.org/packages/bb/ad/5d6702db60b1e40b41ef513b6967ff5848f307d50f8449baf1634f5908f1/cryptography-50.0.1.tar.gz", hash = "sha256:5dd9bda1c12b4162f6ff568eeb5e0ff956c28d14406e875cfe8a63a2d414ff20", size = 880381, upload-time = "2026-08-25T19:45:45.499Z" }
|
||||
|
||||
--- gate 1: uv run ruff format --check tools tests ---
|
||||
18 files already formatted
|
||||
FORMAT_EXIT=0
|
||||
|
||||
--- gate 2: uv run ruff check tools tests ---
|
||||
All checks passed!
|
||||
RUFF_EXIT=0
|
||||
|
||||
--- gate 3: uv run pyright ---
|
||||
0 errors, 0 warnings, 0 informations
|
||||
PYRIGHT_EXIT=0
|
||||
|
||||
--- gate 4: uv run pytest ---
|
||||
.................................................. [100%]
|
||||
50 passed in 0.38s
|
||||
PYTEST_EXIT=0
|
||||
|
||||
=== demo + T3 constants ===
|
||||
synthetic elf bytes: 204 iram extracted: 0x800
|
||||
|
||||
=== layout tables (T3 contract) ===
|
||||
fixed_header (little-endian, struct field order):
|
||||
total size: 92 bytes (0x5C)
|
||||
offset size type field
|
||||
0 4 I magic
|
||||
4 2 H format_major
|
||||
6 2 H format_minor
|
||||
8 4 I header_size
|
||||
12 4 I total_size
|
||||
16 4 I flags
|
||||
20 4 I target_id
|
||||
24 2 H core_abi_major
|
||||
26 2 H core_abi_minor
|
||||
28 8 Q required_features
|
||||
36 8 Q optional_features
|
||||
44 4 I manifest_offset
|
||||
48 4 I manifest_length
|
||||
52 4 I payload_table_offset
|
||||
56 2 H payload_count
|
||||
58 2 H payload_entry_size
|
||||
60 4 I signature_offset
|
||||
64 4 I signature_length
|
||||
68 4 I key_id
|
||||
72 4 I security_epoch
|
||||
76 16 4I reserved
|
||||
|
||||
payload_table entry:
|
||||
total size: 60 bytes (0x3C)
|
||||
offset size type field
|
||||
0 2 H payload_type
|
||||
2 2 H flags
|
||||
4 4 I offset
|
||||
8 4 I length
|
||||
12 4 I unpacked_length
|
||||
16 4 I alignment
|
||||
20 32 32s sha256
|
||||
52 8 2I reserved
|
||||
|
||||
signature_record:
|
||||
total size: 72 bytes (0x48)
|
||||
offset size type field
|
||||
0 2 H algorithm
|
||||
2 2 H record_version
|
||||
4 4 I key_id
|
||||
8 64 64s signature
|
||||
|
||||
manifest TLV entry: field_id u16 | flags u16 | length u32 | value length bytes
|
||||
TLV_FLAG_REQUIRED = 0x0001; unknown field_id + required -> reject
|
||||
|
||||
signing input: sha256(fixed_header_bytes || manifest_bytes || payload_table_bytes)
|
||||
signature: ECDSA P-256 over that digest, IEEE P1363 r||s, 64 bytes
|
||||
magic 0x4d504246 serialized little-endian is bytes 46 42 50 4d
|
||||
target FRAME_TARGET_ESP32S3 = 0x33505345
|
||||
header flags: bit0 resource-only = 0x00000001
|
||||
payload types: ELF=1 RESOURCE=2
|
||||
payload flags: REQUIRED=0x0001 COMPRESSED=0x0002 (ELF must not set COMPRESSED)
|
||||
region order: header | manifest | payload_table | payloads | signature_record;
|
||||
manifest directly after header, table directly after manifest, payloads inside the
|
||||
window [table_end, signature_offset) with per-entry alignment, signature ends at
|
||||
total_size; any other byte coverage is FRAME_ERR_PACKAGE_INVALID.
|
||||
error codes: PACKAGE_INVALID=-18 SIGNATURE_INVALID=-17 HASH_MISMATCH=-19
|
||||
EPOCH_ROLLBACK=-34 TARGET_MISMATCH=-35 ABI_MISMATCH=-7
|
||||
manifest TLV field ids:
|
||||
1 name (utf8_name)
|
||||
2 version (semver)
|
||||
3 requires (str_list)
|
||||
4 max_memory_bytes (u32)
|
||||
5 iram_required_bytes (u32)
|
||||
6 core_affinity (affinity)
|
||||
7 strand_queue_capacity (u32)
|
||||
8 max_outstanding_operations (u32)
|
||||
9 max_timers (u32)
|
||||
10 max_managed_tasks (u32)
|
||||
11 managed_task_priority (u32)
|
||||
12 managed_task_stack_size (u32)
|
||||
13 heartbeat_interval_ms (u32)
|
||||
14 event_rate_limit (u32)
|
||||
15 max_event_subscriptions (u32)
|
||||
16 max_event_message_bytes (u32)
|
||||
17 max_event_buffer_bytes (u32)
|
||||
18 max_outstanding_rpc (u32)
|
||||
19 max_display_commands (u32)
|
||||
20 max_display_bytes (u32)
|
||||
21 max_storage_requests (u32)
|
||||
22 max_storage_io_bytes (u32)
|
||||
23 max_storage_copy_bytes (u32)
|
||||
24 max_tcp_connections (u32)
|
||||
25 max_udp_sockets (u32)
|
||||
26 max_network_requests (u32)
|
||||
27 max_network_buffer_bytes (u32)
|
||||
28 max_network_io_bytes (u32)
|
||||
29 max_log_records_per_second (u32)
|
||||
30 max_log_buffer_bytes (u32)
|
||||
31 max_resource_leases (u32)
|
||||
32 max_update_backlog_events (u32)
|
||||
33 max_update_backlog_bytes (u32)
|
||||
34 state_schema_id (schema_id)
|
||||
35 state_schema_version (u32)
|
||||
|
||||
committed test key key_id = e5677a1c
|
||||
DEMO_SCRIPT_EXIT=0
|
||||
|
||||
=== CLI demo: build + verify with committed test key (entry point frame-manifest-builder) ===
|
||||
/tmp/opencode/poca-t2/code.mpb: signed 572 byte mpb, key_id=e5677a1c, sha256=cdd0d12bb8647620000d64924ab216435c6a5cee339da3e74ba03226127df6e5
|
||||
BUILD_CODE_EXIT=0
|
||||
/tmp/opencode/poca-t2/res.mpb: signed 352 byte mpb, key_id=e5677a1c, sha256=abd94f50ddeceac4ba82de007190a186dd1d431ec106b36a0366e185374b22d3
|
||||
BUILD_RES_EXIT=0
|
||||
/tmp/opencode/poca-t2/code.mpb: OK (code)
|
||||
name=poc-a-demo version=1.2.3 epoch=1 key_id=e5677a1c
|
||||
payloads=1 iram_required_bytes=2048
|
||||
payload[0] sha256=d6b48ace6f549dc211b33abbf76eef454eb46873482cc15406fca0f1b1836b52
|
||||
VERIFY_CODE_EXIT=0
|
||||
/tmp/opencode/poca-t2/res.mpb: OK (resource-only)
|
||||
name=poc-a-res version=0.1.0 epoch=1 key_id=e5677a1c
|
||||
payloads=2 iram_required_bytes=0
|
||||
payload[0] sha256=c3f98e7c86c7e4f3968e5969c9ccf37c72049cbcf556b60bf5a6694e76506e3c
|
||||
payload[1] sha256=df0209573157daf203be7b9f41d657b82bba995e2ac2f695e3481d96a289eaba
|
||||
VERIFY_RES_EXIT=0
|
||||
|
||||
--- determinism cross-check: rebuild code.mpb byte-identical ---
|
||||
BYTE_IDENTICAL=1
|
||||
CMP_EXIT=0
|
||||
|
||||
--- hexdump head: code.mpb (first 160 bytes) ---
|
||||
/usr/bin/bash: line 34: xxd: command not found
|
||||
--- hexdump head: res.mpb (first 96 bytes) ---
|
||||
/usr/bin/bash: line 36: xxd: command not found
|
||||
|
||||
--- tamper demos (misleading_success_output class): verify MUST fail ---
|
||||
code.header.epoch: rejected [-17] ECDSA P-256 signature over fixed_header+manifest+payload_table is invalid
|
||||
res.signature.r: TAMPER ACCEPTED -- BUG
|
||||
code.payload.tail: rejected [-19] payload 0 sha256 does not match
|
||||
TAMPER_DEMO_EXIT=0
|
||||
|
||||
=== CORRECTION: 'res.signature.r' probe above was mislabeled ===
|
||||
it flipped byte sig_off-1 = 279, which is alignment PADDING inside the payload
|
||||
window (payload[1] covers [264,277), sig_off=280): padding bytes lie outside every
|
||||
described region, are not authenticated by design (payloads are bound via the
|
||||
signed table's per-entry sha256) and must never be interpreted by any parser.
|
||||
Correctly-targeted probes:
|
||||
res.signature.r[0] (sig_off+8): rejected [-17] ECDSA P-256 signature over fixed_header+manifest+payload_table is invalid
|
||||
res.payload[1].last_byte (276): rejected [-19] payload 1 sha256 does not match
|
||||
res.padding_byte (279) - expected ACCEPT (dead byte): accepted
|
||||
PROBE_EXIT=0
|
||||
|
||||
--- hexdump head: code.mpb (first 160 bytes, od) ---
|
||||
000000 46 42 50 4d 01 00 00 00 5c 00 00 00 3c 02 00 00 >FBPM....\...<...<
|
||||
000010 00 00 00 00 45 53 50 33 01 00 00 00 00 00 00 00 >....ESP3........<
|
||||
000020 00 00 00 00 00 00 00 00 00 00 00 00 5c 00 00 00 >............\...<
|
||||
000030 8f 00 00 00 eb 00 00 00 01 00 3c 00 f4 01 00 00 >..........<.....<
|
||||
000040 48 00 00 00 1c 7a 67 e5 01 00 00 00 00 00 00 00 >H....zg.........<
|
||||
000050 00 00 00 00 00 00 00 00 00 00 00 00 01 00 01 00 >................<
|
||||
000060 0a 00 00 00 70 6f 63 2d 61 2d 64 65 6d 6f 02 00 >....poc-a-demo..<
|
||||
000070 01 00 05 00 00 00 31 2e 32 2e 33 03 00 00 00 14 >......1.2.3.....<
|
||||
000080 00 00 00 01 11 00 66 72 61 6d 65 2f 63 6f 72 65 >......frame/core<
|
||||
000090 3e 3d 31 2e 30 2e 30 04 00 00 00 04 00 00 00 00 >>=1.0.0.........<
|
||||
--- hexdump head: res.mpb (first 96 bytes, od) ---
|
||||
000000 46 42 50 4d 01 00 00 00 5c 00 00 00 60 01 00 00 >FBPM....\...`...<
|
||||
000010 01 00 00 00 45 53 50 33 01 00 00 00 00 00 00 00 >....ESP3........<
|
||||
000020 00 00 00 00 00 00 00 00 00 00 00 00 5c 00 00 00 >............\...<
|
||||
000030 1e 00 00 00 7a 00 00 00 02 00 3c 00 18 01 00 00 >....z.....<.....<
|
||||
000040 48 00 00 00 1c 7a 67 e5 01 00 00 00 00 00 00 00 >H....zg.........<
|
||||
000050 00 00 00 00 00 00 00 00 00 00 00 00 01 00 01 00 >................<
|
||||
|
||||
=== final gates (post docstring note) ===
|
||||
18 files already formatted
|
||||
FORMAT_EXIT=0
|
||||
All checks passed!
|
||||
RUFF_EXIT=0
|
||||
0 errors, 0 warnings, 0 informations
|
||||
PYRIGHT_EXIT=0
|
||||
50 passed in 0.37s
|
||||
PYTEST_EXIT=0
|
||||
|
||||
=== committed test key material (TEST-ONLY, SEC-003/SEC-005 dev default) ===
|
||||
total 12
|
||||
-rw-r--r-- 1 lain lain 241 Aug 31 20:55 poc_a_test_signing_key.pem
|
||||
-rw-r--r-- 1 lain lain 178 Aug 31 20:55 poc_a_test_signing_key.pub.pem
|
||||
-rw-r--r-- 1 lain lain 1121 Aug 31 20:55 README.md
|
||||
5d9632acefe2ea44081de2733aac2aa5114f31c8c6f86f6da72c3afedc14a72b tools/frame_tools/testdata/keys/poc_a_test_signing_key.pem
|
||||
2b9bf256c94f7098735a6976a946fda473dad82a501a307588d6e6ee7669075c tools/frame_tools/testdata/keys/poc_a_test_signing_key.pub.pem
|
||||
Private-Key: (256 bit)
|
||||
priv:
|
||||
key_id (sha256(SPKI-DER)[:4] big-endian) = e5677a1c
|
||||
|
||||
=== determinism rationale (why RFC 6979 inside the tool) ===
|
||||
library ECDSA sign twice identical (randomized k): False
|
||||
rfc6979 A.2.5 P-256/SHA-256 vector ok: True
|
||||
KEY_PROBE_EXIT=0
|
||||
|
||||
=== commit + post-commit gate re-run on committed tree ===
|
||||
commit 4793cc2e1b14fb96e7504410cce1777d3b5989b9
|
||||
Author: ania-lain <[email protected]>
|
||||
Date: Mon Aug 31 21:02:23 2026 +0800
|
||||
|
||||
feat(tools): deterministic mpb manifest builder with test signing
|
||||
|
||||
.gitleaks.toml | 5 +
|
||||
pyproject.toml | 2 +
|
||||
tests/test_manifest_builder.py | 352 ++++++
|
||||
tools/frame_tools/manifest_builder.py | 1219 ++++++++++++++++++++
|
||||
tools/frame_tools/testdata/keys/README.md | 26 +
|
||||
.../testdata/keys/poc_a_test_signing_key.pem | 5 +
|
||||
.../testdata/keys/poc_a_test_signing_key.pub.pem | 4 +
|
||||
uv.lock | 165 +++
|
||||
FORMAT_EXIT=0
|
||||
RUFF_EXIT=0
|
||||
PYRIGHT_EXIT=0
|
||||
50 passed in 0.37s
|
||||
PYTEST_EXIT=0
|
||||
note: .gitleaks.toml gained a path allowlist for tools/frame_tools/testdata/keys/ --
|
||||
necessary so the plan-sanctioned TEST-ONLY key does not redden CI's gitleaks job;
|
||||
flagged to orchestrator as a documented deviation from the tools/+tests/+pyproject+uv.lock file whitelist.
|
||||
Reference in New Issue
Block a user