From c6db2a1fbeaf5c11ed09167b6dea8c32128e389b Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 03:00:20 +0100 Subject: [PATCH] Audit packaged ELF load segments against the Vinix kernel page size --- BOOTSTRAP.md | 4 ++ tests/archive-pages.py | 87 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/archive-pages.py diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 5225979..1952411 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -38,6 +38,10 @@ The worker resolved all 81 packages in `foundation/xlib-combined-01/repo` into s ## Running the shared worker +The released arm64 kernel uses 16 KiB pages. For every nonempty ELF load segment, the virtual address and file offset must have the same remainder modulo 16384. The x86_64 page size is 4096. Check a package before adding it to the build SDK with `python3 tests/archive-pages.py aarch64 "$archive"`. Add `--inventory` to survey older archives and record every affected executable or shared object. The released kernel must also execute the installed payload. + +The initial arm64 survey covered 22 distinct archive names. Thirteen contained an incompatible load segment, affecting 28 of 53 packaged executables and shared objects. BusyBox 1.38.0-4 and both initial musl releases were affected. The Linux UAPI and fortify headers contained no executable or shared object. Earlier arm64 installation and ownership receipts predate this kernel check. The worker stores the source archive hashes and segment offsets in `arm/abi16/previous-02`, receipt SHA-256 `676679a285a3ccd67bbd85ea2415fbc46e0e79b4f6bfc9bb5e9a12c310bd54f6`. The wrong-machine, historical BusyBox, header-only and x86_64 musl controls are in `arm/abi16/archive-controls-01`, receipt SHA-256 `cc8e171dc5febc3ec75a7a3c30a008c9e49bd7bbc8e9d7ace465c576dee762e1`. + The Ubuntu build worker runs one build or guest test at a time under its shared `compile.lock`. Builds may use **two compiler jobs** under the same 1 GiB memory limit. Set `MAKEFLAGS=-j2` and `CMAKE_BUILD_PARALLEL_LEVEL=2`, or pass `-j2` to Ninja or Meson. The systemd service runs as a dynamic user with `CPUQuota=200%`, `MemoryHigh=768M`, `MemoryMax=1G` and `MemorySwapMax=0`. Keep downloads, build directories, emulators and signing tools in private worker state. Store the cgroup's `memory.peak` and `memory.events` with each build and record any single-job retry. The operator laptop needs only source edits and SSH. ## Verified x86_64 bootstrap diff --git a/tests/archive-pages.py b/tests/archive-pages.py new file mode 100644 index 0000000..704b591 --- /dev/null +++ b/tests/archive-pages.py @@ -0,0 +1,87 @@ +"""Check packaged ELF load segments against the page size of the released Vinix kernel.""" +import argparse +import csv +import struct +import subprocess +import sys +import tarfile +from pathlib import Path + + +def check(stream, size, arch): + header = stream.read(64) + if not header.startswith(b"\x7fELF"): + return None + machine, page = (183, 16384) if arch == "aarch64" else (62, 4096) + if len(header) != 64 or header[4:7] != bytes((2, 1, 1)): + raise ValueError("invalid ELF64 little-endian header") + kind, target = struct.unpack_from(" size: + raise ValueError("invalid program header table") + remaining = offset - len(header) + while remaining: + chunk = stream.read(min(remaining, 65536)) + if not chunk: + raise ValueError("truncated data before the program headers") + remaining -= len(chunk) + loads = 0 + for index in range(count): + kind, _, off, addr, _, filesz, memsz, _ = struct.unpack(" memsz or off > size or filesz > size - off: + raise ValueError(f"invalid PT_LOAD {index}") + if memsz: + loads += 1 + if off % page != addr % page: + return f"PT_LOAD {index}, offset 0x{off:x}, vaddr 0x{addr:x}, page {page}" + if not loads: + raise ValueError("ELF lacks a nonempty PT_LOAD") + return "" + + +def audit(args): + writer = csv.writer(sys.stdout, delimiter="\t", lineterminator="\n") + writer.writerow(["archive", "member", "result", "detail"]) + incompatible = 0 + for path in args.archives: + total = failed = 0 + with subprocess.Popen(["zstd", "-qdc", "--", path], stdout=subprocess.PIPE) as proc: + with tarfile.open(fileobj=proc.stdout, mode="r|") as archive: + for member in archive: + if not member.isfile(): + continue + with archive.extractfile(member) as contents: + try: + reason = check(contents, member.size, args.arch) + except (ValueError, struct.error) as error: + raise ValueError(f"{path}:{member.name}: {error}") from error + if reason is None: + continue + total += 1 + failed += bool(reason) + writer.writerow([path.name, member.name, "incompatible" if reason else "compatible", reason]) + # Drain any padding beyond the final tar member before checking zstd. + while proc.stdout.read(65536): + pass + if proc.wait(): + raise ValueError(f"could not decompress {path}") + writer.writerow([path.name, "", "summary", f"{failed} incompatible of {total} executables and DSOs"]) + incompatible += failed + return int(bool(incompatible) and not args.inventory) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("arch", choices=("aarch64", "x86_64")) + parser.add_argument("archives", type=Path, nargs="+") + parser.add_argument("--inventory", action="store_true", help="record incompatible files without failing the survey") + sys.exit(audit(parser.parse_args())) -- 2.56.1