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,506 @@
|
||||
# poca_plugin(<name> SOURCE <file.c> VERSION <semver> ENTRY <symbol> MANIFEST <json>
|
||||
# [IMPORTS <sym>...] [IRAM] [MPB_NAME <name>] [MAGIC <0xC_MACRO_SUFFIX>])
|
||||
#
|
||||
# PoC-A plugin build pipeline (task T4 of poc-a-dynamic-elf). Produces, under
|
||||
# ${CMAKE_BINARY_DIR}/plugins/:
|
||||
# <name>.o object compiled with the firmware build's xtensa gcc
|
||||
# <name>/<name>.elf plugin ELF loadable by the vendored elf_loader
|
||||
# <name>.mpb signed MPB container built by tools/frame_tools
|
||||
# manifest_builder.py (frame-manifest-builder)
|
||||
# generated/poca_<name>_meta.h size + sha256 of the mpb, compiled into the
|
||||
# firmware so the device can detect a stale embed
|
||||
#
|
||||
# MPB_NAME (T8): overrides the manifest name field (default: <name>) so two
|
||||
# packaged generations of the same plugin identity can carry
|
||||
# the SAME manifest name with different versions (PLUG-004
|
||||
# hot-update semantics) while remaining distinct build
|
||||
# targets.
|
||||
# MAGIC (T8): appends -DPOCA_BASELINE_ACTIVATE_MAGIC=<value> to the plugin
|
||||
# compile and emits POCA_<NAME>_MAGIC into the meta header, so
|
||||
# generation variants return distinguishable activate()
|
||||
# self-check values.
|
||||
#
|
||||
# IRAM (T7): the plugin places hot functions in a .plugin_iram section;
|
||||
# enables gate 5 in check_plugin_elf.cmake (single ALLOC+EXEC section, no
|
||||
# split subsections, no relocations patching the section span).
|
||||
#
|
||||
# Flag provenance: the compile/link/strip flag sets mirror the vendored
|
||||
# component poc/apps/poc_a/components/elf_loader/elf_loader.cmake
|
||||
# project_elf()/project_so() macros (esp-iot-solution @6526c5b1, ADR-0002
|
||||
# coupling). Deviations, each deliberate and the only ones:
|
||||
# - the -Wl,--strip-* link trio is dropped and stripping is deferred to the
|
||||
# strip step, because the firmware finds the query entry through the
|
||||
# symbol table (--keep-symbol=<entry>) instead of assuming the ELF header
|
||||
# entry point;
|
||||
# - --keep-symbol=${ENTRY} is added to --strip-unneeded so exactly one
|
||||
# exported symbol survives in .symtab;
|
||||
# - -Wl,--build-id=none (plus the matching strip removal) keeps note
|
||||
# sections out of the image;
|
||||
# - the compile adds -std=c11 -Os -ffreestanding -fno-builtin because the
|
||||
# plugin is a single freestanding C file with no newlib/libgcc references
|
||||
# (the upstream macros compile inside a full ESP-IDF component context).
|
||||
#
|
||||
# IMPORTS (T5): declares the plugin's host imports (the allowlisted
|
||||
# undefined symbols that gate 2 accepts). This is a BUILD-side intent
|
||||
# declaration only; the device still refuses to load the plugin unless the
|
||||
# same names are registered at runtime through esp_elf_register_symbol().
|
||||
#
|
||||
# The pipeline additionally enforces what the vendored loader expects but does
|
||||
# not itself guarantee (check_plugin_elf.cmake, feeds the T5 allowlist work):
|
||||
# 1. every emitted dynamic relocation type is inside
|
||||
# {R_XTENSA_RELATIVE, R_XTENSA_RTLD, R_XTENSA_GLOB_DAT, R_XTENSA_JMP_SLOT}
|
||||
# (plus R_XTENSA_NONE);
|
||||
# 2. undefined symbols are exactly the declared IMPORTS set;
|
||||
# 3. ELF32 / little-endian / Xtensa / ET_DYN with a live <ENTRY> symbol.
|
||||
|
||||
# Capture the directory of this file at include time; CMAKE_CURRENT_LIST_DIR
|
||||
# inside the functions below would otherwise resolve to the caller's
|
||||
# directory (main/).
|
||||
set(POCA_PLUGINS_DIR "${CMAKE_CURRENT_LIST_DIR}")
|
||||
set(POCA_REPO_ROOT "${POCA_PLUGINS_DIR}/../../../..")
|
||||
|
||||
function(poca_plugin name)
|
||||
cmake_parse_arguments(PLUGIN "IRAM" "SOURCE;VERSION;ENTRY;MANIFEST;MPB_NAME;MAGIC" "IMPORTS" ${ARGN})
|
||||
if(NOT PLUGIN_SOURCE OR NOT PLUGIN_VERSION OR NOT PLUGIN_ENTRY OR NOT PLUGIN_MANIFEST)
|
||||
message(FATAL_ERROR "poca_plugin(${name}): SOURCE, VERSION, ENTRY and MANIFEST are required")
|
||||
endif()
|
||||
if(NOT PLUGIN_IMPORTS)
|
||||
set(PLUGIN_IMPORTS "")
|
||||
endif()
|
||||
if(NOT PLUGIN_MPB_NAME)
|
||||
set(PLUGIN_MPB_NAME "${name}")
|
||||
endif()
|
||||
if(PLUGIN_IRAM)
|
||||
set(iram_gate_args "-D" "EXPECT_IRAM_SECTION=1")
|
||||
else()
|
||||
set(iram_gate_args "-D" "EXPECT_IRAM_SECTION=0")
|
||||
endif()
|
||||
|
||||
set(plugins_dir "${POCA_PLUGINS_DIR}")
|
||||
set(out_dir "${CMAKE_BINARY_DIR}/plugins")
|
||||
set(gen_dir "${out_dir}/generated")
|
||||
file(MAKE_DIRECTORY "${out_dir}/${name}" "${gen_dir}")
|
||||
|
||||
set(obj "${out_dir}/${name}/${name}.o")
|
||||
set(elf_raw "${out_dir}/${name}/${name}.raw.elf")
|
||||
set(elf "${out_dir}/${name}/${name}.elf")
|
||||
set(mpb "${out_dir}/${name}.mpb")
|
||||
set(stamp "${out_dir}/${name}/gates.stamp")
|
||||
set(meta_header "${gen_dir}/poca_${name}_meta.h")
|
||||
|
||||
# Tool siblings of the firmware build's xtensa gcc, same discovery trick
|
||||
# as elf_loader.cmake (string(REPLACE -gcc -strip ...)).
|
||||
string(REPLACE "-gcc" "-readelf" plugin_readelf "${CMAKE_C_COMPILER}")
|
||||
string(REPLACE "-gcc" "-strip" plugin_strip "${CMAKE_C_COMPILER}")
|
||||
string(REPLACE "-gcc" "-nm" plugin_nm "${CMAKE_C_COMPILER}")
|
||||
|
||||
set(plugin_compile_flags -c -std=c11 -Os -g0
|
||||
-fPIC -fvisibility=hidden
|
||||
-fdata-sections -ffunction-sections
|
||||
-ffreestanding -fno-builtin
|
||||
-Wall -Wextra -Werror)
|
||||
if(PLUGIN_MAGIC)
|
||||
list(APPEND plugin_compile_flags "-DPOCA_BASELINE_ACTIVATE_MAGIC=${PLUGIN_MAGIC}")
|
||||
endif()
|
||||
|
||||
set(plugin_link_flags -shared -fPIC -static-libgcc
|
||||
-nostdlib -nostartfiles
|
||||
-fdata-sections -ffunction-sections
|
||||
-Wl,--gc-sections
|
||||
-fvisibility=hidden
|
||||
-Wl,--allow-shlib-undefined
|
||||
-Wl,--build-id=none
|
||||
-e ${PLUGIN_ENTRY})
|
||||
|
||||
set(plugin_strip_flags --strip-unneeded
|
||||
--keep-symbol=${PLUGIN_ENTRY}
|
||||
--remove-section=.comment
|
||||
--remove-section=.got.loc
|
||||
--remove-section=.dynamic
|
||||
--remove-section=.note.gnu.build-id)
|
||||
if(CONFIG_IDF_TARGET_ARCH_XTENSA)
|
||||
list(APPEND plugin_strip_flags
|
||||
--remove-section=.xt.lit
|
||||
--remove-section=.xt.prop
|
||||
--remove-section=.xtensa.info)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${obj}"
|
||||
COMMAND "${CMAKE_C_COMPILER}" ${plugin_compile_flags}
|
||||
-I "${plugins_dir}" -c "${PLUGIN_SOURCE}" -o "${obj}"
|
||||
DEPENDS "${PLUGIN_SOURCE}" "${plugins_dir}/plugin_abi.h"
|
||||
COMMENT "[poca-plugin] compile ${name}.o"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${elf_raw}"
|
||||
COMMAND "${CMAKE_C_COMPILER}" ${plugin_link_flags} "${obj}" -o "${elf_raw}"
|
||||
DEPENDS "${obj}"
|
||||
COMMENT "[poca-plugin] link ${name}.elf"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${elf}"
|
||||
COMMAND "${plugin_strip}" ${plugin_strip_flags} "${elf_raw}" -o "${elf}"
|
||||
DEPENDS "${elf_raw}"
|
||||
COMMENT "[poca-plugin] strip ${name}.elf (keep ${PLUGIN_ENTRY})"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${stamp}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "PLUGIN_NAME=${name}"
|
||||
-D "ELF=${elf}"
|
||||
-D "READELF=${plugin_readelf}"
|
||||
-D "NM=${plugin_nm}"
|
||||
-D "EXPECT_ENTRY=${PLUGIN_ENTRY}"
|
||||
-D "EXPECT_UNDEFINED=${PLUGIN_IMPORTS}"
|
||||
${iram_gate_args}
|
||||
-P "${plugins_dir}/check_plugin_elf.cmake"
|
||||
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
|
||||
DEPENDS "${elf}"
|
||||
COMMENT "[poca-plugin] allowlist/import gates on ${name}.elf"
|
||||
VERBATIM)
|
||||
|
||||
set(repo_root "${POCA_REPO_ROOT}")
|
||||
set(signing_key "${repo_root}/tools/frame_tools/testdata/keys/poc_a_test_signing_key.pem")
|
||||
if(NOT EXISTS "${signing_key}")
|
||||
message(FATAL_ERROR "poca_plugin(${name}): test signing key missing: ${signing_key}")
|
||||
endif()
|
||||
if(Python_EXECUTABLE)
|
||||
set(plugin_python "${Python_EXECUTABLE}")
|
||||
else()
|
||||
set(plugin_python python3)
|
||||
endif()
|
||||
|
||||
# frame-manifest-builder entry point, invoked through the module so the
|
||||
# step also runs inside the plain ESP-IDF CI container (no uv there).
|
||||
add_custom_command(
|
||||
OUTPUT "${mpb}"
|
||||
BYPRODUCTS "${meta_header}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E env "PYTHONPATH=${repo_root}/tools"
|
||||
"${plugin_python}" -m frame_tools.manifest_builder build
|
||||
--elf "${elf}" --name "${PLUGIN_MPB_NAME}" --version "${PLUGIN_VERSION}"
|
||||
--manifest-json "${PLUGIN_MANIFEST}"
|
||||
--key "${signing_key}" --epoch 1 --output "${mpb}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "PLUGIN_NAME=${name}" -D "PLUGIN_MPB_NAME=${PLUGIN_MPB_NAME}"
|
||||
-D "PLUGIN_VERSION=${PLUGIN_VERSION}"
|
||||
-D "PLUGIN_ENTRY=${PLUGIN_ENTRY}"
|
||||
-D "PLUGIN_MAGIC=${PLUGIN_MAGIC}"
|
||||
-D "MPB=${mpb}" -D "OUT=${meta_header}"
|
||||
-P "${plugins_dir}/gen_meta_header.cmake"
|
||||
DEPENDS "${stamp}" "${PLUGIN_MANIFEST}" "${signing_key}"
|
||||
COMMENT "[poca-plugin] package+sign ${name}.mpb"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target("poca_plugin_${name}" DEPENDS "${mpb}")
|
||||
message(STATUS "[poca-plugin] registered ${name} (entry ${PLUGIN_ENTRY}, version ${PLUGIN_VERSION})")
|
||||
endfunction()
|
||||
|
||||
# poca_cxx_probe(<name> SOURCE <file.cpp> ENTRY <symbol> NEEDLES <substr>...
|
||||
# [EXTRA_FLAGS <flag>...])
|
||||
#
|
||||
# T6 C++ feature-rejection probes (appendix C 11.2/11.3). Builds the probe
|
||||
# with the firmware build's xtensa g++ under the pipeline link contract but
|
||||
# with the C++ runtime features that the probe exercises ENABLED, then runs
|
||||
# the REAL positive-pipeline gates (check_plugin_elf.cmake) against the
|
||||
# result and asserts they REJECT it (expected-failure wrapper
|
||||
# cxx_probes/check_probe_rejection.cmake). The probe ELFs are never
|
||||
# gate-approved artifacts; the on-board corpus rows are packaged separately
|
||||
# by build_cxx_probes.py (hostile_signed pattern, see T5).
|
||||
#
|
||||
# The probe compile baseline keeps every OTHER C++ runtime feature off
|
||||
# (-fno-exceptions -fno-rtti -fno-unwind-tables
|
||||
# -fno-asynchronous-unwind-tables) so each variant's emitted artifact set
|
||||
# isolates exactly the feature under test; per-variant flags re-enable one
|
||||
# feature.
|
||||
function(poca_cxx_probe name)
|
||||
cmake_parse_arguments(PROBE "" "SOURCE;ENTRY" "NEEDLES;EXTRA_FLAGS" ${ARGN})
|
||||
if(NOT PROBE_SOURCE OR NOT PROBE_ENTRY OR NOT PROBE_NEEDLES)
|
||||
message(FATAL_ERROR "poca_cxx_probe(${name}): SOURCE, ENTRY and NEEDLES are required")
|
||||
endif()
|
||||
if(NOT PROBE_EXTRA_FLAGS)
|
||||
set(PROBE_EXTRA_FLAGS "")
|
||||
endif()
|
||||
|
||||
set(out_dir "${CMAKE_BINARY_DIR}/plugins")
|
||||
set(gen_dir "${out_dir}/generated")
|
||||
file(MAKE_DIRECTORY "${out_dir}/${name}")
|
||||
|
||||
set(obj "${out_dir}/${name}/${name}.o")
|
||||
set(elf "${out_dir}/${name}/${name}.elf")
|
||||
set(stamp "${out_dir}/${name}/reject.stamp")
|
||||
|
||||
# Tool siblings discovered from the firmware build's xtensa gcc (the g++
|
||||
# driver name does not contain "-gcc"; the C compiler lives in the same
|
||||
# toolchain bin dir).
|
||||
string(REPLACE "-gcc" "-readelf" plugin_readelf "${CMAKE_C_COMPILER}")
|
||||
string(REPLACE "-gcc" "-nm" plugin_nm "${CMAKE_C_COMPILER}")
|
||||
|
||||
set(probe_compile_flags -c -std=c++20 -Os -g0
|
||||
-fPIC -fvisibility=hidden
|
||||
-fdata-sections -ffunction-sections
|
||||
-ffreestanding -fno-builtin
|
||||
-fno-exceptions -fno-rtti
|
||||
-fno-unwind-tables -fno-asynchronous-unwind-tables
|
||||
-Wall -Wextra -Werror)
|
||||
|
||||
set(probe_link_flags -shared -fPIC -static-libgcc
|
||||
-nostdlib -nostartfiles
|
||||
-fdata-sections -ffunction-sections
|
||||
-Wl,--gc-sections
|
||||
-fvisibility=hidden
|
||||
-Wl,--allow-shlib-undefined
|
||||
-Wl,--build-id=none
|
||||
-e ${PROBE_ENTRY})
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${obj}"
|
||||
COMMAND "${CMAKE_CXX_COMPILER}" ${probe_compile_flags} ${PROBE_EXTRA_FLAGS}
|
||||
-I "${POCA_PLUGINS_DIR}" -c "${PROBE_SOURCE}" -o "${obj}"
|
||||
DEPENDS "${PROBE_SOURCE}" "${POCA_PLUGINS_DIR}/plugin_abi.h"
|
||||
COMMENT "[cxx-probe] compile ${name}.o (flags: ${PROBE_EXTRA_FLAGS})"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${elf}"
|
||||
COMMAND "${CMAKE_CXX_COMPILER}" ${probe_link_flags} "${obj}" -o "${elf}"
|
||||
DEPENDS "${obj}"
|
||||
COMMENT "[cxx-probe] link ${name}.elf"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${stamp}"
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "PROBE_NAME=${name}"
|
||||
-D "ELF=${elf}"
|
||||
-D "READELF=${plugin_readelf}"
|
||||
-D "NM=${plugin_nm}"
|
||||
-D "EXPECT_ENTRY=${PROBE_ENTRY}"
|
||||
-D "NEEDLES=${PROBE_NEEDLES}"
|
||||
-D "CHECK_SCRIPT=${POCA_PLUGINS_DIR}/check_plugin_elf.cmake"
|
||||
-P "${POCA_PLUGINS_DIR}/cxx_probes/check_probe_rejection.cmake"
|
||||
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
|
||||
DEPENDS "${elf}" "${POCA_PLUGINS_DIR}/check_plugin_elf.cmake"
|
||||
"${POCA_PLUGINS_DIR}/cxx_probes/check_probe_rejection.cmake"
|
||||
COMMENT "[cxx-probe] ${name}: gates must REJECT (${PROBE_NEEDLES})"
|
||||
VERBATIM)
|
||||
|
||||
add_custom_target("poca_cxx_probe_${name}" DEPENDS "${stamp}")
|
||||
message(STATUS "[cxx-probe] registered ${name} (entry ${PROBE_ENTRY}, "
|
||||
"expect-reject: ${PROBE_NEEDLES})")
|
||||
endfunction()
|
||||
|
||||
# poca_cxx_probe_corpus(CTOR_ELF <elf> TLS_ELF <elf>)
|
||||
#
|
||||
# Packages the on-board T6 corpus rows (cxx_ctor, cxx_tls and the
|
||||
# sections-renamed neg_tls_nosect) from the probe ELFs via the hostile path
|
||||
# (build_cxx_probes.py; TEST-only key). Like poca_negative_corpus this
|
||||
# deliberately steps around the positive pipeline - the probes are rejected
|
||||
# artifacts by design and their containers must still be signature-valid so
|
||||
# the on-device rejection happens in the loader (p1/p4), not in mpb verify.
|
||||
function(poca_cxx_probe_corpus)
|
||||
cmake_parse_arguments(CORPUS "" "CTOR_ELF;TLS_ELF" "" ${ARGN})
|
||||
if(NOT CORPUS_CTOR_ELF OR NOT CORPUS_TLS_ELF)
|
||||
message(FATAL_ERROR "poca_cxx_probe_corpus: CTOR_ELF and TLS_ELF are required")
|
||||
endif()
|
||||
|
||||
set(out_dir "${CMAKE_BINARY_DIR}/plugins")
|
||||
set(gen_dir "${out_dir}/generated")
|
||||
set(corpus_names cxx_ctor cxx_tls neg_tls_nosect)
|
||||
set(corpus_outputs "")
|
||||
foreach(name IN LISTS corpus_names)
|
||||
list(APPEND corpus_outputs "${out_dir}/${name}.mpb" "${gen_dir}/poca_${name}_meta.h")
|
||||
endforeach()
|
||||
set(stamp "${out_dir}/cxx_probes/corpus.stamp")
|
||||
|
||||
set(signing_key "${POCA_REPO_ROOT}/tools/frame_tools/testdata/keys/poc_a_test_signing_key.pem")
|
||||
if(Python_EXECUTABLE)
|
||||
set(corpus_python "${Python_EXECUTABLE}")
|
||||
else()
|
||||
set(corpus_python python3)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${stamp}"
|
||||
BYPRODUCTS ${corpus_outputs}
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${out_dir}/cxx_probes"
|
||||
COMMAND "${corpus_python}" "${POCA_PLUGINS_DIR}/cxx_probes/build_cxx_probes.py"
|
||||
--ctor-elf "${CORPUS_CTOR_ELF}"
|
||||
--tls-elf "${CORPUS_TLS_ELF}"
|
||||
--key "${signing_key}"
|
||||
--out-dir "${out_dir}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
|
||||
DEPENDS "${CORPUS_CTOR_ELF}" "${CORPUS_TLS_ELF}"
|
||||
"${POCA_PLUGINS_DIR}/cxx_probes/build_cxx_probes.py" "${signing_key}"
|
||||
COMMENT "[cxx-corpus] hostile-signed probe containers (cxx_ctor/cxx_tls/neg_tls_nosect)"
|
||||
VERBATIM)
|
||||
add_custom_target(poca_cxx_probe_corpus DEPENDS "${stamp}")
|
||||
endfunction()
|
||||
|
||||
# poca_negative_corpus(BASELINE_ELF <elf> ...)
|
||||
#
|
||||
# T5 negative corpus: runs build_negative_corpus.py against the gated
|
||||
# baseline.elf to fabricate the handcrafted negative containers (out-of-
|
||||
# allowlist relocation types, malformed ELF identity, inflated PT_LOAD
|
||||
# budget). These .mpb files deliberately bypass the check_plugin_elf.cmake
|
||||
# gates - the gates protect positive builds, negatives are handcrafted -
|
||||
# and are signed with the same TEST-only key so device-side mpb
|
||||
# verification still passes and the rejection must come from the loader
|
||||
# (patches p1/p2) or the harness program-header admission check.
|
||||
function(poca_negative_corpus)
|
||||
cmake_parse_arguments(CORPUS "" "BASELINE_ELF" "" ${ARGN})
|
||||
if(NOT CORPUS_BASELINE_ELF)
|
||||
message(FATAL_ERROR "poca_negative_corpus: BASELINE_ELF is required")
|
||||
endif()
|
||||
|
||||
set(out_dir "${CMAKE_BINARY_DIR}/plugins")
|
||||
set(gen_dir "${out_dir}/generated")
|
||||
set(corpus_names neg_r32 neg_s0op neg_phspan neg_phbe neg_ph64 neg_phmach)
|
||||
set(corpus_outputs "")
|
||||
foreach(name IN LISTS corpus_names)
|
||||
list(APPEND corpus_outputs "${out_dir}/${name}.mpb" "${gen_dir}/poca_${name}_meta.h")
|
||||
endforeach()
|
||||
set(stamp "${out_dir}/negative/corpus.stamp")
|
||||
|
||||
set(signing_key "${POCA_REPO_ROOT}/tools/frame_tools/testdata/keys/poc_a_test_signing_key.pem")
|
||||
if(Python_EXECUTABLE)
|
||||
set(corpus_python "${Python_EXECUTABLE}")
|
||||
else()
|
||||
set(corpus_python python3)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${stamp}"
|
||||
BYPRODUCTS ${corpus_outputs}
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${out_dir}/negative"
|
||||
COMMAND "${corpus_python}" "${POCA_PLUGINS_DIR}/negative/build_negative_corpus.py"
|
||||
--baseline-elf "${CORPUS_BASELINE_ELF}"
|
||||
--key "${signing_key}"
|
||||
--out-dir "${out_dir}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
|
||||
DEPENDS "${CORPUS_BASELINE_ELF}" "${POCA_PLUGINS_DIR}/negative/build_negative_corpus.py" "${signing_key}"
|
||||
COMMENT "[poca-corpus] handcrafted negative containers (gate-bypass by design)"
|
||||
VERBATIM)
|
||||
add_custom_target(poca_negative_corpus DEPENDS "${stamp}")
|
||||
endfunction()
|
||||
|
||||
# poca_iram_corpus(PROBE_ELF <elf> OBJDUMP <tool>)
|
||||
#
|
||||
# T7 IRAM negative corpus: packages the budget-mismatch container
|
||||
# iram_mismatch (hostile assemble_mpb path, manifest declares
|
||||
# section_size+16) from the gate-approved probe ELF. Also runs the
|
||||
# objdump-level IRAM contract check on the probe ELF (no l32r inside
|
||||
# .plugin_iram - a literal pool there is unreachable across the IRAM/PSRAM
|
||||
# window split). The positive iram_probe.mpb comes from poca_plugin.
|
||||
function(poca_iram_corpus)
|
||||
cmake_parse_arguments(CORPUS "" "PROBE_ELF;OBJDUMP" "" ${ARGN})
|
||||
if(NOT CORPUS_PROBE_ELF OR NOT CORPUS_OBJDUMP)
|
||||
message(FATAL_ERROR "poca_iram_corpus: PROBE_ELF and OBJDUMP are required")
|
||||
endif()
|
||||
|
||||
set(out_dir "${CMAKE_BINARY_DIR}/plugins")
|
||||
set(gen_dir "${out_dir}/generated")
|
||||
set(corpus_names iram_mismatch)
|
||||
set(corpus_outputs "")
|
||||
foreach(name IN LISTS corpus_names)
|
||||
list(APPEND corpus_outputs "${out_dir}/${name}.mpb" "${gen_dir}/poca_${name}_meta.h")
|
||||
endforeach()
|
||||
set(stamp "${out_dir}/iram_probe/corpus.stamp")
|
||||
|
||||
set(signing_key "${POCA_REPO_ROOT}/tools/frame_tools/testdata/keys/poc_a_test_signing_key.pem")
|
||||
if(Python_EXECUTABLE)
|
||||
set(corpus_python "${Python_EXECUTABLE}")
|
||||
else()
|
||||
set(corpus_python python3)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${stamp}"
|
||||
BYPRODUCTS ${corpus_outputs}
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${out_dir}/iram_probe"
|
||||
COMMAND "${corpus_python}" "${POCA_PLUGINS_DIR}/iram_probe/build_iram_corpus.py"
|
||||
--probe-elf "${CORPUS_PROBE_ELF}"
|
||||
--objdump "${CORPUS_OBJDUMP}"
|
||||
--key "${signing_key}"
|
||||
--out-dir "${out_dir}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
|
||||
DEPENDS "${CORPUS_PROBE_ELF}"
|
||||
"${POCA_PLUGINS_DIR}/iram_probe/build_iram_corpus.py" "${signing_key}"
|
||||
COMMENT "[iram-corpus] probe + budget-mismatch containers (T7)"
|
||||
VERBATIM)
|
||||
add_custom_target(poca_iram_corpus DEPENDS "${stamp}")
|
||||
endfunction()
|
||||
|
||||
# poca_maxmem_corpus(BASELINE_ELF <elf>)
|
||||
#
|
||||
# T8 admission negative: packages neg_maxmem, a signature-valid container
|
||||
# whose manifest declares max_memory_bytes=614400 (600 KiB > the 512 KiB hard
|
||||
# maximum of MEM-003). The builder refuses to build this via the positive
|
||||
# path (manifest cross-field validation), so the fixture is handcrafted with
|
||||
# the hostile assemble_mpb path; the on-device rejection must then come from
|
||||
# the poca admission check, before esp_elf_init and before any plugin byte
|
||||
# executes.
|
||||
function(poca_maxmem_corpus)
|
||||
cmake_parse_arguments(CORPUS "" "BASELINE_ELF" "" ${ARGN})
|
||||
if(NOT CORPUS_BASELINE_ELF)
|
||||
message(FATAL_ERROR "poca_maxmem_corpus: BASELINE_ELF is required")
|
||||
endif()
|
||||
|
||||
set(out_dir "${CMAKE_BINARY_DIR}/plugins")
|
||||
set(gen_dir "${out_dir}/generated")
|
||||
set(corpus_names neg_maxmem)
|
||||
set(corpus_outputs "")
|
||||
foreach(name IN LISTS corpus_names)
|
||||
list(APPEND corpus_outputs "${out_dir}/${name}.mpb" "${gen_dir}/poca_${name}_meta.h")
|
||||
endforeach()
|
||||
set(stamp "${out_dir}/coexist/corpus.stamp")
|
||||
|
||||
set(signing_key "${POCA_REPO_ROOT}/tools/frame_tools/testdata/keys/poc_a_test_signing_key.pem")
|
||||
if(NOT Python_EXECUTABLE)
|
||||
set(corpus_python python3)
|
||||
else()
|
||||
set(corpus_python "${Python_EXECUTABLE}")
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT "${stamp}"
|
||||
BYPRODUCTS ${corpus_outputs}
|
||||
COMMAND "${CMAKE_COMMAND}" -E make_directory "${out_dir}/coexist"
|
||||
COMMAND "${corpus_python}" "${POCA_PLUGINS_DIR}/coexist/build_maxmem_corpus.py"
|
||||
--baseline-elf "${CORPUS_BASELINE_ELF}"
|
||||
--key "${signing_key}"
|
||||
--out-dir "${out_dir}"
|
||||
COMMAND "${CMAKE_COMMAND}" -E touch "${stamp}"
|
||||
DEPENDS "${CORPUS_BASELINE_ELF}"
|
||||
"${POCA_PLUGINS_DIR}/coexist/build_maxmem_corpus.py" "${signing_key}"
|
||||
COMMENT "[poca-corpus] hostile 600KiB-declared admission container (T8)"
|
||||
VERBATIM)
|
||||
add_custom_target(poca_maxmem_corpus DEPENDS "${stamp}")
|
||||
endfunction()
|
||||
|
||||
# Generate the embedded TEST public key header (65-byte uncompressed point
|
||||
# 0x04||X||Y plus key_id) from the committed PEM. Runs at configure time with
|
||||
# any stdlib python; fails the configure when the derived key_id does not
|
||||
# match EXPECT_KEY_ID (guards against key material drift).
|
||||
function(poca_pubkey_header pem out_header expect_key_id)
|
||||
set(gen_py "${POCA_PLUGINS_DIR}/gen_pubkey_header.py")
|
||||
if(Python_EXECUTABLE)
|
||||
set(plugin_python "${Python_EXECUTABLE}")
|
||||
else()
|
||||
set(plugin_python python3)
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND "${plugin_python}" "${gen_py}" "${pem}" "${out_header}"
|
||||
--expect-key-id "${expect_key_id}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE stdout
|
||||
ERROR_VARIABLE stderr)
|
||||
if(NOT res EQUAL 0)
|
||||
message(FATAL_ERROR "poca_pubkey_header: ${gen_py} failed (${res}): ${stdout} ${stderr}")
|
||||
endif()
|
||||
string(STRIP "${stdout}" stdout)
|
||||
message(STATUS "[poca-plugin] pubkey ${stdout}")
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user