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,125 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Hostile-path packaging for the T6 C++ feature-rejection corpus.
|
||||
|
||||
The probe ELFs are built by poca_cxx_probe() and are NEVER gate-approved
|
||||
(the expected-failure runner proves check_plugin_elf.cmake rejects each
|
||||
one); packaging them here therefore mirrors the T5 hostile_signed pattern:
|
||||
the containers are structurally valid, signed with the TEST-only key and
|
||||
carry a genuine xtensa ELF payload, so mpb verification passes on device
|
||||
and the rejection must come from the loader layers (patch p1 relocation
|
||||
allowlist, patch p4 forbidden-section policy).
|
||||
|
||||
cxx_ctor v1 probe ELF as built (.ctors present)
|
||||
-> p4 must reject with -EINVAL pre-execute
|
||||
cxx_tls v3 probe ELF as built (.tdata/.tbss + R_XTENSA_TLSDESC_*)
|
||||
-> p4 (sections) must reject with -EINVAL pre-execute
|
||||
neg_tls_nosect v3 bytes with the .tdata/.tbss section names renamed
|
||||
(same-length ".xdata"/".xbss" overwrite inside .shstrtab)
|
||||
-> p4 finds nothing; p1 must reject the R_XTENSA_TLSDESC_*
|
||||
relocation types with -EINVAL. This row isolates the
|
||||
relocation-layer rejection from the section-layer one.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import struct
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[5]
|
||||
sys.path.insert(0, str(REPO_ROOT / "tools"))
|
||||
|
||||
from frame_tools.manifest_builder import ( # noqa: E402
|
||||
PAYLOAD_TYPE_ELF,
|
||||
Manifest,
|
||||
Payload,
|
||||
build_mpb,
|
||||
load_private_key,
|
||||
)
|
||||
|
||||
MAX_MEMORY_BYTES = 262144
|
||||
SHT_STRTAB = 3
|
||||
|
||||
|
||||
def shstrtab_span(elf: bytes) -> tuple[int, int]:
|
||||
(shoff,) = struct.unpack_from("<I", elf, 32)
|
||||
(shentsize,) = struct.unpack_from("<H", elf, 46)
|
||||
(shstrndx,) = struct.unpack_from("<H", elf, 50)
|
||||
shdr = struct.unpack_from("<10I", elf, shoff + shstrndx * shentsize)
|
||||
if shdr[1] != SHT_STRTAB:
|
||||
raise SystemExit("e_shstrndx does not name a SHT_STRTAB; cannot patch")
|
||||
return shdr[4], shdr[4] + shdr[5]
|
||||
|
||||
|
||||
def rename_section(elf: bytes, old: str, new: str) -> bytes:
|
||||
if len(old) != len(new):
|
||||
raise SystemExit(f"rename must be same-length: {old} -> {new}")
|
||||
start, end = shstrtab_span(elf)
|
||||
table = elf[start:end]
|
||||
needle = old.encode() + b"\x00"
|
||||
count = table.count(needle)
|
||||
if count != 1:
|
||||
raise SystemExit(f"expected exactly one '{old}' in .shstrtab, found {count}")
|
||||
buf = bytearray(elf)
|
||||
offset = start + table.index(needle)
|
||||
buf[offset : offset + len(new)] = new.encode()
|
||||
print(f" .shstrtab@0x{offset:04x}: '{old}' -> '{new}'")
|
||||
return bytes(buf)
|
||||
|
||||
|
||||
def package(out_dir: Path, name: str, elf: bytes, key) -> None:
|
||||
manifest = Manifest(name, "1.0.0")
|
||||
manifest.set("max_memory_bytes", MAX_MEMORY_BYTES)
|
||||
container = build_mpb(
|
||||
manifest,
|
||||
[Payload(kind=PAYLOAD_TYPE_ELF, data=elf)],
|
||||
signing_key=key,
|
||||
security_epoch=1,
|
||||
)
|
||||
(out_dir / f"{name}.mpb").write_bytes(container)
|
||||
digest = hashlib.sha256(container).hexdigest()
|
||||
upper = name.upper()
|
||||
header = (
|
||||
f"/* Generated by poc/apps/poc_a/plugins/cxx_probes/build_cxx_probes.py - do not edit. */\n"
|
||||
f"#define POCA_{upper}_MPB_SIZE {len(container)}u\n"
|
||||
f"#define POCA_{upper}_MPB_SHA256 \"{digest}\"\n"
|
||||
f"#define POCA_{upper}_NAME \"{name}\"\n"
|
||||
f"#define POCA_{upper}_VERSION \"1.0.0\"\n"
|
||||
f"#define POCA_{upper}_ENTRY \"frame_plugin_entry\"\n"
|
||||
)
|
||||
(out_dir / "generated" / f"poca_{name}_meta.h").write_text(header)
|
||||
elf_digest = hashlib.sha256(elf).hexdigest()
|
||||
print(f"[cxx-corpus] {name}.mpb size={len(container)} sha256={digest} "
|
||||
f"(elf sha256={elf_digest})")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--ctor-elf", required=True)
|
||||
parser.add_argument("--tls-elf", required=True)
|
||||
parser.add_argument("--key", required=True)
|
||||
parser.add_argument("--out-dir", required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
out_dir = Path(args.out_dir)
|
||||
(out_dir / "generated").mkdir(parents=True, exist_ok=True)
|
||||
key = load_private_key(Path(args.key))
|
||||
|
||||
ctor_elf = Path(args.ctor_elf).read_bytes()
|
||||
tls_elf = Path(args.tls_elf).read_bytes()
|
||||
|
||||
print("[cxx-corpus] cxx_ctor (probe ELF, .ctors present)")
|
||||
package(out_dir, "cxx_ctor", ctor_elf, key)
|
||||
print("[cxx-corpus] cxx_tls (probe ELF, .tdata/.tbss + TLSDESC relocs)")
|
||||
package(out_dir, "cxx_tls", tls_elf, key)
|
||||
print("[cxx-corpus] neg_tls_nosect (TLS sections renamed; p1-only row)")
|
||||
renamed = rename_section(tls_elf, ".tdata", ".xdata")
|
||||
renamed = rename_section(renamed, ".tbss", ".xbss")
|
||||
package(out_dir, "neg_tls_nosect", renamed, key)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,56 @@
|
||||
# Expected-failure wrapper around the positive-pipeline gates (task T6).
|
||||
#
|
||||
# Invoked as: cmake -D PROBE_NAME=<n> -D ELF=<file> -D READELF=<tool>
|
||||
# -D NM=<tool> -D EXPECT_ENTRY=<sym>
|
||||
# -D "NEEDLES=<substr;...>"
|
||||
# -P cxx_probes/check_probe_rejection.cmake
|
||||
#
|
||||
# Runs the REAL gate script (check_plugin_elf.cmake, the same one that
|
||||
# protects every positive poca_plugin build) against a C++ feature probe
|
||||
# ELF and asserts it FAILS with the expected reason. A probe that the
|
||||
# gates ACCEPT is a matrix failure (a forbidden feature slipped through),
|
||||
# so success of the inner gate is fatal here; the actual rejection text is
|
||||
# echoed verbatim so the evidence log carries the real gate output, not a
|
||||
# summary of it.
|
||||
|
||||
execute_process(
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "PLUGIN_NAME=${PROBE_NAME}"
|
||||
-D "ELF=${ELF}"
|
||||
-D "READELF=${READELF}"
|
||||
-D "NM=${NM}"
|
||||
-D "EXPECT_ENTRY=${EXPECT_ENTRY}"
|
||||
-D "EXPECT_UNDEFINED="
|
||||
-P "${CHECK_SCRIPT}"
|
||||
OUTPUT_VARIABLE gate_out
|
||||
RESULT_VARIABLE gate_res
|
||||
ERROR_VARIABLE gate_err)
|
||||
|
||||
if(gate_res EQUAL 0)
|
||||
message(FATAL_ERROR
|
||||
"[cxx-probe] ${PROBE_NAME}: NOT REJECTED by the pipeline gates - "
|
||||
"the gates accepted a forbidden C++ feature (gate output: ${gate_out})")
|
||||
endif()
|
||||
|
||||
set(gate_text "${gate_err}\n${gate_out}")
|
||||
set(missing "")
|
||||
foreach(needle IN LISTS NEEDLES)
|
||||
string(FIND "${gate_text}" "${needle}" needle_idx)
|
||||
if(needle_idx EQUAL -1)
|
||||
list(APPEND missing "${needle}")
|
||||
endif()
|
||||
endforeach()
|
||||
if(missing)
|
||||
message(FATAL_ERROR
|
||||
"[cxx-probe] ${PROBE_NAME}: gates failed (rc=${gate_res}) but the "
|
||||
"rejection reason is unexpected; missing [${missing}] in: ${gate_text}")
|
||||
endif()
|
||||
|
||||
message(STATUS "[cxx-probe] ${PROBE_NAME}: pipeline gates REJECTED the probe as required "
|
||||
"(exit ${gate_res}); verbatim gate output follows")
|
||||
string(REPLACE "\n" ";" gate_lines "${gate_err}")
|
||||
foreach(line IN LISTS gate_lines)
|
||||
if(NOT line STREQUAL "")
|
||||
message(STATUS "[cxx-probe] ${PROBE_NAME}: | ${line}")
|
||||
endif()
|
||||
endforeach()
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* C++ feature-rejection probe v4: exceptions (task T6 of poc-a-dynamic-elf,
|
||||
* appendix C 11.2/11.3).
|
||||
*
|
||||
* Compiled with -fexceptions (plus -funwind-tables, which this toolchain
|
||||
* requires to emit the landing-pad tables at -Os): a throw/catch pair in
|
||||
* activate() emits .gcc_except_table and .eh_frame unwind metadata and
|
||||
* leaves the C++ EH runtime imports (__cxa_*, _Unwind_Resume,
|
||||
* __gxx_personality_v0) undefined. The PoC-A loader has no unwinder; the
|
||||
* sections are the forbidden artifact (build gate 4), the imports would
|
||||
* additionally fail the closed-world import gate (gate 2) with -ENOSYS on
|
||||
* target.
|
||||
*/
|
||||
|
||||
#include "plugin_abi.h"
|
||||
|
||||
#define CXX_PROBE_ERR_ABI_MISMATCH (-7)
|
||||
#define CXX_PROBE_ERR_PACKAGE_INVALID (-18)
|
||||
|
||||
static int32_t exc_probe_prepare(void) { return 0; }
|
||||
|
||||
static int32_t exc_probe_activate(void) {
|
||||
const uint32_t crc = poca_crc32(POCA_BASELINE_PATTERN, POCA_BASELINE_PATTERN_SIZE);
|
||||
uint32_t code = 0u;
|
||||
try {
|
||||
throw 0xE77C37;
|
||||
} catch (int caught) {
|
||||
code = static_cast<uint32_t>(caught) & 0x00FFFFFFu;
|
||||
}
|
||||
if (code != 0x00E77C37u) {
|
||||
return CXX_PROBE_ERR_PACKAGE_INVALID;
|
||||
}
|
||||
return static_cast<int32_t>(POCA_PLUGIN_MAGIC ^ crc ^ code);
|
||||
}
|
||||
|
||||
static int32_t exc_probe_unload(void) { return 0; }
|
||||
|
||||
static const poca_plugin_table_t k_exc_table = {
|
||||
.struct_size = (uint32_t)sizeof(poca_plugin_table_t),
|
||||
.abi_major = POCA_PLUGIN_ABI_MAJOR,
|
||||
.abi_minor = POCA_PLUGIN_ABI_MINOR,
|
||||
.prepare = &exc_probe_prepare,
|
||||
.activate = &exc_probe_activate,
|
||||
.unload = &exc_probe_unload,
|
||||
.state_schema_id = 0u,
|
||||
.state_schema_version = 0u,
|
||||
.host_sentinel = nullptr,
|
||||
.host_add = nullptr,
|
||||
.iram_check = nullptr,
|
||||
.iram_write = nullptr,
|
||||
.data_word_ptr = nullptr,
|
||||
.data_word_read = nullptr,
|
||||
};
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const poca_plugin_table_t*
|
||||
frame_plugin_entry(void) {
|
||||
return &k_exc_table;
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* C++ feature-rejection probe v5: RTTI (task T6 of poc-a-dynamic-elf,
|
||||
* appendix C 11.2/11.3).
|
||||
*
|
||||
* Compiled with -frtti on top of the probe baseline (-fno-rtti): a
|
||||
* polymorphic typeid plus a downcast dynamic_cast emit local typeinfo
|
||||
* objects (relocated with allowlisted R_XTENSA_RELATIVE words) but leave
|
||||
* the C++ ABI runtime imports undefined: __dynamic_cast (libstdc++) and
|
||||
* the __cxxabiv1 class-type-info vtables. This xtensa toolchain emits no
|
||||
* dedicated RTTI section, so the closed-world import gate (gate 2) is the
|
||||
* build-side rejection layer for this variant; on target the imports would
|
||||
* fail with -ENOSYS before any plugin byte executes (stock loader
|
||||
* behavior, proven for import_neg in T5).
|
||||
*/
|
||||
|
||||
#include "plugin_abi.h"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
#define CXX_PROBE_ERR_ABI_MISMATCH (-7)
|
||||
|
||||
struct RttiBase {
|
||||
virtual ~RttiBase() {}
|
||||
};
|
||||
|
||||
struct RttiDerived : RttiBase {};
|
||||
|
||||
static RttiDerived g_rtti_obj;
|
||||
|
||||
static int32_t rtti_probe_prepare(void) { return 0; }
|
||||
|
||||
static int32_t rtti_probe_activate(void) {
|
||||
const uint32_t crc = poca_crc32(POCA_BASELINE_PATTERN, POCA_BASELINE_PATTERN_SIZE);
|
||||
const RttiBase* obj = &g_rtti_obj;
|
||||
const RttiDerived* down = dynamic_cast<const RttiDerived*>(obj);
|
||||
const uintptr_t info_addr = reinterpret_cast<uintptr_t>(&typeid(*obj));
|
||||
const uint32_t down_bit = (down != nullptr && info_addr != 0u) ? 0x37713900u : 0u;
|
||||
return static_cast<int32_t>(POCA_PLUGIN_MAGIC ^ crc ^ down_bit);
|
||||
}
|
||||
|
||||
static int32_t rtti_probe_unload(void) { return 0; }
|
||||
|
||||
static const poca_plugin_table_t k_rtti_table = {
|
||||
.struct_size = (uint32_t)sizeof(poca_plugin_table_t),
|
||||
.abi_major = POCA_PLUGIN_ABI_MAJOR,
|
||||
.abi_minor = POCA_PLUGIN_ABI_MINOR,
|
||||
.prepare = &rtti_probe_prepare,
|
||||
.activate = &rtti_probe_activate,
|
||||
.unload = &rtti_probe_unload,
|
||||
.state_schema_id = 0u,
|
||||
.state_schema_version = 0u,
|
||||
.host_sentinel = nullptr,
|
||||
.host_add = nullptr,
|
||||
.iram_check = nullptr,
|
||||
.iram_write = nullptr,
|
||||
.data_word_ptr = nullptr,
|
||||
.data_word_read = nullptr,
|
||||
};
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const poca_plugin_table_t*
|
||||
frame_plugin_entry(void) {
|
||||
return &k_rtti_table;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* C++ feature-rejection probe v1: static constructor (task T6 of
|
||||
* poc-a-dynamic-elf, appendix C 11.2/11.3).
|
||||
*
|
||||
* A file-scope object with a non-trivial constructor forces the toolchain to
|
||||
* emit a static-initialization section (this xtensa gcc emits ".ctors", the
|
||||
* pre-standard spelling of ".init_array"). The section is on the C++ feature
|
||||
* forbidden list: the PoC-A loader has no entry-point-model replacement for
|
||||
* running constructors, so admitting the image would silently skip them.
|
||||
*
|
||||
* This source is built by poca_cxx_probe() ONLY to prove that the pipeline
|
||||
* gates reject it; it is never whitelisted and (for the on-board row) only
|
||||
* its packaged ELF is offered to the loader, which must refuse it before any
|
||||
* plugin byte executes.
|
||||
*/
|
||||
|
||||
#include "plugin_abi.h"
|
||||
|
||||
#define CXX_PROBE_ERR_ABI_MISMATCH (-7)
|
||||
#define CXX_PROBE_ERR_PACKAGE_INVALID (-18)
|
||||
|
||||
static uint32_t g_ctor_sentinel = 0u;
|
||||
|
||||
class CtorProbe {
|
||||
public:
|
||||
CtorProbe() { g_ctor_sentinel = 0xC0DEC7C0u; }
|
||||
};
|
||||
|
||||
static CtorProbe g_ctor_probe;
|
||||
|
||||
static int32_t ctor_probe_prepare(void) {
|
||||
if (g_ctor_sentinel != 0xC0DEC7C0u) {
|
||||
/* Constructor never ran: exactly the silent misbehavior the feature
|
||||
* ban protects against. */
|
||||
return CXX_PROBE_ERR_PACKAGE_INVALID;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t ctor_probe_activate(void) {
|
||||
const uint32_t crc = poca_crc32(POCA_BASELINE_PATTERN, POCA_BASELINE_PATTERN_SIZE);
|
||||
return static_cast<int32_t>(POCA_PLUGIN_MAGIC ^ crc ^ g_ctor_sentinel);
|
||||
}
|
||||
|
||||
static int32_t ctor_probe_unload(void) { return 0; }
|
||||
|
||||
static const poca_plugin_table_t k_ctor_table = {
|
||||
.struct_size = (uint32_t)sizeof(poca_plugin_table_t),
|
||||
.abi_major = POCA_PLUGIN_ABI_MAJOR,
|
||||
.abi_minor = POCA_PLUGIN_ABI_MINOR,
|
||||
.prepare = &ctor_probe_prepare,
|
||||
.activate = &ctor_probe_activate,
|
||||
.unload = &ctor_probe_unload,
|
||||
.state_schema_id = 0u,
|
||||
.state_schema_version = 0u,
|
||||
.host_sentinel = nullptr,
|
||||
.host_add = nullptr,
|
||||
.iram_check = nullptr,
|
||||
.iram_write = nullptr,
|
||||
.data_word_ptr = nullptr,
|
||||
.data_word_read = nullptr,
|
||||
};
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const poca_plugin_table_t*
|
||||
frame_plugin_entry(void) {
|
||||
return &k_ctor_table;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* C++ feature-rejection probe v2: static destructor (task T6 of
|
||||
* poc-a-dynamic-elf, appendix C 11.2/11.3).
|
||||
*
|
||||
* A file-scope object with a non-trivial destructor plus an explicit
|
||||
* __attribute__((destructor)) hook force the toolchain to emit a static
|
||||
* finalization section (".dtors" on this xtensa gcc, i.e. ".fini_array").
|
||||
* The PoC-A unload path is the plugin's own unload() callback; a section
|
||||
* driven teardown register has no runner in the entry-point model, so the
|
||||
* artifact is forbidden.
|
||||
*/
|
||||
|
||||
#include "plugin_abi.h"
|
||||
|
||||
#define CXX_PROBE_ERR_ABI_MISMATCH (-7)
|
||||
|
||||
static uint32_t g_dtor_mark = 0xA11CE11Du;
|
||||
|
||||
class DtorProbe {
|
||||
public:
|
||||
~DtorProbe() { g_dtor_mark = 0xDEAD0002u; }
|
||||
};
|
||||
|
||||
static DtorProbe g_dtor_probe;
|
||||
|
||||
__attribute__((destructor)) static void dtor_hook(void) { g_dtor_mark ^= 0x00000001u; }
|
||||
|
||||
static int32_t dtor_probe_prepare(void) { return 0; }
|
||||
|
||||
static int32_t dtor_probe_activate(void) {
|
||||
const uint32_t crc = poca_crc32(POCA_BASELINE_PATTERN, POCA_BASELINE_PATTERN_SIZE);
|
||||
return static_cast<int32_t>(POCA_PLUGIN_MAGIC ^ crc ^ g_dtor_mark);
|
||||
}
|
||||
|
||||
static int32_t dtor_probe_unload(void) { return 0; }
|
||||
|
||||
static const poca_plugin_table_t k_dtor_table = {
|
||||
.struct_size = (uint32_t)sizeof(poca_plugin_table_t),
|
||||
.abi_major = POCA_PLUGIN_ABI_MAJOR,
|
||||
.abi_minor = POCA_PLUGIN_ABI_MINOR,
|
||||
.prepare = &dtor_probe_prepare,
|
||||
.activate = &dtor_probe_activate,
|
||||
.unload = &dtor_probe_unload,
|
||||
.state_schema_id = 0u,
|
||||
.state_schema_version = 0u,
|
||||
.host_sentinel = nullptr,
|
||||
.host_add = nullptr,
|
||||
.iram_check = nullptr,
|
||||
.iram_write = nullptr,
|
||||
.data_word_ptr = nullptr,
|
||||
.data_word_read = nullptr,
|
||||
};
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const poca_plugin_table_t*
|
||||
frame_plugin_entry(void) {
|
||||
return &k_dtor_table;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* C++ feature-rejection probe v3: dynamic TLS (task T6 of poc-a-dynamic-elf,
|
||||
* appendix C 11.2/11.3).
|
||||
*
|
||||
* Two __thread variables, written and read at runtime (a never-written
|
||||
* thread-local is constant-folded away by gcc and emits nothing, so the
|
||||
* runtime store is load-bearing for the probe). Under the pipeline link
|
||||
* flags this emits .tdata/.tbss sections plus R_XTENSA_TLSDESC_FN /
|
||||
* R_XTENSA_TLSDESC_ARG dynamic relocations in .rela.dyn:
|
||||
* - build gate 1 rejects the relocation types (out of the loader's
|
||||
* xtensa allowlist),
|
||||
* - build gate 4 rejects the TLS sections,
|
||||
* - on target, loader patch p4 rejects the sections pre-execute and
|
||||
* (with the sections renamed away, the neg_tls_nosect corpus row) patch
|
||||
* p1 rejects the relocation types with -EINVAL.
|
||||
*/
|
||||
|
||||
#include "plugin_abi.h"
|
||||
|
||||
#define CXX_PROBE_ERR_ABI_MISMATCH (-7)
|
||||
|
||||
static __thread uint32_t g_tls_slot = 0x71557003u;
|
||||
static __thread uint32_t g_tls_zero = 0u;
|
||||
|
||||
__attribute__((noinline)) static uint32_t tls_stage(uint32_t seed) {
|
||||
g_tls_slot = seed ^ 0x71557003u;
|
||||
g_tls_zero = seed + 1u;
|
||||
return 0u;
|
||||
}
|
||||
|
||||
static int32_t tls_probe_prepare(void) { return 0; }
|
||||
|
||||
static int32_t tls_probe_activate(void) {
|
||||
(void)tls_stage(0xC7557001u);
|
||||
const uint32_t crc = poca_crc32(POCA_BASELINE_PATTERN, POCA_BASELINE_PATTERN_SIZE);
|
||||
return static_cast<int32_t>(POCA_PLUGIN_MAGIC ^ crc ^ g_tls_slot ^ g_tls_zero);
|
||||
}
|
||||
|
||||
static int32_t tls_probe_unload(void) { return 0; }
|
||||
|
||||
static const poca_plugin_table_t k_tls_table = {
|
||||
.struct_size = (uint32_t)sizeof(poca_plugin_table_t),
|
||||
.abi_major = POCA_PLUGIN_ABI_MAJOR,
|
||||
.abi_minor = POCA_PLUGIN_ABI_MINOR,
|
||||
.prepare = &tls_probe_prepare,
|
||||
.activate = &tls_probe_activate,
|
||||
.unload = &tls_probe_unload,
|
||||
.state_schema_id = 0u,
|
||||
.state_schema_version = 0u,
|
||||
.host_sentinel = nullptr,
|
||||
.host_add = nullptr,
|
||||
.iram_check = nullptr,
|
||||
.iram_write = nullptr,
|
||||
.data_word_ptr = nullptr,
|
||||
.data_word_read = nullptr,
|
||||
};
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const poca_plugin_table_t*
|
||||
frame_plugin_entry(void) {
|
||||
return &k_tls_table;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* C++ feature-rejection probe v6: unwind tables (task T6 of poc-a-dynamic-elf,
|
||||
* appendix C 11.2/11.3).
|
||||
*
|
||||
* Compiled with -funwind-tables -fasynchronous-unwind-tables (and the C++
|
||||
* EH flags deliberately OFF): every function - including the noinline
|
||||
* marker below - gets an .eh_frame FDE. No exception code, no EH runtime
|
||||
* imports: the purest emitter of the forbidden unwind-metadata section,
|
||||
* which gate 4 rejects at build time and loader patch p4 rejects on
|
||||
* target before any plugin byte executes.
|
||||
*/
|
||||
|
||||
#include "plugin_abi.h"
|
||||
|
||||
#define CXX_PROBE_ERR_ABI_MISMATCH (-7)
|
||||
|
||||
__attribute__((noinline)) static uint32_t unwind_marker(uint32_t value) {
|
||||
return value ^ 0x0BADCAFEu;
|
||||
}
|
||||
|
||||
static int32_t unwind_probe_prepare(void) { return 0; }
|
||||
|
||||
static int32_t unwind_probe_activate(void) {
|
||||
const uint32_t crc = poca_crc32(POCA_BASELINE_PATTERN, POCA_BASELINE_PATTERN_SIZE);
|
||||
const uint32_t marked = unwind_marker(crc);
|
||||
if (marked != (crc ^ 0x0BADCAFEu)) {
|
||||
return CXX_PROBE_ERR_ABI_MISMATCH;
|
||||
}
|
||||
return static_cast<int32_t>(POCA_PLUGIN_MAGIC ^ marked);
|
||||
}
|
||||
|
||||
static int32_t unwind_probe_unload(void) { return 0; }
|
||||
|
||||
static const poca_plugin_table_t k_unwind_table = {
|
||||
.struct_size = (uint32_t)sizeof(poca_plugin_table_t),
|
||||
.abi_major = POCA_PLUGIN_ABI_MAJOR,
|
||||
.abi_minor = POCA_PLUGIN_ABI_MINOR,
|
||||
.prepare = &unwind_probe_prepare,
|
||||
.activate = &unwind_probe_activate,
|
||||
.unload = &unwind_probe_unload,
|
||||
.state_schema_id = 0u,
|
||||
.state_schema_version = 0u,
|
||||
.host_sentinel = nullptr,
|
||||
.host_add = nullptr,
|
||||
.iram_check = nullptr,
|
||||
.iram_write = nullptr,
|
||||
.data_word_ptr = nullptr,
|
||||
.data_word_read = nullptr,
|
||||
};
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) const poca_plugin_table_t*
|
||||
frame_plugin_entry(void) {
|
||||
return &k_unwind_table;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"max_memory_bytes": 262144
|
||||
}
|
||||
Reference in New Issue
Block a user