]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot-secret: don't initialize secret mixin file if marked read-only
authorLennart Poettering <lennart@amutable.com>
Mon, 13 Jul 2026 13:50:28 +0000 (15:50 +0200)
committerLennart Poettering <lennart@amutable.com>
Tue, 14 Jul 2026 08:12:50 +0000 (10:12 +0200)
If the boot secret mixin file exists but is empty we'd normally fill it
with a fresh mixin. Refrain from that if the read-only FAT file
attribute is set on it, taking that as a hint that the file shall not
be initialized. Reading an existing, fully populated mixin file remains
unaffected by the flag.

src/boot/boot-secret.c

index 7be0880d3b07476bea3b213af3ec5bce0acf63ce..3b614d3fe89365b76ef62e4060dd14be756881c6 100644 (file)
@@ -223,7 +223,7 @@ static EFI_STATUS acquire_secret_mixin(
                         (char16_t *) BOOT_SECRET_MIXIN_PATH,
                         EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
                         /* Attributes= */ 0);
-        if (err == EFI_WRITE_PROTECTED) {
+        if (EFI_STATUS_IS_WRITE_REFUSED(err)) {
                 err = root_dir->Open(
                                 root_dir,
                                 &handle,
@@ -243,8 +243,13 @@ static EFI_STATUS acquire_secret_mixin(
         err = get_file_info(handle, &info, /* ret_size= */ NULL);
         if (err != EFI_SUCCESS)
                 return log_debug_status(err, "Failed to get boot secret mixin file '%ls' info: %m", BOOT_SECRET_MIXIN_PATH);
-        if (info->FileSize == 0 && writable) /* New file? Fill it. */
+        if (info->FileSize == 0 && writable) { /* New file? Fill it. */
+                /* If the mixin file is marked read-only take this as a hint that it shall not be initialized. */
+                if (FLAGS_SET(info->Attribute, EFI_FILE_READ_ONLY))
+                        return log_debug_status(EFI_WRITE_PROTECTED, "Boot secret mixin file '%ls' is marked read-only, not initializing it.", BOOT_SECRET_MIXIN_PATH);
+
                 return setup_secret_mixin(handle, seed_table, ret_mixin);
+        }
 
         /* If the mixin file is too small we won't overwrite it (in order to not destroy some potentially
          * load bearing key), but we won't use it either. */