]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: skip boot counter logic for entries marked read-only 43012/head
authorLennart Poettering <lennart@amutable.com>
Mon, 13 Jul 2026 13:56:36 +0000 (15:56 +0200)
committerLennart Poettering <lennart@amutable.com>
Tue, 14 Jul 2026 08:13:17 +0000 (10:13 +0200)
If the read-only FAT file attribute is set on a boot entry file with a
counter in its name, don't attempt to rename it, but simply skip the
boot counter logic for it, taking the flag as a hint that the entry
shall not be subject to boot assessment.

src/boot/boot.c

index c2f7e9b5008dec1ce2daf79d3b5fb39148f335a8..e62df180910a6cfaf8818a6aa8062573d7f4ca7c 100644 (file)
@@ -1326,6 +1326,8 @@ static EFI_STATUS boot_entry_bump_counters(BootEntry *entry) {
         old_path = xasprintf("%ls\\%ls", entry->directory, entry->current_name);
 
         err = root->Open(root, &handle, old_path, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL);
+        if (EFI_STATUS_IS_WRITE_REFUSED(err))
+                goto read_only;
         if (err != EFI_SUCCESS)
                 return log_error_status(err, "Error opening boot entry '%ls': %m", old_path);
 
@@ -1333,6 +1335,11 @@ static EFI_STATUS boot_entry_bump_counters(BootEntry *entry) {
         if (err != EFI_SUCCESS)
                 return log_error_status(err, "Error getting boot entry file info: %m");
 
+        /* If the boot entry file is marked read-only take this as a hint that the boot counter logic shall
+         * not be applied to it, and skip it. */
+        if (FLAGS_SET(file_info->Attribute, EFI_FILE_READ_ONLY))
+                goto read_only;
+
         /* And rename the file */
         strcpy16(file_info->FileName, entry->next_name);
         err = handle->SetInfo(handle, MAKE_GUID_PTR(EFI_FILE_INFO), file_info_size, file_info);
@@ -1357,6 +1364,10 @@ static EFI_STATUS boot_entry_bump_counters(BootEntry *entry) {
         }
 
         return EFI_SUCCESS;
+
+read_only:
+        log_debug("Boot entry '%ls' is read-only, skipping boot counter logic.", old_path);
+        return EFI_SUCCESS;
 }
 
 static EFI_STATUS call_image_start(const BootEntry *entry, EFI_FILE *root_dir, EFI_HANDLE parent_image);