Enforce release musl floors and test executable relocations in signed roots
@@ -42,6 +42,10 @@ The released arm64 kernel uses 16 KiB pages. For every nonempty ELF load segment
4242
4343The 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`.
4444
45+The desktop metapackage requires musl 1.2.6-3 or later on arm64 and 1.2.6-2 or later on x86_64. A vpac metadata check on each architecture accepted the intended minimum and rejected the obsolete ARM loader version for arm64. See `foundation/release-musl-floor-01`, receipt SHA-256 `8ebf28b531b0db68fd393028c3205df6edb719d0675875b6f7a0442077a2621f`.
46+
47+Run `python3 tests/exec-linkage.py x86_64 "$client" "$auditor" --proot "$(command -v proot)"` on an x86_64 worker to exercise the installed loader against each dynamic executable in an audited root. For a Vinix guest, use `--fixture "$work/linkage.sh"` and pass that script to the boot harness. Packaged musl 1.2.6 applies relocations before returning from `--list`. It resolved all 109 dynamic executables in the signed 106-package x86_64 root. Renaming the exported `OPENSSL_init_ssl` symbol in an isolated copy of libssl caused the loader to reject `/usr/bin/openssl` with status 127. See `foundation/exec-linkage-01`, receipt SHA-256 `cb2fdec09f4b9e7c873ec82d672af576e9e0c26484f9496744588323a01ed3a0`.
48+
4549The 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.
4650
4751## Verified x86_64 bootstrap
@@ -0,0 +1,87 @@
1+"""Use the installed musl loader to relocate each dynamic executable in a signed root."""
2+import argparse
3+import os
4+from pathlib import Path
5+import shlex
6+import struct
7+import subprocess
8+
9+
10+def interpreter(path):
11+ with path.open("rb") as stream:
12+ header = stream.read(64)
13+ if header[:4] != b"\x7fELF":
14+ return None
15+ if len(header) != 64 or header[4:6] != bytes((2, 1)):
16+ raise ValueError(f"unexpected ELF header in {path}")
17+ if struct.unpack_from("<H", header, 16)[0] not in (2, 3):
18+ return None
19+ offset, = struct.unpack_from("<Q", header, 32)
20+ stride, count = struct.unpack_from("<HH", header, 54)
21+ if stride != 56 or offset + count * stride > path.stat().st_size:
22+ raise ValueError(f"invalid ELF program headers in {path}")
23+ stream.seek(offset)
24+ for _ in range(count):
25+ kind, _, position, _, _, length, _, _ = struct.unpack("<II6Q", stream.read(stride))
26+ if kind == 3:
27+ if length < 2 or length > 4096:
28+ raise ValueError(f"invalid ELF interpreter in {path}")
29+ stream.seek(position)
30+ raw = stream.read(length)
31+ if len(raw) != length or not raw.endswith(b"\0"):
32+ raise ValueError(f"truncated ELF interpreter in {path}")
33+ return os.fsdecode(raw[:-1])
34+ return None
35+
36+
37+def commands(arch, sdk):
38+ root = sdk / "root"
39+ expected = f"/lib/ld-musl-{arch}.so.1"
40+ for directory, _, files in os.walk(root):
41+ for name in sorted(files):
42+ path = Path(directory) / name
43+ if path.is_symlink() or not path.is_file():
44+ continue
45+ loader = interpreter(path)
46+ if loader is not None:
47+ if loader != expected:
48+ raise ValueError(f"unexpected interpreter {loader} in {path}")
49+ yield [loader, "--list", "/" + path.relative_to(root).as_posix()]
50+
51+
52+def main(args):
53+ subprocess.run([args.auditor, args.arch, args.client], check=True)
54+ entries = sorted(commands(args.arch, args.client))
55+ if not entries:
56+ raise ValueError("root has no dynamically linked executables")
57+ if args.fixture:
58+ with args.fixture.open("x") as output:
59+ output.write("#!/bin/sh\nset -eu\nexport LC_ALL=C\nunset LD_LIBRARY_PATH LD_PRELOAD\n"
60+ "trap '/sbin/poweroff -f' EXIT\n")
61+ for cmd in entries:
62+ output.write(shlex.join(cmd) + " >/dev/null\n")
63+ output.write(f"echo 'Relocated {len(entries)} Vinix executables'\n"
64+ "echo 'VPAC FIXTURE GUEST PASS'\n")
65+ if args.proot:
66+ for cmd in entries:
67+ result = subprocess.run([args.proot, "-r", args.client / "root", "-w", "/", *cmd],
68+ text=True, capture_output=True)
69+ if result.returncode:
70+ raise ValueError(f"{cmd[-1]}: musl exited {result.returncode}\n{result.stderr}")
71+ print(cmd[-1])
72+ print(f"Relocated {len(entries)} {args.arch} executables in the signed root")
73+
74+
75+if __name__ == "__main__":
76+ parser = argparse.ArgumentParser(description=__doc__)
77+ parser.add_argument("arch", choices=("x86_64", "aarch64"))
78+ for arg in ("client", "auditor"):
79+ parser.add_argument(arg, type=lambda p: Path(p).resolve())
80+ parser.add_argument("--fixture", type=Path, help="write a guest script for the Vinix boot harness")
81+ parser.add_argument("--proot", type=Path, help="also check a host-architecture root in unprivileged PRoot")
82+ options = parser.parse_args()
83+ if not (options.fixture or options.proot):
84+ parser.error("supply --fixture or --proot")
85+ if options.proot and options.arch != os.uname().machine:
86+ parser.error("use the Vinix guest fixture for a foreign architecture")
87+ main(options)
@@ -2,7 +2,8 @@
22; The Vinix image builder adds the kernel, compositor and native services.
33selected := get-environment-variable("VPAC_TARGET_ARCH")
44arch := if string?(selected) { selected } else if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" }
5-common := list("musl>=1.2.6-2", "busybox>=1.38.0-5", "musl-utils", "ssl-client", "netbase",
5+musl := if string=?("aarch64", arch) { "musl>=1.2.6-3" } else { "musl>=1.2.6-2" }
6+common := list(musl, "busybox>=1.38.0-5", "musl-utils", "ssl-client", "netbase",
67 "vinix-release", "vinix-filesystem>=0.1.0-2", "vinix-accounts", "vinix-keyring",
78 "ca-certificates", "curl", "git", "openssh-client", "vpac", "xbps",
89 "zsh", "vim", "build-base", "vinix-desktop-init")