SPS · log · files · refs · tags · releases · people · languages · GitHub · commit
4dd33bc
mkiso: root-owned live root, and no silent init substitution
Parents
Stat
bin/mkiso | 26 ++++++++++++++++++++++---- tests/test_mkiso.sh | 2 ++ 2 files changed, 24 insertions(+), 4 deletions(-)
Diff
diff --git a/bin/mkiso b/bin/mkiso
index 9995ef1..fff7ea9 100755
--- a/bin/mkiso
+++ b/bin/mkiso
@@ -1572,6 +1572,14 @@ mkiso_install_pid1()
mkiso_copy_path "$mkiso_openrc"
mkiso_copy_libs "$mkiso_openrc"
ln -sf "$mkiso_openrc" "$mkiso_live/sbin/init"
+ elif [ "$mkiso_init" = systemd ] || [ "$mkiso_init" = openrc ]; then
+ # Falling back silently ships a disc that says systemd in
+ # /etc/sps/init and on the kernel command line while PID 1 is
+ # really busybox. Every service the image declares is then
+ # quietly dead and the cause is invisible from inside the
+ # booted system. Refuse instead.
+ sps_die "$SPS_EX_PACKAGE" \
+ "--init $mkiso_init was requested but this host has no $mkiso_init binaries to copy"
else
printf '%s: live PID 1 is busybox init (host has no %s binaries)\n' \
"$sps_prog" "$mkiso_init" >&2
@@ -1865,19 +1873,24 @@ mkiso_squash_jobs=$(nproc 2>/dev/null || printf 2)
case $mkiso_squash_jobs in
''|*[!0-9]*|0) mkiso_squash_jobs=2 ;;
esac
+# -all-root: everything in a live root belongs to root. Without it an
+# unprivileged build bakes the builder's uid into every file, and the booted
+# system finds /usr owned by a user that does not exist on it. systemd
+# refuses unit files it does not trust and sudo refuses to run at all.
if ! mksquashfs "$mkiso_live" "$mkiso_iso/live/filesystem.squashfs" \
-comp zstd -Xcompression-level 3 -b 262144 -noappend -no-progress \
- -processors "$mkiso_squash_jobs" \
+ -all-root -processors "$mkiso_squash_jobs" \
-e boot tmp var/tmp var/cache
then
printf '%s: zstd squashfs failed, trying xz\n' "$sps_prog" >&2
if ! mksquashfs "$mkiso_live" "$mkiso_iso/live/filesystem.squashfs" \
- -comp xz -noappend -no-progress -processors "$mkiso_squash_jobs" \
+ -comp xz -noappend -no-progress -all-root \
+ -processors "$mkiso_squash_jobs" \
-e boot tmp var/tmp var/cache
then
printf '%s: xz squashfs failed, trying gzip\n' "$sps_prog" >&2
mksquashfs "$mkiso_live" "$mkiso_iso/live/filesystem.squashfs" \
- -comp gzip -noappend -no-progress \
+ -comp gzip -noappend -no-progress -all-root \
-processors "$mkiso_squash_jobs" \
-e boot tmp var/tmp var/cache ||
sps_die "$SPS_EX_BUILD" "mksquashfs failed"
@@ -1949,9 +1962,14 @@ if [ -d "$mkiso_modules" ]; then
fi
printf '%s: packing initramfs\n' "$sps_prog" >&2
+# --owner root:root for the same reason as -all-root above: PID 1 runs out of
+# this archive, and cpio would otherwise record the building user's uid.
+mkiso_cpio_owner=--owner=root:root
+printf '' | cpio -o -H newc --owner=root:root >/dev/null 2>&1 ||
+ mkiso_cpio_owner=-R0:0
(
cd "$mkiso_ird" || exit 1
- find . | cpio -o -H newc 2>/dev/null
+ find . | cpio -o -H newc "$mkiso_cpio_owner" 2>/dev/null
) | gzip -n -6 >"$mkiso_iso/live/initrd.img" ||
sps_die "$SPS_EX_BUILD" "initramfs cpio failed"
diff --git a/tests/test_mkiso.sh b/tests/test_mkiso.sh
index 56a47dc..9551534 100755
--- a/tests/test_mkiso.sh
+++ b/tests/test_mkiso.sh
@@ -98,6 +98,8 @@ if grep -q -- '-isohybrid-gpt-basdat' "$mkiso"; then
fi
grep -q 'generated ISO has no USB-visible EFI partition' "$mkiso" ||
fail 'mkiso must reject an EFI ISO without a visible EFI partition'
+grep -q 'was requested but this host has no' "$mkiso" ||
+ fail 'mkiso must refuse to substitute busybox init for a requested init'
# Host /bin/sh is bash. Getty runs /bin/sh. A bash symlink without libtinfo
# is the Plasma ISO boot loop.