Skip to content

Commit 1c70adc

Browse files
committed
Add ownership verification and architecture checks to firmware build
Adds check_perms function to verify file ownership is preserved during squashfs operations. Also adds validation to ensure only ARM binaries are present in the final rootfs image.
1 parent 878b881 commit 1c70adc

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

scripts/create_firmware.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,37 @@ shift 3
2020

2121
rm -rf "$TEMP_DIR"
2222

23+
check_perms() {
24+
local file="$1"
25+
local expected_uid="$2"
26+
local expected_gid="$3"
27+
28+
if [[ ! -e "$file" ]]; then
29+
echo "Error: $file does not exist for ownership check."
30+
exit 1
31+
fi
32+
33+
local actual_uid=$(stat -c '%u' "$file")
34+
local actual_gid=$(stat -c '%g' "$file")
35+
36+
if [[ "$actual_uid" != "$expected_uid" ]] || [[ "$actual_gid" != "$expected_gid" ]]; then
37+
echo "Error: $file should be $expected_uid:$expected_gid, got $actual_uid:$actual_gid"
38+
echo "This system does not properly preserve file ownership in squashfs operations."
39+
exit 1
40+
fi
41+
}
42+
2343
echo ">> Unpacking firmware..."
2444
"$ROOT_DIR/scripts/helpers/unpack_firmware.sh" "$IN_FIRMWARE" "$TEMP_DIR"
2545

2646
echo ">> Extracting squashfs from rootfs.img..."
2747
unsquashfs -d "$TEMP_DIR/rootfs" "$TEMP_DIR/rk-unpacked/rootfs.img"
2848

49+
echo ">> Verifying ownership preservation..."
50+
check_perms "$TEMP_DIR/rootfs/etc/passwd" 0 0
51+
check_perms "$TEMP_DIR/rootfs/home/lava/bin/gui" 1000 1000
52+
echo " Ownership check passed"
53+
2954
for overlay; do
3055
if [[ ! -d "$overlay" ]]; then
3156
echo "!! Overlay directory '$overlay' does not exist, skipping."
@@ -60,6 +85,13 @@ for overlay; do
6085
fi
6186
done
6287

88+
echo ">> Checking for non-ARM binaries in rootfs..."
89+
if FILES=$(find "$TEMP_DIR/rootfs" -type f -exec file {} + | grep "ELF" | grep -v "ARM"); then
90+
echo "!! Error: Found non-ARM binaries in the rootfs:"
91+
echo "$FILES"
92+
exit 1
93+
fi
94+
6395
echo ">> Create squash filesystem..."
6496
mksquashfs "$TEMP_DIR/rootfs" "$TEMP_DIR/rk-unpacked/rootfs-v2.img" -comp gzip
6597

0 commit comments

Comments
 (0)