From e9909e7354f9bbb17505a244f919ec5d8f0f9a1a Mon Sep 17 00:00:00 2001 From: diviocity Date: Tue, 1 Dec 2026 04:26:41 +0100 Subject: [PATCH] Repair public compiler and X11 directories after a signed upgrade --- ports/vinix-pkg/70-restore-public-paths.hook | 9 ++ ports/vinix-pkg/PKGBUILD.vile | 13 ++- ports/vinix-pkg/restore-public-paths | 22 ++++ tests/public-mode-upgrade.py | 114 +++++++++++++++++++ tests/x11/README.md | 4 + tests/x11/public-mode-upgrade.sh | 40 +++++++ 6 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 ports/vinix-pkg/70-restore-public-paths.hook create mode 100644 ports/vinix-pkg/restore-public-paths create mode 100644 tests/public-mode-upgrade.py create mode 100644 tests/x11/public-mode-upgrade.sh diff --git a/ports/vinix-pkg/70-restore-public-paths.hook b/ports/vinix-pkg/70-restore-public-paths.hook new file mode 100644 index 0000000..2f32c41 --- /dev/null +++ b/ports/vinix-pkg/70-restore-public-paths.hook @@ -0,0 +1,9 @@ +[Trigger] +Operation = Upgrade +Type = Package +Target = vinix-pkg + +[Action] +Description = Restoring public compiler and X11 directory access +When = PostTransaction +Exec = /usr/libexec/vinix-restore-public-paths diff --git a/ports/vinix-pkg/PKGBUILD.vile b/ports/vinix-pkg/PKGBUILD.vile index 4e51295..69c0f0e 100644 --- a/ports/vinix-pkg/PKGBUILD.vile +++ b/ports/vinix-pkg/PKGBUILD.vile @@ -1,17 +1,24 @@ defpkgbuild(vinix-pkg, #:pkgname, "vinix-pkg", #:pkgver, "1.0.0", - #:pkgrel, 1, + #:pkgrel, 2, #:pkgdesc, "Vinix pkg command for the vpac package repository", #:arch, [#:any], #:url, "https://github.com/vlang/vinix", #:license, "0BSD", #:depends, ["busybox", "vpac>=1.0.0-2"], - #:source, ["pkg"], - #:sha256sums, ["35a291f69a5965bbbbcd4692eea6db4db746324760a46f8fcc8b78f5798858cf"], + #:source, ["pkg", "70-restore-public-paths.hook", "restore-public-paths"], + #:sha256sums, ["35a291f69a5965bbbbcd4692eea6db4db746324760a46f8fcc8b78f5798858cf", + "317586b314942658a13d69fdfbb92688aa638e1d20c588cff7edbf05d497d573", + "26a9292a251cc71578977a2971ea3f691b5a3ead25987ac59b892a4ec568694e"], #:check, fn() { run("sh", "-n", "pkg") + run("sh", "-n", "restore-public-paths") }, #:package, fn() { run("install", "-Dm755", "pkg", string-append(pkgdir(), "/usr/bin/pkg")) + run("install", "-Dm644", "70-restore-public-paths.hook", + string-append(pkgdir(), "/usr/share/libalpm/hooks/70-restore-public-paths.hook")) + run("install", "-Dm755", "restore-public-paths", + string-append(pkgdir(), "/usr/libexec/vinix-restore-public-paths")) }) diff --git a/ports/vinix-pkg/restore-public-paths b/ports/vinix-pkg/restore-public-paths new file mode 100644 index 0000000..49624d4 --- /dev/null +++ b/ports/vinix-pkg/restore-public-paths @@ -0,0 +1,22 @@ +#!/bin/sh +# SPDX-License-Identifier: 0BSD +set -eu + +case "$(/bin/busybox uname -m)" in + x86_64) triplet=/usr/x86_64-linux-musl ;; + aarch64) triplet=/usr/aarch64-linux-musl ;; + *) exit 0 ;; +esac + +# These public directories were installed with the build worker's private umask. +for path in "$triplet" "$triplet/bin" "$triplet/lib" "$triplet/lib/ldscripts" \ + /usr/include/libiberty /usr/lib/bfd-plugins /usr/lib64 \ + /usr/include/xorg /usr/lib/cmake/FreeGLUT /etc/X11/xinit \ + /usr/lib/xorg/modules/drivers /usr/lib/xorg/modules/extensions /usr/lib/xorg/modules/input +do + [ -d "$path" ] || continue + [ "$(/bin/busybox readlink -f "$path")" = "$path" ] || continue + if [ "$(/bin/busybox stat -c '%a' "$path")" = 700 ]; then + /bin/busybox chmod 755 "$path" + fi +done diff --git a/tests/public-mode-upgrade.py b/tests/public-mode-upgrade.py new file mode 100644 index 0000000..eb514a1 --- /dev/null +++ b/tests/public-mode-upgrade.py @@ -0,0 +1,114 @@ +"""Verify an in-place signed upgrade of the compiler and X11 permission fixes.""" + +import argparse +import csv +import json +from pathlib import Path +import stat +import subprocess +import tempfile + + +PACKAGES = {"binutils", "freeglut", "gcc", "vinix-pkg", "xf86-video-fbdev", "xinit", "xorg-server"} + + +def installed(db): + results = {} + for desc in (db / "local").glob("*/desc"): + fields = {} + for field in desc.read_text().split("\n\n"): + key, _, value = field.partition("\n") + fields[key] = value.strip() + name = fields["%NAME%"] + if name in results or fields["%VALIDATION%"] != "pgp": + raise ValueError(f"{desc}: expected a unique signature-validated package") + results[name] = fields["%VERSION%"] + return results + + +def versions(feed): + with (feed / "packages.tsv").open() as stream: + return {row["name"]: row["version"] for row in csv.DictReader(stream, delimiter="\t")} + + +def inaccessible(root): + results = [] + for base in (root / "usr", root / "etc/X11"): + for path in [base, *base.rglob("*")]: + mode = path.lstat().st_mode + if ((stat.S_ISDIR(mode) and not mode & stat.S_IXOTH) + or (stat.S_ISREG(mode) and not mode & stat.S_IROTH)): + results.append(path.relative_to(root).as_posix()) + return sorted(results) + + +def audit(args): + initial = installed(args.client / "db") + if len(initial) != 138: + raise ValueError("expected the original signed desktop-plus-X11 root") + planned = versions(args.feed) + if not set(initial) <= planned.keys(): + raise ValueError("the updated feed omits installed packages") + expected = {name: planned[name] for name in initial} + if {name for name in initial if expected[name] != initial[name]} != PACKAGES: + raise ValueError("expected the permission-fixed packages and the vinix-pkg migration") + + args.output.mkdir() + before = inaccessible(args.client / "root") + if not before: + raise ValueError("fixture does not contain the original restrictive modes") + (args.output / "before.txt").write_text("\n".join(before) + "\n") + with tempfile.TemporaryDirectory(prefix="vinix-mode-upgrade-", dir=args.scratch) as area: + client = Path(area) + for name in ("root", "db", "hooks"): + subprocess.run(["cp", "-a", args.client / name, client / name], check=True) + keyring = client / "keyring" + subprocess.run(["cp", "-a", args.keyring, keyring], check=True) + cache = client / "cache" + cache.mkdir() + config = client / "config.vile" + url = (args.feed / args.arch).as_uri() + config.write_text("\n".join(( + f"path-root = {json.dumps(str(client / 'root') + '/')}", + f"path-db = {json.dumps(str(client / 'db') + '/')}", + f"path-cache = [{json.dumps(str(cache) + '/')}]", + f"path-gpg = {json.dumps(str(keyring) + '/')}", + f"path-log = {json.dumps(str(client / 'vpac.log'))}", + f"path-hook = [{json.dumps(str(client / 'hooks') + '/')}]", + f"pkg-arch = {json.dumps(args.arch)}", + 'network-siglevel = ["package", "database"]', + 'network-user = ""', + 'network-disable-sandbox = true', + f'repositories = list(sync-repo("vinix", [{json.dumps(url)}]))', + )) + "\n") + transaction_log = args.output / "transaction.log" + with transaction_log.open("x") as log: + result = subprocess.run(["fakeroot", "--", "vpac", "--config", config, "u", + "--sync", "--noconfirm"], stdout=log, stderr=subprocess.STDOUT) + if (client / "vpac.log").is_file(): + (args.output / "vpac.log").write_bytes((client / "vpac.log").read_bytes()) + result.check_returncode() + if any(line.startswith("error:") for line in transaction_log.read_text().splitlines()): + raise ValueError(f"vpac reported an upgrade error in {transaction_log}") + if installed(client / "db") != expected: + raise ValueError("the installed versions do not match the signed upgrade") + with (args.output / "installed-root.log").open("x") as log: + subprocess.run([args.auditor, args.arch, client], check=True, stdout=log, stderr=subprocess.STDOUT) + after = inaccessible(client / "root") + (args.output / "after.txt").write_text("".join(path + "\n" for path in after)) + if after: + raise ValueError(f"{len(after)} public paths are still restricted after the upgrade") + if installed(args.client / "db") != initial or inaccessible(args.client / "root") != before: + raise ValueError("the original client changed during the upgrade test") + print(f"{args.arch}: upgraded {len(PACKAGES)} signed packages and restored {len(before)} public paths") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("arch", choices=("x86_64", "aarch64")) + for name in ("client", "feed", "keyring", "auditor", "scratch", "output"): + parser.add_argument(name, type=lambda path: Path(path).resolve()) + try: + audit(parser.parse_args()) + except (ValueError, OSError, subprocess.SubprocessError) as error: + parser.exit(1, f"{error}\n") diff --git a/tests/x11/README.md b/tests/x11/README.md index 16886ca..ccd03f9 100644 --- a/tests/x11/README.md +++ b/tests/x11/README.md @@ -114,6 +114,10 @@ The refreshed test-signed feeds contain 152 packages per architecture, with only The worker reclaimed about 990 MiB of download cache after matching every archive to its signed feed digest. The per-architecture reference tables retain the original cache modes, timestamps and archive paths. See `foundation/release-public-mode-root-cache-reuse-02`, receipt SHA-256 `ab5cf4b30a4784605aafda6010ecdfe78234922477b54aae50dcfd35c3418ce9`. +An in-place update from the first test feed installed all six signed packages. It fixed the compiler file modes and retained 11 restrictive directories on x86_64 and seven on AArch64. The `vinix-pkg` upgrade hook restores access to the affected public directories when they still have mode 0700. See `foundation/release-public-mode-upgrade-01`, receipt SHA-256 `9342f3a232a4b73d38686d7caeb4f0db0e1a8e9817f46b8a4f4e7e63eeaa937c`. + +The refreshed feed adds `vinix-pkg` 1.0.0-2 on both architectures. On x86_64, `tests/public-mode-upgrade.py` installed the seven signed updates onto a disposable copy of the original 138-package desktop-plus-X11 client. libalpm ran the hook, and the audit reported zero inaccessible paths in `/usr` and `/etc/X11`, down from 138. See `foundation/release-mode-migration-feed-01` and `foundation/release-mode-migration-host-01`, receipt SHA-256 `c8f6aa4041a25457f6fe433204df66c5c5adc0904599c7a5ed62ae15d62ffd2a` and `da93252dbc9f1ecfd8ee587bb5fa9ba3fee77827c1f3fe819743c34d94423a45`. + Use the same signed feed for the downloadable X11 sidecar. Cold-install `vinix-release-desktop` into one client. Into a second client, cold-install both `vinix-release-desktop` and `vinix-release-x11` with the target font hooks enabled. ```sh diff --git a/tests/x11/public-mode-upgrade.sh b/tests/x11/public-mode-upgrade.sh new file mode 100644 index 0000000..0454e6c --- /dev/null +++ b/tests/x11/public-mode-upgrade.sh @@ -0,0 +1,40 @@ +#!/bin/sh +set -eu +export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C +trap '/sbin/poweroff -f' EXIT + +test "$(uname -o)" = Vinix +test "$(id -u)" = 0 +test "$(vpac o --quiet /usr/bin/pkg)" = vinix-pkg +test "$(stat -c '%a' /usr/include/libiberty)" = 700 + +pkg upgrade >/tmp/public-mode-upgrade.log 2>&1 || { + cat /tmp/public-mode-upgrade.log + exit 1 +} +cat /tmp/public-mode-upgrade.log +if grep -E '^error:|failed to run .*hook|scriptlet failed' /tmp/public-mode-upgrade.log; then + exit 1 +fi + +while IFS=' ' read -r name version; do + test -s "/var/lib/vpac/local/$name-$version/desc" + vpac q -F validation "local/$name" | + grep -Eq '^validation[[:space:]]+signature$' +done