me

/

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

Repair public compiler and X11 directories after a signed upgrade

diviocity committed 4 days ago · e9909e7354f9bbb17505a244f919ec5d8f0f9a1a View patch
Unverified signature 6 files changed +199 -3
ports/vinix-pkg/70-restore-public-paths.hook new file +9 -0

@@ -0,0 +1,9 @@

1+[Trigger]

2+Operation = Upgrade

3+Type = Package

4+Target = vinix-pkg

5+

6+[Action]

7+Description = Restoring public compiler and X11 directory access

8+When = PostTransaction

9+Exec = /usr/libexec/vinix-restore-public-paths

ports/vinix-pkg/PKGBUILD.vile +10 -3

@@ -1,17 +1,24 @@

11defpkgbuild(vinix-pkg,

22 #:pkgname, "vinix-pkg",

33 #:pkgver, "1.0.0",

4- #:pkgrel, 1,

4+ #:pkgrel, 2,

55 #:pkgdesc, "Vinix pkg command for the vpac package repository",

66 #:arch, [#:any],

77 #:url, "https://github.com/vlang/vinix",

88 #:license, "0BSD",

99 #:depends, ["busybox", "vpac>=1.0.0-2"],

10- #:source, ["pkg"],

11- #:sha256sums, ["35a291f69a5965bbbbcd4692eea6db4db746324760a46f8fcc8b78f5798858cf"],

10+ #:source, ["pkg", "70-restore-public-paths.hook", "restore-public-paths"],

11+ #:sha256sums, ["35a291f69a5965bbbbcd4692eea6db4db746324760a46f8fcc8b78f5798858cf",

12+ "317586b314942658a13d69fdfbb92688aa638e1d20c588cff7edbf05d497d573",

13+ "26a9292a251cc71578977a2971ea3f691b5a3ead25987ac59b892a4ec568694e"],

1214 #:check, fn() {

1315 run("sh", "-n", "pkg")

16+ run("sh", "-n", "restore-public-paths")

1417 },

1518 #:package, fn() {

1619 run("install", "-Dm755", "pkg", string-append(pkgdir(), "/usr/bin/pkg"))

20+ run("install", "-Dm644", "70-restore-public-paths.hook",

21+ string-append(pkgdir(), "/usr/share/libalpm/hooks/70-restore-public-paths.hook"))

22+ run("install", "-Dm755", "restore-public-paths",

23+ string-append(pkgdir(), "/usr/libexec/vinix-restore-public-paths"))

1724 })

ports/vinix-pkg/restore-public-paths new file +22 -0

@@ -0,0 +1,22 @@

1+#!/bin/sh

2+# SPDX-License-Identifier: 0BSD

3+set -eu

4+

5+case "$(/bin/busybox uname -m)" in

6+ x86_64) triplet=/usr/x86_64-linux-musl ;;

7+ aarch64) triplet=/usr/aarch64-linux-musl ;;

8+ *) exit 0 ;;

9+esac

10+

11+# These public directories were installed with the build worker's private umask.

12+for path in "$triplet" "$triplet/bin" "$triplet/lib" "$triplet/lib/ldscripts" \

13+ /usr/include/libiberty /usr/lib/bfd-plugins /usr/lib64 \

14+ /usr/include/xorg /usr/lib/cmake/FreeGLUT /etc/X11/xinit \

15+ /usr/lib/xorg/modules/drivers /usr/lib/xorg/modules/extensions /usr/lib/xorg/modules/input

16+do

17+ [ -d "$path" ] || continue

18+ [ "$(/bin/busybox readlink -f "$path")" = "$path" ] || continue

19+ if [ "$(/bin/busybox stat -c '%a' "$path")" = 700 ]; then

20+ /bin/busybox chmod 755 "$path"

21+ fi

22+done

tests/public-mode-upgrade.py new file +114 -0

@@ -0,0 +1,114 @@

1+"""Verify an in-place signed upgrade of the compiler and X11 permission fixes."""

2+

3+import argparse

4+import csv

5+import json

6+from pathlib import Path

7+import stat

8+import subprocess

9+import tempfile

10+

11+

12+PACKAGES = {"binutils", "freeglut", "gcc", "vinix-pkg", "xf86-video-fbdev", "xinit", "xorg-server"}

13+

14+

15+def installed(db):

16+ results = {}

17+ for desc in (db / "local").glob("*/desc"):

18+ fields = {}

19+ for field in desc.read_text().split("\n\n"):

20+ key, _, value = field.partition("\n")

21+ fields[key] = value.strip()

22+ name = fields["%NAME%"]

23+ if name in results or fields["%VALIDATION%"] != "pgp":

24+ raise ValueError(f"{desc}: expected a unique signature-validated package")

25+ results[name] = fields["%VERSION%"]

26+ return results

27+

28+

29+def versions(feed):

30+ with (feed / "packages.tsv").open() as stream:

31+ return {row["name"]: row["version"] for row in csv.DictReader(stream, delimiter="\t")}

32+

33+

34+def inaccessible(root):

35+ results = []

36+ for base in (root / "usr", root / "etc/X11"):

37+ for path in [base, *base.rglob("*")]:

38+ mode = path.lstat().st_mode

39+ if ((stat.S_ISDIR(mode) and not mode & stat.S_IXOTH)

40+ or (stat.S_ISREG(mode) and not mode & stat.S_IROTH)):

41+ results.append(path.relative_to(root).as_posix())

42+ return sorted(results)

43+

44+

45+def audit(args):

46+ initial = installed(args.client / "db")

47+ if len(initial) != 138:

48+ raise ValueError("expected the original signed desktop-plus-X11 root")

49+ planned = versions(args.feed)

50+ if not set(initial) <= planned.keys():

51+ raise ValueError("the updated feed omits installed packages")

52+ expected = {name: planned[name] for name in initial}

53+ if {name for name in initial if expected[name] != initial[name]} != PACKAGES:

54+ raise ValueError("expected the permission-fixed packages and the vinix-pkg migration")

55+

56+ args.output.mkdir()

57+ before = inaccessible(args.client / "root")

58+ if not before:

59+ raise ValueError("fixture does not contain the original restrictive modes")

60+ (args.output / "before.txt").write_text("\n".join(before) + "\n")

61+ with tempfile.TemporaryDirectory(prefix="vinix-mode-upgrade-", dir=args.scratch) as area:

62+ client = Path(area)

63+ for name in ("root", "db", "hooks"):

64+ subprocess.run(["cp", "-a", args.client / name, client / name], check=True)

65+ keyring = client / "keyring"

66+ subprocess.run(["cp", "-a", args.keyring, keyring], check=True)

67+ cache = client / "cache"

68+ cache.mkdir()

69+ config = client / "config.vile"

70+ url = (args.feed / args.arch).as_uri()

71+ config.write_text("\n".join((

72+ f"path-root = {json.dumps(str(client / 'root') + '/')}",

73+ f"path-db = {json.dumps(str(client / 'db') + '/')}",

74+ f"path-cache = [{json.dumps(str(cache) + '/')}]",

75+ f"path-gpg = {json.dumps(str(keyring) + '/')}",

76+ f"path-log = {json.dumps(str(client / 'vpac.log'))}",

77+ f"path-hook = [{json.dumps(str(client / 'hooks') + '/')}]",

78+ f"pkg-arch = {json.dumps(args.arch)}",

79+ 'network-siglevel = ["package", "database"]',

80+ 'network-user = ""',

81+ 'network-disable-sandbox = true',

82+ f'repositories = list(sync-repo("vinix", [{json.dumps(url)}]))',

83+ )) + "\n")

84+ transaction_log = args.output / "transaction.log"

85+ with transaction_log.open("x") as log:

86+ result = subprocess.run(["fakeroot", "--", "vpac", "--config", config, "u",

87+ "--sync", "--noconfirm"], stdout=log, stderr=subprocess.STDOUT)

88+ if (client / "vpac.log").is_file():

89+ (args.output / "vpac.log").write_bytes((client / "vpac.log").read_bytes())

90+ result.check_returncode()

91+ if any(line.startswith("error:") for line in transaction_log.read_text().splitlines()):

92+ raise ValueError(f"vpac reported an upgrade error in {transaction_log}")

93+ if installed(client / "db") != expected:

94+ raise ValueError("the installed versions do not match the signed upgrade")

95+ with (args.output / "installed-root.log").open("x") as log:

96+ subprocess.run([args.auditor, args.arch, client], check=True, stdout=log, stderr=subprocess.STDOUT)

97+ after = inaccessible(client / "root")

98+ (args.output / "after.txt").write_text("".join(path + "\n" for path in after))

99+ if after:

100+ raise ValueError(f"{len(after)} public paths are still restricted after the upgrade")

101+ if installed(args.client / "db") != initial or inaccessible(args.client / "root") != before:

102+ raise ValueError("the original client changed during the upgrade test")

103+ print(f"{args.arch}: upgraded {len(PACKAGES)} signed packages and restored {len(before)} public paths")

104+

105+

106+if __name__ == "__main__":

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

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

109+ for name in ("client", "feed", "keyring", "auditor", "scratch", "output"):

110+ parser.add_argument(name, type=lambda path: Path(path).resolve())

111+ try:

112+ audit(parser.parse_args())

113+ except (ValueError, OSError, subprocess.SubprocessError) as error:

114+ parser.exit(1, f"{error}\n")

tests/x11/README.md +4 -0

@@ -114,6 +114,10 @@ The refreshed test-signed feeds contain 152 packages per architecture, with only

114114

115115The 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`.

116116

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

118+

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

120+

117121Use 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.

118122

119123```sh

tests/x11/public-mode-upgrade.sh new file +40 -0

@@ -0,0 +1,40 @@

1+#!/bin/sh

2+set -eu

3+export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C

4+trap '/sbin/poweroff -f' EXIT

5+

6+test "$(uname -o)" = Vinix

7+test "$(id -u)" = 0

8+test "$(vpac o --quiet /usr/bin/pkg)" = vinix-pkg

9+test "$(stat -c '%a' /usr/include/libiberty)" = 700

10+

11+pkg upgrade >/tmp/public-mode-upgrade.log 2>&1 || {

12+ cat /tmp/public-mode-upgrade.log

13+ exit 1

14+}

15+cat /tmp/public-mode-upgrade.log

16+if grep -E '^error:|failed to run .*hook|scriptlet failed' /tmp/public-mode-upgrade.log; then

17+ exit 1

18+fi

19+

20+while IFS=' ' read -r name version; do

21+ test -s "/var/lib/vpac/local/$name-$version/desc"

22+ vpac q -F validation "local/$name" |

23+ grep -Eq '^validation[[:space:]]+signature$'

24+done </usr/share/vinix-mode-upgrade/versions

25+

26+while IFS= read -r path; do

27+ test -d "$path"

28+ test "$(stat -c '%a' "$path")" = 755

29+done </usr/share/vinix-mode-upgrade/paths

30+

31+/bin/su -s /bin/sh -c 'test -r /usr/lib/bfd-plugins/liblto_plugin.so &&

32+ test -r /usr/include/libiberty/libiberty.h &&

33+ test -r /usr/lib/cmake/FreeGLUT/FreeGLUTConfig.cmake &&

34+ test -r /usr/lib/xorg/modules/input/inputtest_drv.so &&

35+ test -r /usr/lib/xorg/modules/extensions/libglx.so &&

36+ test -r /usr/lib/xorg/modules/drivers/fbdev_drv.so &&

37+ test -r /etc/X11/xinit/xinitrc' nobody

38+

39+echo 'Vinix upgraded the signed compiler and X11 packages and restored public access'

40+echo 'VPAC FIXTURE GUEST PASS'