boot: skip boot counter logic for entries marked read-only

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.
This commit is contained in:
Lennart Poettering
2026-07-13 15:56:36 +02:00
parent 38f63d28c2
commit de39ad2cfe

View 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);