From: Lennart Poettering Date: Mon, 13 Jul 2026 13:56:36 +0000 (+0200) Subject: boot: skip boot counter logic for entries marked read-only X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de39ad2cfefc4369ebcf9805afe02dc82582e8de;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/boot/boot.c b/src/boot/boot.c index c2f7e9b5008..e62df180910 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -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);