From: Daan De Meyer Date: Sun, 18 Sep 2022 13:36:59 +0000 (+0200) Subject: dissect: Process verity sig partitions if a root hash is specified X-Git-Tag: v252-rc1~98^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3dd73ea77e22da8cf5fdf9f3160ec7a9df254d68;p=thirdparty%2Fsystemd.git dissect: Process verity sig partitions if a root hash is specified If a root hash is specified, we should be checking that it matches the root hash in the verity signature partition, so let's not skip processing of the verity signature partitions if a root hash is specified. --- diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index a7eec9fa11d..2ea053e009a 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -603,13 +603,10 @@ int dissect_image( m->has_verity_sig = true; - /* If root hash is specified explicitly, then ignore any embedded signature */ if (!verity) continue; if (verity->designator >= 0 && verity->designator != PARTITION_ROOT) continue; - if (verity->root_hash) - continue; assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0); designator = PARTITION_VERITY_SIG_OF(PARTITION_ROOT_OF_ARCH(architecture)); @@ -667,13 +664,10 @@ int dissect_image( m->has_verity_sig = true; - /* If usr hash is specified explicitly, then ignore any embedded signature */ if (!verity) continue; if (verity->designator >= 0 && verity->designator != PARTITION_USR) continue; - if (verity->root_hash) - continue; assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0); designator = PARTITION_VERITY_SIG_OF(PARTITION_USR_OF_ARCH(architecture)); @@ -1074,6 +1068,9 @@ int dissect_image( if (verity->designator >= 0 && !m->partitions[verity->designator].found) return -EADDRNOTAVAIL; + bool have_verity_sig_partition = + m->partitions[verity->designator == PARTITION_USR ? PARTITION_USR_VERITY_SIG : PARTITION_ROOT_VERITY_SIG].found; + if (verity->root_hash) { /* If we have an explicit root hash and found the partitions for it, then we are ready to use * Verity, set things up for it */ @@ -1097,9 +1094,9 @@ int dissect_image( } if (m->verity_ready) - m->verity_sig_ready = verity->root_hash_sig; + m->verity_sig_ready = verity->root_hash_sig || have_verity_sig_partition; - } else if (m->partitions[verity->designator == PARTITION_USR ? PARTITION_USR_VERITY_SIG : PARTITION_ROOT_VERITY_SIG].found) { + } else if (have_verity_sig_partition) { /* If we found an embedded signature partition, we are ready, too. */ diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh index f39383abc5d..3ab020d6876 100755 --- a/test/units/testsuite-50.sh +++ b/test/units/testsuite-50.sh @@ -214,8 +214,11 @@ losetup -d "${loop}" ROOT_UUID="$(systemd-id128 -u show "$(head -c 32 "${image}.roothash")" -u | tail -n 1 | cut -b 6-)" VERITY_UUID="$(systemd-id128 -u show "$(tail -c 32 "${image}.roothash")" -u | tail -n 1 | cut -b 6-)" -systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt" | grep -q '{"rw":"ro","designator":"root","partition_uuid":"'"$ROOT_UUID"'","partition_label":"Root Partition","fstype":"squashfs","architecture":"'"$architecture"'","verity":"yes",' +systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt" | grep -q '{"rw":"ro","designator":"root","partition_uuid":"'"$ROOT_UUID"'","partition_label":"Root Partition","fstype":"squashfs","architecture":"'"$architecture"'","verity":"signed",' systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt" | grep -q '{"rw":"ro","designator":"root-verity","partition_uuid":"'"$VERITY_UUID"'","partition_label":"Verity Partition","fstype":"DM_verity_hash","architecture":"'"$architecture"'","verity":null,' +if [ "${HAVE_OPENSSL}" -eq 1 ]; then + systemd-dissect --json=short --root-hash "${roothash}" "${image}.gpt" | grep -q -E '{"rw":"ro","designator":"root-verity-sig","partition_uuid":"'".*"'","partition_label":"Signature Partition","fstype":"verity_hash_signature","architecture":"'"$architecture"'","verity":null,' +fi systemd-dissect --root-hash "${roothash}" "${image}.gpt" | grep -q -F "MARKER=1" systemd-dissect --root-hash "${roothash}" "${image}.gpt" | grep -q -F -f <(sed 's/"//g' "$os_release")