Skip to content

Commit a7e7059

Browse files
committed
fix(os): pin rootfs assembly binaries
1 parent b7007c4 commit a7e7059

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

os/mkosi/scripts/make-release-artifacts.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ FLAVOR=${4:?flavor required}
1313
SOURCE_DATE_EPOCH=${SOURCE_DATE_EPOCH:?}
1414
export SOURCE_DATE_EPOCH TZ=UTC LC_ALL=C
1515
mkdir -p "$OUT/files"
16+
TREE_RUNNER="$SELF/scripts/run-in-tree.sh"
17+
TOOLS_TREE=${DSTACK_TOOLS_TREE:-$SELF/mkosi.tools}
18+
[[ -x $TOOLS_TREE/usr/bin/mksquashfs ]] || {
19+
echo "mksquashfs missing from pinned mkosi tools tree" >&2; exit 1;
20+
}
1621

1722
kernel="$KERNEL_TREE/usr/lib/modules/$KERNEL_VERSION-dstack/vmlinuz"
1823
install -m0644 "$kernel" "$OUT/files/bzImage"
@@ -25,13 +30,17 @@ truncate -s 0 "$rootfs"
2530
# Privileged mkosi runs can inherit host default ACLs from their workspace.
2631
# The guest rootfs does not rely on xattrs, so exclude this host-only metadata.
2732
# A single compressor worker also avoids host-CPU-dependent fragment ordering.
28-
env -u SOURCE_DATE_EPOCH mksquashfs "$TREE" "$rootfs" -noappend -all-root -no-progress \
33+
env -u SOURCE_DATE_EPOCH "$TREE_RUNNER" "$TOOLS_TREE" /usr/bin/mksquashfs \
34+
"$TREE" "$rootfs" -noappend -all-root -no-progress \
2935
-no-xattrs -processors 1 -comp zstd -mkfs-time "$SOURCE_DATE_EPOCH" \
3036
-all-time "$SOURCE_DATE_EPOCH" >/dev/null
3137
data_size=$(stat -c %s "$rootfs")
3238
data_size=$(( (data_size + 4095) / 4096 * 4096 ))
3339
truncate -s "$data_size" "$rootfs"
34-
verity_output=$(veritysetup format "$rootfs" "$rootfs" \
40+
verity_program=$(find "$TREE" -type f \( -path '*/sbin/veritysetup' -o \
41+
-path '*/bin/veritysetup' \) -printf '/%P\n' | head -1)
42+
[[ -n $verity_program ]] || { echo 'veritysetup missing from mkosi tree' >&2; exit 1; }
43+
verity_output=$("$TREE_RUNNER" "$TREE" "$verity_program" format "$rootfs" "$rootfs" \
3544
--hash-offset="$data_size" --data-block-size=4096 --hash-block-size=4096 \
3645
--uuid=00000000-0000-0000-0000-000000000000 \
3746
--salt="$(printf '%064x' 0)")

os/mkosi/scripts/run-in-tree.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: Apache-2.0
3+
set -euo pipefail
4+
5+
TREE=${1:?root tree required}
6+
PROGRAM=${2:?program path required}
7+
shift 2
8+
9+
[[ $PROGRAM == /* ]] || { echo "program path must be absolute" >&2; exit 2; }
10+
[[ -x $TREE$PROGRAM ]] || { echo "program not found in tree: $PROGRAM" >&2; exit 1; }
11+
12+
# Invoke the program with the dynamic loader and libraries from its immutable
13+
# tree. This avoids silently using equivalent-looking host tools with different
14+
# distro patches while requiring neither chroot nor mount privileges.
15+
loader=$(find "$TREE/usr/lib" "$TREE/lib" -type f \
16+
-name 'ld-linux-x86-64.so.2' -print -quit 2>/dev/null)
17+
[[ -n $loader ]] || { echo "dynamic loader missing from tree" >&2; exit 1; }
18+
library_path="$TREE/usr/lib/x86_64-linux-gnu:$TREE/lib/x86_64-linux-gnu"
19+
exec "$loader" --library-path "$library_path" "$TREE$PROGRAM" "$@"

0 commit comments

Comments
 (0)