From: Lennart Poettering Date: Mon, 13 Jul 2026 13:41:36 +0000 (+0200) Subject: ci: add test suite for verity+luks disk images X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d14c40919a4d31b0f269156f0a3239e768c7b0e2;p=thirdparty%2Fsystemd.git ci: add test suite for verity+luks disk images --- diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index 551e72c53c2..d5fe4897eac 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -1556,6 +1556,168 @@ EOF veritysetup dump "${loop}p2" | grep 'Data blocks:' | grep "$data_verity_blocks" >/dev/null } +testcase_verity_encrypt() { + local defs imgs output loop drh hrh part_size dm_devno verity_dep + + if ( . /etc/os-release && [[ "$ID" == "postmarketos" ]] ); then + echo "Skipping verity+encrypt test on postmarketOS." + return + fi + + defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" + imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" + # shellcheck disable=SC2064 + trap "rm -rf '$defs' '$imgs'" RETURN + chmod 0755 "$defs" + + echo "*** dm-verity + LUKS2 (verity envelope around encrypted data) ***" + + echo -n "wetterfrosch" >"$imgs/key" + + # Encrypting verity hash partitions must be refused + tee "$defs/verity-data.conf" </dev/null + + # Now a valid combination: the hash partition is sized via SizeMaxBytes= of the data partition + tee "$defs/verity-data.conf" <"$imgs/creds/dissect.passphrase" + + systemd-dissect --root-hash "$drh" "$imgs/verity-encrypt" + systemd-dissect --root-hash "$drh" --validate --image-policy "root=encrypted+verity" "$imgs/verity-encrypt" + # A policy that doesn't allow encryption must be refused + (! systemd-dissect --root-hash "$drh" --validate --image-policy "root=verity" "$imgs/verity-encrypt") + + CREDENTIALS_DIRECTORY="$imgs/creds" systemd-dissect --root-hash "$drh" -M "$imgs/verity-encrypt" "$imgs/mnt" + + # shellcheck disable=SC2064 + trap "umount --quiet --recursive '$imgs/mnt' || : ; rm -rf '$defs' '$imgs' ; systemd-dissect --detach '$loop'" RETURN ERR + + # Check that both DM layers are stacked as expected: the mounted device is a LUKS volume backed by a + # dm-verity device + dm_devno=$(findmnt --noheadings --output MAJ:MIN "$imgs/mnt" | tr -d ' ') + [[ "$(dmsetup table -j "${dm_devno%%:*}" -m "${dm_devno##*:}" | cut -d' ' -f3)" == "crypt" ]] + verity_dep=$(dmsetup deps -o devname -j "${dm_devno%%:*}" -m "${dm_devno##*:}" | sed 's/.*(\(.*\))/\1/') + [[ "$(dmsetup table "/dev/mapper/$verity_dep" | cut -d' ' -f3)" == "verity" ]] + + # The copied-in files must be intact + cmp "$defs/verity-data.conf" "$imgs/mnt$defs/verity-data.conf" + + systemd-dissect -U "$imgs/mnt" + + # Now corrupt a block in the middle of the encrypted data partition and check that verification fails + part_size=$(blockdev --getsize64 "${loop}p1") + dd if=/dev/urandom of="${loop}p1" bs=4096 count=1 seek=$(( part_size / 2 / 4096 )) oflag=direct conv=notrunc + (! veritysetup verify "${loop}p1" "${loop}p2" "$drh") +} + testcase_exclude_files() { local defs imgs root output