]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stub: Ignore the boot counter when looking for .extra.d directory
authorValentin David <me@valentindavid.com>
Thu, 19 Oct 2023 21:13:45 +0000 (23:13 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 20 Oct 2023 15:18:09 +0000 (16:18 +0100)
If `foo+3-0.efi` is booted when there are some files in `foo.efi.extra.d`,
those files are ignored. But after the boot is blessed and the system rebooted,
those file are taken into account, and the boot is different from first
boot. This behavior is a bit puzzling.

Instead we now ignore the counter and always look for the extra files in
`foo.efi.extra.d` and always boot the same way.

man/systemd-stub.xml
src/boot/efi/util.c

index 5650c53f0218b15ff92e176d07b42f9786c2d017..337759a0c3c5f7dc7fe7e242e2b2bd6420bf47cc 100644 (file)
     <itemizedlist>
       <listitem><para>For a kernel binary called <filename><replaceable>foo</replaceable>.efi</filename>, it
       will look for files with the <filename>.cred</filename> suffix in a directory named
-      <filename><replaceable>foo</replaceable>.efi.extra.d/</filename> next to it. A <command>cpio</command>
+      <filename><replaceable>foo</replaceable>.efi.extra.d/</filename> next to it. If the kernel binary
+      uses a counter for the purpose of
+      <ulink url="https://systemd.io/AUTOMATIC_BOOT_ASSESSMENT">Automatic Boot Assessment</ulink>, this
+      counter will be ignored. For example, <filename><replaceable>foo</replaceable>+3-0.efi</filename>
+      will look in directory <filename><replaceable>foo</replaceable>.efi.extra.d/</filename>.
+      A <command>cpio</command>
       archive is generated from all files found that way, placing them in the
       <filename>/.extra/credentials/</filename> directory of the initrd file hierarchy. The main initrd may
       then access them in this directory. This is supposed to be used to store auxiliary, encrypted,
index 32796f9ff2e36072114f043481f176d47e0cb5e5..25f5e0f032469cd873448868d7827e76fc5ddc7e 100644 (file)
@@ -646,6 +646,34 @@ void *find_configuration_table(const EFI_GUID *guid) {
         return NULL;
 }
 
+static void remove_boot_count(char16_t *path) {
+        char16_t *prefix_end;
+        const char16_t *tail;
+        uint64_t ignored;
+
+        assert(path);
+
+        prefix_end = strchr16(path, '+');
+        if (!prefix_end)
+                return;
+
+        tail = prefix_end + 1;
+
+        if (!parse_number16(tail, &ignored, &tail))
+                return;
+
+        if (*tail == '-') {
+                ++tail;
+                if (!parse_number16(tail, &ignored, &tail))
+                        return;
+        }
+
+        if (!IN_SET(*tail, '\0', '.'))
+                return;
+
+        strcpy16(prefix_end, tail);
+}
+
 char16_t *get_extra_dir(const EFI_DEVICE_PATH *file_path) {
         if (!file_path)
                 return NULL;
@@ -666,5 +694,6 @@ char16_t *get_extra_dir(const EFI_DEVICE_PATH *file_path) {
                 return NULL;
 
         convert_efi_path(file_path_str);
+        remove_boot_count(file_path_str);
         return xasprintf("%ls.extra.d", file_path_str);
 }