263 lines
11 KiB
Bash
263 lines
11 KiB
Bash
#!/bin/sh
|
|||
|
|
# Comprehensive Geminux verification suite (repo policy, zero-Rust ELF scan,
|
||
|
|
# Alpine Edge upgrade simulation, aarch64 binaries, image integrity, unit tests).
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||
|
|
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
|
||
|
|
IMAGES_DIR="$BASE_DIR/images"
|
||
|
|
|
||
|
|
if [ ! -d "$ROOTFS_DIR/lib/apk/db" ]; then
|
||
|
|
echo "FAIL: rootfs not bootstrapped at $ROOTFS_DIR" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "[1/8] Checking APK repositories (pure Alpine Edge + @geminux, zero postmarketOS)..."
|
||
|
|
grep -q '^@geminux /var/lib/geminux/apk-repo$' "$ROOTFS_DIR/etc/apk/repositories"
|
||
|
|
grep -q 'alpine/edge/main' "$ROOTFS_DIR/etc/apk/repositories"
|
||
|
|
grep -q 'alpine/edge/community' "$ROOTFS_DIR/etc/apk/repositories"
|
||
|
|
grep -q 'alpine/edge/testing' "$ROOTFS_DIR/etc/apk/repositories"
|
||
|
|
if grep -qi 'postmarketos' "$ROOTFS_DIR/etc/apk/repositories"; then
|
||
|
|
echo "FAIL: unexpected postmarketos repository in target rootfs" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
echo "OK"
|
||
|
|
|
||
|
|
echo "[2/8] Checking excluded Wayland/Rust/compiler/upstream packages..."
|
||
|
|
for bad_pkg in sway wayfire weston phosh cage xwayland grim slurp wofi \
|
||
|
|
sudo-rs postmarketos-base-sudo-rs rust cargo librsvg libglycin rav1e \
|
||
|
|
rav1e-libs libdovi mesa-rusticl gdk-pixbuf adwaita-icon-theme imv-x11 \
|
||
|
|
gst-libav gst-plugins-bad gst-plugins-good libnotify \
|
||
|
|
linux-edge linux-lts xorg-server xf86-input-libinput xf86-video-fbdev \
|
||
|
|
gcc g++ musl-dev make; do
|
||
|
|
if grep -Fxq "P:$bad_pkg" "$ROOTFS_DIR/lib/apk/db/installed"; then
|
||
|
|
echo "FAIL: forbidden package '$bad_pkg' is installed in rootfs" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
echo "OK (zero forbidden packages)"
|
||
|
|
|
||
|
|
echo "[3/8] Running full binary ELF Rust scan across $ROOTFS_DIR..."
|
||
|
|
python3 - "$ROOTFS_DIR" <<'PYEOF'
|
||
|
|
import os
|
||
|
|
import re
|
||
|
|
import subprocess
|
||
|
|
import sys
|
||
|
|
|
||
|
|
root = sys.argv[1]
|
||
|
|
raw_markers = re.compile(
|
||
|
|
rb"(core::panicking|rustc_version|libstd-[0-9a-f]{8}|librsvg|libglycin|rav1e|libdovi)"
|
||
|
|
)
|
||
|
|
sym_markers = re.compile(
|
||
|
|
r"(rust_eh_personality|rust_begin_unwind|_ZN4core9panicking|_ZN3std9panicking|libstd-[0-9a-f]{8}|librsvg|libglycin|rav1e|libdovi)"
|
||
|
|
)
|
||
|
|
elfs = []
|
||
|
|
hits = []
|
||
|
|
for parent, _, names in os.walk(root):
|
||
|
|
for name in names:
|
||
|
|
p = os.path.join(parent, name)
|
||
|
|
if os.path.islink(p) or not os.path.isfile(p):
|
||
|
|
continue
|
||
|
|
try:
|
||
|
|
with open(p, "rb") as f:
|
||
|
|
if f.read(4) != b"\x7fELF":
|
||
|
|
continue
|
||
|
|
f.seek(0)
|
||
|
|
data = f.read()
|
||
|
|
except OSError:
|
||
|
|
continue
|
||
|
|
elfs.append(p)
|
||
|
|
m = raw_markers.search(data)
|
||
|
|
if m:
|
||
|
|
hits.append((os.path.relpath(p, root), m.group(0).decode("ascii", "replace")))
|
||
|
|
|
||
|
|
if elfs:
|
||
|
|
batch_sz = 200
|
||
|
|
for i in range(0, len(elfs), batch_sz):
|
||
|
|
chunk = elfs[i:i + batch_sz]
|
||
|
|
proc = subprocess.run(
|
||
|
|
["readelf", "-d", "-Ws"] + chunk,
|
||
|
|
capture_output=True, text=True, check=False,
|
||
|
|
)
|
||
|
|
cur_file = chunk[0]
|
||
|
|
for line in proc.stdout.splitlines():
|
||
|
|
if line.startswith("File: "):
|
||
|
|
cur_file = line[6:].strip()
|
||
|
|
continue
|
||
|
|
sm = sym_markers.search(line)
|
||
|
|
if sm:
|
||
|
|
hits.append((os.path.relpath(cur_file, root), sm.group(1)))
|
||
|
|
|
||
|
|
print(f"Scanned {len(elfs)} ELF binaries/libraries in rootfs -> {len(hits)} Rust marker hit(s)")
|
||
|
|
if hits:
|
||
|
|
for path, marker in hits[:20]:
|
||
|
|
print(f"FAIL: Rust marker '{marker}' in {path}", file=sys.stderr)
|
||
|
|
sys.exit(1)
|
||
|
|
PYEOF
|
||
|
|
|
||
|
|
echo "[4/8] Simulating Alpine Edge live 'apk upgrade' with locked @geminux packages..."
|
||
|
|
ROOTFS_HOST="$(realpath "$ROOTFS_DIR")"
|
||
|
|
docker run --rm --network=host \
|
||
|
|
-v "$ROOTFS_HOST:/rootfs" \
|
||
|
|
alpine:3.24 sh -eu -c '
|
||
|
|
mkdir -p /var/lib/geminux
|
||
|
|
ln -sfn /rootfs/var/lib/geminux/apk-repo /var/lib/geminux/apk-repo
|
||
|
|
cp -f /rootfs/etc/apk/keys/*.rsa.pub /etc/apk/keys/ 2>/dev/null || true
|
||
|
|
|
||
|
|
apk --root /rootfs --arch aarch64 update
|
||
|
|
UPG_OUT="$(apk --root /rootfs --arch aarch64 upgrade --simulate 2>&1)"
|
||
|
|
printf "%s\n" "$UPG_OUT"
|
||
|
|
|
||
|
|
for pkg in geminux-kernel-modules geminux-xlibre geminux-suckless \
|
||
|
|
geminux-dunst geminux-ui geminux-config; do
|
||
|
|
if ! grep -q "^${pkg}@geminux=" /rootfs/etc/apk/world; then
|
||
|
|
echo "FAIL: ${pkg} is not exact-version pinned to @geminux in world" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
if printf "%s\n" "$UPG_OUT" | grep -q -E "(Upgrading|Replacing|Deleting|Downgrading) ${pkg}\b"; then
|
||
|
|
echo "FAIL: ${pkg} would be modified by upstream upgrade" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
|
||
|
|
if printf "%s\n" "$UPG_OUT" | grep -q -E "(rust|cargo|librsvg|libglycin|gdk-pixbuf|rav1e|libdovi|xorg-server|linux-edge)"; then
|
||
|
|
echo "FAIL: upgrade simulation tried to pull forbidden Rust or upstream override package" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
'
|
||
|
|
echo "OK"
|
||
|
|
|
||
|
|
echo "[5/8] Verifying overlay artifact sync..."
|
||
|
|
"$BASE_DIR/scripts/sync-prebuilt-overlay.sh" --check
|
||
|
|
|
||
|
|
echo "[6/8] Verifying aarch64 ELF architecture on all Geminux custom binaries..."
|
||
|
|
file \
|
||
|
|
"$BASE_DIR/prebuilt/xlibre/usr/bin/Xorg" \
|
||
|
|
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/libglamoregl.so" \
|
||
|
|
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/extensions/libglx.so" \
|
||
|
|
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/drivers/modesetting_drv.so" \
|
||
|
|
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/drivers/fbdev_drv.so" \
|
||
|
|
"$BASE_DIR/prebuilt/xlibre/usr/lib/xorg/modules/xlibre-25/input/libinput_drv.so" \
|
||
|
|
"$BASE_DIR/prebuilt/suckless/usr/bin/st" \
|
||
|
|
"$BASE_DIR/prebuilt/suckless/usr/bin/dwm" \
|
||
|
|
"$BASE_DIR/prebuilt/suckless/usr/bin/dmenu" \
|
||
|
|
"$BASE_DIR/prebuilt/suckless/usr/bin/stest" \
|
||
|
|
"$BASE_DIR/prebuilt/dunst/usr/bin/dunst" \
|
||
|
|
"$BASE_DIR/prebuilt/dunst/usr/bin/notify-send" \
|
||
|
|
"$BASE_DIR/prebuilt/geminux/usr/lib/libgemui.so" \
|
||
|
|
"$BASE_DIR/prebuilt/geminux/usr/bin/"* \
|
||
|
|
"$BASE_DIR/prebuilt/geminux/usr/sbin/"* | \
|
||
|
|
awk '!/ARM aarch64/ { print "FAIL: not aarch64: " $0; bad=1 } END { exit bad }'
|
||
|
|
echo "OK (all aarch64 ELFs verified)"
|
||
|
|
|
||
|
|
echo "[7/8] Verifying partition budgets, ext4 image e2fsck, and SHA256SUMS..."
|
||
|
|
BOOT_SZ="$(stat -c %s "$IMAGES_DIR/boot-geminux.img")"
|
||
|
|
REC_SZ="$(stat -c %s "$IMAGES_DIR/recovery-geminux.img")"
|
||
|
|
DTB_SZ="$(stat -c %s "$BASE_DIR/prebuilt/kernel/boot/mt6797-gemini-pda-geminux.dtb")"
|
||
|
|
[ "$BOOT_SZ" -le 16777216 ] || { echo "FAIL: boot-geminux.img > 16 MiB ($BOOT_SZ)" >&2; exit 1; }
|
||
|
|
[ "$REC_SZ" -le 16777216 ] || { echo "FAIL: recovery-geminux.img > 16 MiB ($REC_SZ)" >&2; exit 1; }
|
||
|
|
[ "$DTB_SZ" -le 524288 ] || { echo "FAIL: DTB > 512 KiB ($DTB_SZ)" >&2; exit 1; }
|
||
|
|
|
||
|
|
python3 - "$IMAGES_DIR/boot-geminux.img" "$IMAGES_DIR/recovery-geminux.img" \
|
||
|
|
"$BASE_DIR/prebuilt/kernel/boot/config-7.3.5-geminux" "$ROOTFS_DIR" <<'PYEOF'
|
||
|
|
import os
|
||
|
|
import struct
|
||
|
|
import sys
|
||
|
|
|
||
|
|
for path in sys.argv[1:3]:
|
||
|
|
with open(path, "rb") as f:
|
||
|
|
hdr = f.read(640)
|
||
|
|
if hdr[:8] != b"ANDROID!":
|
||
|
|
raise SystemExit(f"FAIL: invalid boot image magic in {path}")
|
||
|
|
kernel_addr = struct.unpack("<I", hdr[12:16])[0]
|
||
|
|
if kernel_addr != 0x40080000:
|
||
|
|
raise SystemExit(
|
||
|
|
f"FAIL: {path} kernel_addr={kernel_addr:#010x}, expected 0x40080000 for Gemini LK"
|
||
|
|
)
|
||
|
|
cmdline = hdr[64:576].split(b"\x00", 1)[0].decode("ascii", "replace")
|
||
|
|
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
|
||
|
|
if req not in cmdline.split():
|
||
|
|
raise SystemExit(f"FAIL: {path} cmdline missing '{req}': {cmdline}")
|
||
|
|
|
||
|
|
with open(sys.argv[3], "r", encoding="utf-8") as f:
|
||
|
|
kcfg = f.read()
|
||
|
|
for line in kcfg.splitlines():
|
||
|
|
if line.startswith("CONFIG_CMDLINE="):
|
||
|
|
for req in ("clk_ignore_unused", "maxcpus=8", "noautodetect"):
|
||
|
|
if req not in line:
|
||
|
|
raise SystemExit(f"FAIL: {sys.argv[3]} {line} missing '{req}'")
|
||
|
|
break
|
||
|
|
else:
|
||
|
|
raise SystemExit(f"FAIL: {sys.argv[3]} missing CONFIG_CMDLINE")
|
||
|
|
|
||
|
|
rootfs = sys.argv[4]
|
||
|
|
for req_rel in ("etc/pam.d/autologin", "etc/init.d/geminux-hwinit",
|
||
|
|
"usr/lib/dri/simpledrm_dri.so", "etc/runlevels/boot/geminux-usb-gadget"):
|
||
|
|
if not os.path.lexists(os.path.join(rootfs, req_rel)):
|
||
|
|
raise SystemExit(f"FAIL: missing required path {os.path.join(rootfs, req_rel)}")
|
||
|
|
if os.path.lexists(os.path.join(rootfs, "etc/runlevels/sysinit/hwdrivers")):
|
||
|
|
raise SystemExit("FAIL: hwdrivers must not be enabled in sysinit")
|
||
|
|
xorg_mode = os.stat(os.path.join(rootfs, "usr/bin/Xorg")).st_mode & 0o7777
|
||
|
|
if xorg_mode != 0o4755:
|
||
|
|
raise SystemExit(f"FAIL: rootfs/usr/bin/Xorg mode is {oct(xorg_mode)}, expected 0o4755")
|
||
|
|
|
||
|
|
awk_path = os.path.join(rootfs, "usr", "bin", "awk")
|
||
|
|
if not os.path.lexists(awk_path):
|
||
|
|
raise SystemExit(f"FAIL: missing BusyBox applet {awk_path}")
|
||
|
|
|
||
|
|
bb_path = os.path.join(rootfs, "bin", "busybox")
|
||
|
|
with open(bb_path, "rb") as f:
|
||
|
|
bb_data = f.read()
|
||
|
|
idx = bb_data.find(b"[\x00[[\x00")
|
||
|
|
if idx < 0:
|
||
|
|
raise SystemExit(f"FAIL: unable to locate applet table in {bb_path}")
|
||
|
|
end = bb_data.find(b"\x00\x00", idx)
|
||
|
|
names = [s.decode("ascii") for s in bb_data[idx:end].split(b"\x00") if s]
|
||
|
|
missing = [
|
||
|
|
n for n in names
|
||
|
|
if not any(os.path.lexists(os.path.join(rootfs, d, n))
|
||
|
|
for d in ("bin", "sbin", "usr/bin", "usr/sbin"))
|
||
|
|
]
|
||
|
|
if missing:
|
||
|
|
raise SystemExit(f"FAIL: {len(missing)} missing BusyBox applet(s): {' '.join(missing)}")
|
||
|
|
print(f"OK (kernel_addr=0x40080000, noautodetect, {len(names)} BusyBox applets linked)")
|
||
|
|
PYEOF
|
||
|
|
|
||
|
|
docker run --rm -v "$IMAGES_DIR:/images:ro" -v "$BASE_DIR/prebuilt/kernel/boot:/kboot:ro" alpine:3.24 sh -eu -c '
|
||
|
|
apk add --no-cache e2fsprogs e2fsprogs-extra dtc >/dev/null
|
||
|
|
e2fsck -fn /images/geminux-rootfs.img
|
||
|
|
debugfs -R "stat /usr/bin/Xorg" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04755\b" || {
|
||
|
|
echo "FAIL: geminux-rootfs.img /usr/bin/Xorg is not mode 04755" >&2; exit 1;
|
||
|
|
}
|
||
|
|
debugfs -R "stat /usr/bin/Xorg" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*0\b" || {
|
||
|
|
echo "FAIL: geminux-rootfs.img /usr/bin/Xorg is not UID 0" >&2; exit 1;
|
||
|
|
}
|
||
|
|
debugfs -R "stat /usr/bin/doas" /images/geminux-rootfs.img | grep -qE "Mode:[[:space:]]*04755\b" || {
|
||
|
|
echo "FAIL: geminux-rootfs.img /usr/bin/doas is not mode 04755" >&2; exit 1;
|
||
|
|
}
|
||
|
|
debugfs -R "stat /home/user" /images/geminux-rootfs.img | grep -qE "User:[[:space:]]*10000\b" || {
|
||
|
|
echo "FAIL: geminux-rootfs.img /home/user is not UID 10000" >&2; exit 1;
|
||
|
|
}
|
||
|
|
DTS_OUT="$(dtc -I dtb -O dts /kboot/mt6797-gemini-pda-geminux.dtb 2>/dev/null)"
|
||
|
|
printf "%s\n" "$DTS_OUT" | grep -qE "^\tmemory \{$" || { echo "FAIL: DTB missing /memory node" >&2; exit 1; }
|
||
|
|
if printf "%s\n" "$DTS_OUT" | grep -qE "^\tmemory@40000000 \{$"; then
|
||
|
|
echo "FAIL: DTB still contains root /memory@40000000" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
if printf "%s\n" "$DTS_OUT" | grep -q "memory@7df00000"; then
|
||
|
|
echo "FAIL: DTB contains static memory@7df00000 that triggers LK reserved_memory_conflict_check" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
'
|
||
|
|
(cd "$IMAGES_DIR" && sha256sum -c SHA256SUMS)
|
||
|
|
|
||
|
|
echo "[8/8] Running all 5 Python unit/verification suites..."
|
||
|
|
python3 "$BASE_DIR/scripts/test-flash-mtk-gpt.py"
|
||
|
|
python3 "$BASE_DIR/scripts/test-xkb-keymap.py"
|
||
|
|
python3 "$BASE_DIR/scripts/test-theme-dunst-sync.py"
|
||
|
|
python3 "$BASE_DIR/scripts/test-ccci-protocol.py"
|
||
|
|
python3 "$BASE_DIR/scripts/test-power-policy.py"
|
||
|
|
|
||
|
|
echo "============================================================"
|
||
|
|
echo "ALL GEMINUX CHECKS PASSED CLEANLY"
|
||
|
|
echo "============================================================"
|