Build verified engine payload through read-only linker section
This commit is contained in:
@@ -146,9 +146,18 @@ jobs:
|
||||
rustup target add --toolchain 1.99.0 x86_64-unknown-linux-musl
|
||||
- name: Assemble actual combined executable and runtime image
|
||||
run: |
|
||||
# Keep resource evidence even if the hosted runner terminates this job.
|
||||
(while sleep 20; do
|
||||
date -u
|
||||
free -m
|
||||
df -m "$RUNNER_TEMP"
|
||||
test ! -r /sys/fs/cgroup/memory.events || cat /sys/fs/cgroup/memory.events
|
||||
done) &
|
||||
resource_sampler=$!
|
||||
trap 'kill "$resource_sampler" 2>/dev/null || true; wait "$resource_sampler" 2>/dev/null || true' EXIT
|
||||
engine="$STRATA_BUILD_DIR/strata"
|
||||
package="$RUNNER_TEMP/strata-hosted-cuda-package"
|
||||
python3 scripts/build-linux-package.py --engine "$engine" \
|
||||
/usr/bin/time -v python3 scripts/build-linux-package.py --engine "$engine" \
|
||||
--sha256 "$(sha256sum "$engine" | cut -d ' ' -f 1)" --revision "$GITHUB_SHA" \
|
||||
--cargo-target-dir "$RUNNER_TEMP/strata-hosted-package-build" --output "$package"
|
||||
python3 scripts/build-runtime-image.py --package "$package" \
|
||||
|
||||
+35
-1
@@ -71,10 +71,44 @@ fn embed_engine() -> Result<(), Box<dyn std::error::Error>> {
|
||||
)?;
|
||||
(digest.to_ascii_lowercase(), revision.to_ascii_lowercase())
|
||||
};
|
||||
let size = fs::metadata(&payload_path)?.len();
|
||||
let declaration = if size == 0 {
|
||||
"pub const BYTES: &[u8] = &[];\n".to_owned()
|
||||
} else {
|
||||
// Keep large verified payloads out of Rust constant evaluation/LLVM IR.
|
||||
// The target assembler copies the bytes into an immutable ELF section.
|
||||
let path = payload_path.to_str().ok_or("payload path must be UTF-8")?;
|
||||
if path.contains(['\n', '\r']) {
|
||||
return Err("payload path cannot contain newlines".into());
|
||||
}
|
||||
let path = path.replace('\\', "\\\\").replace('"', "\\\"");
|
||||
let assembly = output.join("embedded-engine.S");
|
||||
fs::write(
|
||||
&assembly,
|
||||
format!(
|
||||
".section .rodata.strata_engine,\"a\"\n\
|
||||
.balign 16\n\
|
||||
.global strata_embedded_engine_bytes\n\
|
||||
.hidden strata_embedded_engine_bytes\n\
|
||||
strata_embedded_engine_bytes:\n\
|
||||
.incbin \"{path}\"\n\
|
||||
.size strata_embedded_engine_bytes, .-strata_embedded_engine_bytes\n\
|
||||
.section .note.GNU-stack,\"\"\n"
|
||||
),
|
||||
)?;
|
||||
cc::Build::new()
|
||||
.file(assembly)
|
||||
.compile("strata_embedded_payload");
|
||||
format!(
|
||||
"unsafe extern \"C\" {{ static strata_embedded_engine_bytes: [u8; {size}]; }}\n\
|
||||
// SAFETY: build.rs emits exactly {size} verified bytes in read-only storage.\n\
|
||||
pub static BYTES: &[u8] = unsafe {{ &strata_embedded_engine_bytes }};\n"
|
||||
)
|
||||
};
|
||||
fs::write(
|
||||
output.join("embedded-engine.rs"),
|
||||
format!(
|
||||
"pub const BYTES: &[u8] = include_bytes!(concat!(env!(\"OUT_DIR\"), \"/embedded-engine.bin\"));\n\
|
||||
"{declaration}\
|
||||
pub const SHA256: &str = {digest:?};\n\
|
||||
pub const SOURCE_REVISION: &str = {revision:?};\n"
|
||||
),
|
||||
|
||||
@@ -813,6 +813,16 @@ Actual host/compiler versions and initial resources are recorded. Toolkit bytes
|
||||
are pinned; hosted OS/compiler patch updates mean byte-identical rebuilds are
|
||||
not asserted.
|
||||
|
||||
Nonempty Linux engine payloads use a target-assembler `.incbin` in a read-only
|
||||
ELF section after the existing bounded SHA/ELF verification. Rust references
|
||||
that immutable section through an exact-length external static; it does not
|
||||
parse a 600+ MB engine as a Rust byte-array constant. Empty/nonembedded builds
|
||||
remain unchanged. The hosted packaging step records memory/disk counters and
|
||||
`time -v` resource usage. Two initial hosted attempts received runner shutdown
|
||||
signals during the previous Rust embedding path; those logs do not establish
|
||||
an OOM diagnosis. Exact memfd bytes, seals, restart and external-worker output
|
||||
equality remain mandatory checks for this build-path change.
|
||||
|
||||
Existing static-engine, combined-package and OCI builders supply the actual
|
||||
compile/link, dependency/ABI, embedded identity and GPU-hidden help gates.
|
||||
The private `strata-next-hosted-cuda-preview` artifact retains package checksums,
|
||||
|
||||
Reference in New Issue
Block a user