mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-03-06 12:58:22 +03:00
boot: Fix boot counting for XBOOTLDR entries
We were passing the dir handle for the ESP to config_entry_bump_counters(), which will obviously fail if the entry actually resides on the XBOOTLDR partition. Fixes: #28637 (cherry picked from commit 66fd078ba89e90e8aeba6edac52d20456fc2cd5d) (cherry picked from commit b44bd7d7a88a1ca7a03aebbf5d791f3f99789fb9)
This commit is contained in:
parent
4953edf2fb
commit
2d58262118
@ -1355,7 +1355,7 @@ static void config_entry_parse_tries(
|
||||
suffix);
|
||||
}
|
||||
|
||||
static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
|
||||
static EFI_STATUS config_entry_bump_counters(ConfigEntry *entry) {
|
||||
_cleanup_free_ char16_t* old_path = NULL, *new_path = NULL;
|
||||
_cleanup_(file_closep) EFI_FILE *handle = NULL;
|
||||
_cleanup_free_ EFI_FILE_INFO *file_info = NULL;
|
||||
@ -1363,34 +1363,39 @@ static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
|
||||
EFI_STATUS err;
|
||||
|
||||
assert(entry);
|
||||
assert(root_dir);
|
||||
|
||||
if (entry->tries_left < 0)
|
||||
return;
|
||||
return EFI_SUCCESS;
|
||||
|
||||
if (!entry->path || !entry->current_name || !entry->next_name)
|
||||
return;
|
||||
return EFI_SUCCESS;
|
||||
|
||||
_cleanup_(file_closep) EFI_FILE *root = NULL;
|
||||
err = open_volume(entry->device, &root);
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(err, "Error opening entry root path: %m");
|
||||
|
||||
old_path = xasprintf("%ls\\%ls", entry->path, entry->current_name);
|
||||
|
||||
err = root_dir->Open(root_dir, &handle, old_path, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL);
|
||||
err = root->Open(root, &handle, old_path, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0ULL);
|
||||
if (err != EFI_SUCCESS)
|
||||
return;
|
||||
return log_error_status(err, "Error opening boot entry: %m");
|
||||
|
||||
err = get_file_info_harder(handle, &file_info, &file_info_size);
|
||||
if (err != EFI_SUCCESS)
|
||||
return;
|
||||
return log_error_status(err, "Error getting boot entry file info: %m");
|
||||
|
||||
/* 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);
|
||||
if (err != EFI_SUCCESS) {
|
||||
log_error_status(err, "Failed to rename '%ls' to '%ls', ignoring: %m", old_path, entry->next_name);
|
||||
return;
|
||||
}
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(
|
||||
err, "Failed to rename '%ls' to '%ls', ignoring: %m", old_path, entry->next_name);
|
||||
|
||||
/* Flush everything to disk, just in case… */
|
||||
(void) handle->Flush(handle);
|
||||
err = handle->Flush(handle);
|
||||
if (err != EFI_SUCCESS)
|
||||
return log_error_status(err, "Error flushing boot entry file info: %m");
|
||||
|
||||
/* Let's tell the OS that we renamed this file, so that it knows what to rename to the counter-less name on
|
||||
* success */
|
||||
@ -1402,6 +1407,8 @@ static void config_entry_bump_counters(ConfigEntry *entry, EFI_FILE *root_dir) {
|
||||
free(entry->loader);
|
||||
entry->loader = TAKE_PTR(new_path);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static void config_entry_add_type1(
|
||||
@ -2721,7 +2728,7 @@ static EFI_STATUS run(EFI_HANDLE image) {
|
||||
continue;
|
||||
}
|
||||
|
||||
config_entry_bump_counters(entry, root_dir);
|
||||
(void) config_entry_bump_counters(entry);
|
||||
save_selected_entry(&config, entry);
|
||||
|
||||
/* Optionally, read a random seed off the ESP and pass it to the OS */
|
||||
|
Loading…
x
Reference in New Issue
Block a user