me

/

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

Audit packaged ELF load segments against the Vinix kernel page size

diviocity committed 5 days ago · c6db2a1fbeaf5c11ed09167b6dea8c32128e389b View patch
Unverified signature 2 files changed +91 -0
BOOTSTRAP.md +4 -0

@@ -38,6 +38,10 @@ The worker resolved all 81 packages in `foundation/xlib-combined-01/repo` into s

3838

3939## Running the shared worker

4040

41+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.

42+

43+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`.

44+

4145The 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.

4246

4347## Verified x86_64 bootstrap

tests/archive-pages.py new file +87 -0

@@ -0,0 +1,87 @@

1+"""Check packaged ELF load segments against the page size of the released Vinix kernel."""

2+import argparse

3+import csv

4+import struct

5+import subprocess

6+import sys

7+import tarfile

8+from pathlib import Path

9+

10+

11+def check(stream, size, arch):

12+ header = stream.read(64)

13+ if not header.startswith(b"\x7fELF"):

14+ return None

15+ machine, page = (183, 16384) if arch == "aarch64" else (62, 4096)

16+ if len(header) != 64 or header[4:7] != bytes((2, 1, 1)):

17+ raise ValueError("invalid ELF64 little-endian header")

18+ kind, target = struct.unpack_from("<HH", header, 16)

19+ if target != machine:

20+ raise ValueError(f"unexpected ELF machine {target}")

21+ if kind == 1:

22+ return None

23+ if kind not in (2, 3):

24+ raise ValueError(f"unexpected ELF type {kind}")

25+ offset, = struct.unpack_from("<Q", header, 32)

26+ stride, count = struct.unpack_from("<HH", header, 54)

27+ if stride != 56 or not count or offset < 64 or offset + stride * count > size:

28+ raise ValueError("invalid program header table")

29+ remaining = offset - len(header)

30+ while remaining:

31+ chunk = stream.read(min(remaining, 65536))

32+ if not chunk:

33+ raise ValueError("truncated data before the program headers")

34+ remaining -= len(chunk)

35+ loads = 0

36+ for index in range(count):

37+ kind, _, off, addr, _, filesz, memsz, _ = struct.unpack("<II6Q", stream.read(stride))

38+ if kind != 1:

39+ continue

40+ if filesz > memsz or off > size or filesz > size - off:

41+ raise ValueError(f"invalid PT_LOAD {index}")

42+ if memsz:

43+ loads += 1

44+ if off % page != addr % page:

45+ return f"PT_LOAD {index}, offset 0x{off:x}, vaddr 0x{addr:x}, page {page}"

46+ if not loads:

47+ raise ValueError("ELF lacks a nonempty PT_LOAD")

48+ return ""

49+

50+

51+def audit(args):

52+ writer = csv.writer(sys.stdout, delimiter="\t", lineterminator="\n")

53+ writer.writerow(["archive", "member", "result", "detail"])

54+ incompatible = 0

55+ for path in args.archives:

56+ total = failed = 0

57+ with subprocess.Popen(["zstd", "-qdc", "--", path], stdout=subprocess.PIPE) as proc:

58+ with tarfile.open(fileobj=proc.stdout, mode="r|") as archive:

59+ for member in archive:

60+ if not member.isfile():

61+ continue

62+ with archive.extractfile(member) as contents:

63+ try:

64+ reason = check(contents, member.size, args.arch)

65+ except (ValueError, struct.error) as error:

66+ raise ValueError(f"{path}:{member.name}: {error}") from error

67+ if reason is None:

68+ continue

69+ total += 1

70+ failed += bool(reason)

71+ writer.writerow([path.name, member.name, "incompatible" if reason else "compatible", reason])

72+ # Drain any padding beyond the final tar member before checking zstd.

73+ while proc.stdout.read(65536):

74+ pass

75+ if proc.wait():

76+ raise ValueError(f"could not decompress {path}")

77+ writer.writerow([path.name, "", "summary", f"{failed} incompatible of {total} executables and DSOs"])

78+ incompatible += failed

79+ return int(bool(incompatible) and not args.inventory)

80+

81+

82+if __name__ == "__main__":

83+ parser = argparse.ArgumentParser(description=__doc__)

84+ parser.add_argument("arch", choices=("aarch64", "x86_64"))

85+ parser.add_argument("archives", type=Path, nargs="+")

86+ parser.add_argument("--inventory", action="store_true", help="record incompatible files without failing the survey")

87+ sys.exit(audit(parser.parse_args()))