me

/

vinix-ports Public
382 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

Run the packaged loader against original release executables

diviocity committed 5 days ago · 62c5793bffc76005750a4473ccf8ecb751feb8ed View patch
Unverified signature 2 files changed +68 -1
tests/FEED.md +2 -0

@@ -154,3 +154,5 @@ On both targets, the worker installed musl and the public key package, then asse

154154Changing the netbase archive after signing caused assembly to fail its signed index checksum check before exposing the output root. The rejection log in `foundation/offline-stage-rejection-01` has receipt manifest SHA-256 `e15be9b8ba76c5c115a622e7fa57997c1bcb9ca99a3319e18b3daf489ecc3c8d`.

155155

156156The installed-root auditor checks each nonempty ELF load segment against the released kernel page size, 4 KiB on x86_64 and 16 KiB on aarch64. It also checks required symbol-version namespaces against the actual resolved package-owned provider using GNU readelf and objdump. The 106-package x86_64 root and the corrected arm64 loader passed. An old arm64 BusyBox failed its segment congruence check. An x86_64 libcrypto with its original SONAME and a changed version tag failed the OpenSSL consumer check. See `foundation/load-and-versions-02`, receipt SHA-256 `fd32f6b69db215ff6b79ec1f58c8457cf7f514dd162fbde410d9f6882072b979`. Use `tests/exec-linkage.py` as well to exercise actual dynamic symbol resolution.

157+

158+To exercise the original release binaries against the installed libraries on a worker of the same architecture, run `python3 tests/exec-linkage.py "$arch" "$client" "$auditor" --proot "$proot" --release "$archive" "$sha256" "$report"`. The probe binds one original executable over its guest path and runs the installed musl loader with `--list`. A negative control changed a library import in the original input and verified that the installed loader diagnosed the changed SONAME. In the 129-package x86_64 root, 52 of 95 dynamic image executables relocated, 27 reported failures and 16 fixed-address executables needed direct execution. Twelve of 17 X11 sidecar executables relocated. See `foundation/release-binary-relocation-02`, receipt SHA-256 `8483666ef4294f1ac5d44c1eb637a8f5200be4e613e635d835ef4f86e7ffa37b`. Directly starting the release `cpp` and `cc1` in that root expanded `__SIZEOF_POINTER__` to 8. See `foundation/release-original-exec-02`, receipt SHA-256 `b9f1659e4669df9f3d4aeddea37fd9b85abc40f9d55045fff1fc7096f091a209`.

tests/exec-linkage.py +66 -1

@@ -1,10 +1,15 @@

11"""Use the installed musl loader to relocate each dynamic executable in a signed root."""

22import argparse

3+import csv

4+import hashlib

35import os

46from pathlib import Path

57import shlex

8+import shutil

69import struct

710import subprocess

11+import tarfile

12+import tempfile

813

914

1015def interpreter(path):

@@ -49,8 +54,64 @@ def commands(arch, sdk):

4954 yield [loader, "--list", "/" + path.relative_to(root).as_posix()]

5055

5156

57+def release_probe(args):

58+ archive, expected, report = args.release

59+ with Path(archive).open("rb") as source:

60+ if hashlib.file_digest(source, "sha256").hexdigest() != expected:

61+ raise ValueError("release archive checksum mismatch")

62+ root = args.client / "root"

63+ loader = f"/lib/ld-musl-{args.arch}.so.1"

64+ rows = []

65+ with tempfile.TemporaryDirectory() as folder, tarfile.open(archive, "r|gz") as members:

66+ program = Path(folder) / "program"

67+ program.touch(mode=0o755)

68+ for entry in members:

69+ if not entry.isfile():

70+ continue

71+ with members.extractfile(entry) as member:

72+ magic = member.read(4)

73+ if magic != b"\x7fELF":

74+ continue

75+ with program.open("wb") as out:

76+ out.write(magic)

77+ shutil.copyfileobj(member, out)

78+ interp = interpreter(program)

79+ if interp is None:

80+ continue

81+ path = Path(entry.name.removeprefix("./"))

82+ if path.is_absolute() or ".." in path.parts or ":" in str(path) or "!" in str(path):

83+ raise ValueError(f"invalid guest bind path: {path}")

84+ if interp != loader:

85+ rows.append((str(path), "other interpreter", interp))

86+ continue

87+ # Bind only the original program at its release path. Dependencies

88+ # and the interpreter come from the independently audited root.

89+ result = subprocess.run([args.proot, "-r", root, "-w", "/", "-b", f"{program}:/{path}!",

90+ loader, "--list", "/" + str(path)], capture_output=True, text=True)

91+ diagnostic = " | ".join(result.stderr.splitlines())

92+ status = "failed" if result.returncode else "relocated"

93+ with program.open("rb") as source:

94+ kind, = struct.unpack_from("<H", source.read(18), 16)

95+ if kind == 2 and result.returncode and "Not a valid dynamic program" in diagnostic:

96+ # The loader's explicit --list entry cannot map some fixed-address

97+ # executables that do start through the kernel's normal ELF entry.

98+ status = "requires direct execution"

99+ rows.append((str(path), status, diagnostic))

100+ if not rows:

101+ raise ValueError("release contained no executable with an interpreter")

102+ with Path(report).open("x") as output:

103+ table = csv.writer(output, delimiter="\t", lineterminator="\n")

104+ table.writerow(("release_path", "status", "diagnostic"))

105+ table.writerows(sorted(rows))

106+ passed = sum(status == "relocated" for _, status, _ in rows)

107+ print(f"Relocated {passed} of {len(rows)} original {args.arch} executables")

108+ return int(passed != len(rows))

109+

110+

52111def main(args):

53112 subprocess.run([args.auditor, args.arch, args.client], check=True)

113+ if args.release:

114+ return release_probe(args)

54115 entries = sorted(commands(args.arch, args.client))

55116 if not entries:

56117 raise ValueError("root has no dynamically linked executables")

@@ -79,9 +140,13 @@ if __name__ == "__main__":

79140 parser.add_argument(arg, type=lambda p: Path(p).resolve())

80141 parser.add_argument("--fixture", type=Path, help="write a guest script for the Vinix boot harness")

81142 parser.add_argument("--proot", type=Path, help="also check a host-architecture root in unprivileged PRoot")

143+ parser.add_argument("--release", nargs=3, metavar=("ARCHIVE", "SHA256", "REPORT"),

144+ help="bind each original release executable over its guest path and record relocation results")

82145 options = parser.parse_args()

83146 if not (options.fixture or options.proot):

84147 parser.error("supply --fixture or --proot")

85148 if options.proot and options.arch != os.uname().machine:

86149 parser.error("use the Vinix guest fixture for a foreign architecture")

87- main(options)

150+ if options.release and (not options.proot or options.fixture):

151+ parser.error("--release requires --proot and an independent report path")

152+ raise SystemExit(main(options))