]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
veritysetup: add support for hash-offset option
authorGaël PORTAY <gael.portay@collabora.com>
Fri, 25 Dec 2020 08:08:05 +0000 (03:08 -0500)
committerGaël PORTAY <gael.portay@rtone.fr>
Thu, 13 Apr 2023 03:15:17 +0000 (05:15 +0200)
The verity parameter hash_area_offset allows to locate the superblock in
the hash device. It can be used to have a single device which contains
both data and hashes.

This adds the option hash-offset=BYTES (sixth argument) which is the
equivalent of the option --hash-offset in the veritysetup world.

See `veritysetup(8)` for more details.

man/systemd-veritysetup-generator.xml
man/veritytab.xml
src/veritysetup/veritysetup.c

index 37ded91a936dd5f8898f09fb30aca778a5ef86c0..6098895f55f1e67f979dea6ac82a176f84ec7277 100644 (file)
@@ -85,7 +85,8 @@
         <term><varname>systemd.verity_root_options=</varname></term>
 
         <listitem><para>Takes a comma-separated list of dm-verity options. Expects the following options
-        <option>ignore-corruption</option>, <option>restart-on-corruption</option>, <option>ignore-zero-blocks</option>,
+        <option>hash-offset=<replaceable>BYTES</replaceable></option>, <option>ignore-corruption</option>,
+        <option>restart-on-corruption</option>, <option>ignore-zero-blocks</option>,
         <option>check-at-most-once</option>, <option>panic-on-corruption</option> and
         <option>root-hash-signature=<replaceable>PATH</replaceable>|base64:<replaceable>HEX</replaceable></option>. See
         <citerefentry project='die-net'><refentrytitle>veritysetup</refentrytitle><manvolnum>8</manvolnum></citerefentry> for more
index dc2f11c31e26e7f85d66930b4f987fdd13124eb4..ec5d0f45a1a279519a2200d7cd2d87127b59df84 100644 (file)
@@ -60,6 +60,13 @@ This is based on crypttab(5).
 
     <variablelist class='fstab-options'>
 
+      <varlistentry>
+        <term><option>hash-offset=<replaceable>BYTES</replaceable></option></term>
+
+        <listitem><para>Offset of hash area/superblock on <literal>hash-device</literal>. (Multiples of 512 bytes.)
+        </para></listitem>
+      </varlistentry>
+
       <varlistentry>
         <term><option>ignore-corruption</option></term>
         <term><option>restart-on-corruption</option></term>
index ae497b02eefa829b7059730f5ae21012a40f4d12..e1b0e00e421cd78edb7082985e4f497d81f605ce 100644 (file)
 #include "hexdecoct.h"
 #include "log.h"
 #include "main-func.h"
+#include "parse-util.h"
 #include "path-util.h"
 #include "pretty-print.h"
 #include "process-util.h"
 #include "string-util.h"
 #include "terminal-util.h"
 
+static uint64_t arg_hash_offset = 0;
 static uint32_t arg_activate_flags = CRYPT_ACTIVATE_READONLY;
 static char *arg_root_hash_signature = NULL;
 
@@ -104,7 +106,17 @@ static int parse_options(const char *options) {
                 else if (streq(word, "panic-on-corruption"))
                         arg_activate_flags |= CRYPT_ACTIVATE_PANIC_ON_CORRUPTION;
 #endif
-                else if ((val = startswith(word, "root-hash-signature="))) {
+                else if ((val = startswith(word, "hash-offset="))) {
+                        uint64_t off;
+
+                        r = parse_size(val, 1024, &off);
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to parse offset '%s': %m", word);
+                        if (off % 512 != 0)
+                                return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "hash-offset= expects a 512-byte aligned value.");
+
+                        arg_hash_offset = off;
+                } else if ((val = startswith(word, "root-hash-signature="))) {
                         r = save_roothashsig_option(val, /* strict= */ true);
                         if (r < 0)
                                 return r;
@@ -138,6 +150,7 @@ static int run(int argc, char *argv[]) {
         if (streq(verb, "attach")) {
                 const char *volume, *data_device, *verity_device, *root_hash, *options;
                 _cleanup_free_ void *m = NULL;
+                struct crypt_params_verity p = {};
                 crypt_status_info status;
                 size_t l;
 
@@ -173,9 +186,11 @@ static int run(int argc, char *argv[]) {
                         r = parse_options(options);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to parse options: %m");
+
+                        p.hash_area_offset = arg_hash_offset;
                 }
 
-                r = crypt_load(cd, CRYPT_VERITY, NULL);
+                r = crypt_load(cd, CRYPT_VERITY, &p);
                 if (r < 0)
                         return log_error_errno(r, "Failed to load verity superblock: %m");