]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect: add new helper verity_settings_data_covers()
authorLennart Poettering <lennart@poettering.net>
Wed, 30 Nov 2022 17:44:06 +0000 (18:44 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 2 Dec 2022 23:22:23 +0000 (00:22 +0100)
This function checks if the external verity data referenced in
VeritySettings covers the specified partition (indicated via
designator).

Right now, we'll use that at one place, but in a later commit in more.

src/shared/dissect-image.c
src/shared/dissect-image.h

index 4dd2c2c3a9c9433d9aa4645e1eecb948889be68a..b3d35e9fbf34c6545160a80b4fbf80b2640c3f4d 100644 (file)
@@ -513,13 +513,10 @@ static int dissect_image(
                         m->encrypted = streq_ptr(fstype, "crypto_LUKS");
 
                         m->has_verity = verity && verity->data_path;
-                        m->verity_ready = m->has_verity &&
-                                verity->root_hash &&
-                                (verity->designator < 0 || verity->designator == PARTITION_ROOT);
+                        m->verity_ready = verity_settings_data_covers(verity, PARTITION_ROOT);
 
                         m->has_verity_sig = false; /* signature not embedded, must be specified */
-                        m->verity_sig_ready = m->verity_ready &&
-                                verity->root_hash_sig;
+                        m->verity_sig_ready = m->verity_ready && verity->root_hash_sig;
 
                         m->image_uuid = uuid;
 
index 5402e4fca2e9eebb15fd4d1325df48155127d09c..059b9aecbb9e36dcfc4faf32157995698c8385f3 100644 (file)
@@ -166,6 +166,14 @@ int dissected_image_relinquish(DissectedImage *m);
 int verity_settings_load(VeritySettings *verity, const char *image, const char *root_hash_path, const char *root_hash_sig_path);
 void verity_settings_done(VeritySettings *verity);
 
+static inline bool verity_settings_data_covers(const VeritySettings *verity, PartitionDesignator d) {
+        /* Returns true if the verity settings contain sufficient information to cover the specified partition */
+        return verity &&
+                ((d >= 0 && verity->designator == d) || (d == PARTITION_ROOT && verity->designator < 0)) &&
+                verity->root_hash &&
+                verity->data_path;
+}
+
 int dissected_image_load_verity_sig_partition(DissectedImage *m, int fd, VeritySettings *verity);
 
 bool dissected_image_verity_candidate(const DissectedImage *image, PartitionDesignator d);