eficonfig: add UEFI Secure Boot key maintenance interface
v6 cover eficonfig: add UEFI Secure Boot key maintenance interface
This series adds the UEFI Secure Boot key maintenance interface to the eficonfig command.
User can enroll and delete the PK, KEK, db and dbx.
Source code can be cloned with:
$ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git -b kojima/eficonfig_sbkey_v6
Masahisa Kojima (5):
eficonfig: refactor eficonfig_select_file_handler()
eficonfig: expose append entry function
eficonfig: refactor change boot order implementation
eficonfig: add UEFI Secure Boot Key enrollment interface
eficonfig: add "Show/Delete Signature Database" menu entry
cmd/Makefile | 5 + cmd/eficonfig.c | 177 +++-- cmd/eficonfig_sbkey.c | 727 ++++++++++++++++++ include/efi_config.h | 10 + .../py/tests/test_eficonfig/test_eficonfig.py | 1 + 5 files changed, 835 insertions(+), 85 deletions(-) create mode 100644 cmd/eficonfig_sbkey.c
Signature · 1 line
2.17.1
PATCH v6 1/5 eficonfig: refactor eficonfig_select_file_handler()
eficonfig_select_file_handler() is commonly used to select the file. eficonfig_display_select_file_option() intends to add the additional menu mainly to clear the selected file information. eficonfig_display_select_file_option() is not necessary for the file selection process, so it should be outside of eficonfig_select_file_handler().
---
No change since v2
newly created in v2
cmd/eficonfig.c | 13 +++++-------- test/py/tests/test_eficonfig/test_eficonfig.py | 1 + 2 files changed, 6 insertions(+), 8 deletions(-)
cmd/eficonfig.c +5 -8
@@ -968,7 +968,7 @@ efi_status_t eficonfig_process_clear_file_selection(void *data) }static struct eficonfig_item select_file_menu_items[] = { - {"Select File" , eficonfig_process_select_file}, + {"Select File" , eficonfig_select_file_handler}, {"Clear" , eficonfig_process_clear_file_selection}, {"Quit" , eficonfig_process_quit}, };
@@ -980,12 +980,13 @@ static struct eficonfig_item select_file_menu_items[] = {* @file_info: pointer to the file information structure * Return: status code */ -efi_status_t eficonfig_display_select_file_option (struct eficonfig_select_file_info *file_info) +efi_status_t eficonfig_display_select_file_option (void *data) {efi_status_t ret;struct efimenu *efi_menu; - select_file_menu_items[1 ].data = file_info; + select_file_menu_items[0 ].data = data; + select_file_menu_items[1 ].data = data; efi_menu =eficonfig_create_fixed_menu (select_file_menu_items,ARRAY_SIZE (select_file_menu_items));if (!efi_menu)
@@ -1016,10 +1017,6 @@ efi_status_t eficonfig_select_file_handler(void *data)struct eficonfig_select_file_info *tmp =NULL ;struct eficonfig_select_file_info *file_info = data; - ret =eficonfig_display_select_file_option (file_info); -if (ret !=EFI_SUCCESS ) -return ret; - tmp =calloc (1 ,sizeof (struct eficonfig_select_file_info ));if (!tmp)return EFI_OUT_OF_RESOURCES ;
@@ -1284,7 +1281,7 @@ static efi_status_t prepare_file_selection_entry(struct efimenu *efi_menu, charutf8_utf16_strcpy (&p, devname);u16_strlcat (file_name, file_info->current_path, len); ret =create_boot_option_entry (efi_menu, title, file_name, - eficonfig_select_file_handler, file_info); + eficonfig_display_select_file_option, file_info); out:free (devname);free (file_name);
test/py/tests/test_eficonfig/test_eficonfig.py +1 -0
@@ -349,6 +349,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): press_up_down_enter_and_wait(0, 1, True, 'Quit') press_up_down_enter_and_wait(0, 0, True, 'No block device found!') press_escape_key(False) + press_escape_key(False) check_current_is_maintenance_menu() # Return to U-Boot console press_escape_key(True)
Signature · 1 line
2.17.1
PATCH v6 2/5 eficonfig: expose append entry function
In reply to Masahisa KojimaThis commit exposes the eficonfig menu entry append function.
---
No change since v2
newly created in v2
cmd/eficonfig.c | 32 +++++++++++++++++--------------- include/efi_config.h | 5 +++++ 2 files changed, 22 insertions(+), 15 deletions(-)
cmd/eficonfig.c +17 -15
@@ -263,7 +263,7 @@ efi_status_t eficonfig_process_quit(void *data) }/** -* append_entry() - append menu item +* eficonfig_append_menu_entry() - append menu item * * @efi_menu: pointer to the efimenu structure * @title: pointer to the entry title
@@ -271,8 +271,9 @@ efi_status_t eficonfig_process_quit(void *data)* @data: pointer to the data to be passed to each entry callback * Return: status code */ -static efi_status_t append_entry (struct efimenu *efi_menu, -char *title,eficonfig_entry_func func,void *data) +efi_status_t eficonfig_append_menu_entry (struct efimenu *efi_menu, +char *title,eficonfig_entry_func func, +void *data) {struct eficonfig_entry *entry;
@@ -295,12 +296,12 @@ static efi_status_t append_entry(struct efimenu *efi_menu, }/** -* append_quit_entry() - append quit entry +* eficonfig_append_quit_entry() - append quit entry * * @efi_menu: pointer to the efimenu structure * Return: status code */ -static efi_status_t append_quit_entry (struct efimenu *efi_menu) +efi_status_t eficonfig_append_quit_entry (struct efimenu *efi_menu) {char *title;efi_status_t ret;
@@ -309,7 +310,7 @@ static efi_status_t append_quit_entry(struct efimenu *efi_menu)if (!title)return EFI_OUT_OF_RESOURCES ; - ret =append_entry (efi_menu, title, eficonfig_process_quit,NULL ); + ret =eficonfig_append_menu_entry (efi_menu, title, eficonfig_process_quit,NULL );if (ret !=EFI_SUCCESS )free (title);
@@ -341,7 +342,7 @@ void *eficonfig_create_fixed_menu(const struct eficonfig_item *items, int count)if (!title) goto out; - ret =append_entry (efi_menu, title, iter->func, iter->data); + ret =eficonfig_append_menu_entry (efi_menu, title, iter->func, iter->data);if (ret !=EFI_SUCCESS ) {free (title); goto out;
@@ -634,14 +635,15 @@ static efi_status_t eficonfig_select_volume(struct eficonfig_select_file_info *f info->v = v; info->dp = device_path; info->file_info = file_info; - ret =append_entry (efi_menu, devname, eficonfig_volume_selected, info); + ret =eficonfig_append_menu_entry (efi_menu, devname, eficonfig_volume_selected, + info);if (ret !=EFI_SUCCESS ) {free (info); goto out; } } - ret =append_quit_entry (efi_menu); + ret =eficonfig_append_quit_entry (efi_menu);if (ret !=EFI_SUCCESS ) goto out;
@@ -745,8 +747,8 @@ eficonfig_create_file_entry(struct efimenu *efi_menu, u32 count, (int (*)(const void *, const void *))sort_file);for (i =0 ; i < entry_num; i++) { - ret =append_entry (efi_menu, tmp_infos[i]->file_name, - eficonfig_file_selected, tmp_infos[i]); + ret =eficonfig_append_menu_entry (efi_menu, tmp_infos[i]->file_name, + eficonfig_file_selected, tmp_infos[i]);if (ret !=EFI_SUCCESS ) goto out; }
@@ -815,7 +817,7 @@ static efi_status_t eficonfig_select_file(struct eficonfig_select_file_info *filif (ret !=EFI_SUCCESS ) goto err; - ret =append_quit_entry (efi_menu); + ret =eficonfig_append_quit_entry (efi_menu);if (ret !=EFI_SUCCESS ) goto err;
@@ -1218,7 +1220,7 @@ static efi_status_t create_boot_option_entry(struct efimenu *efi_menu, char *titutf16_utf8_strcpy (&p, val); } -return append_entry (efi_menu, buf, func, data); +return eficonfig_append_menu_entry (efi_menu, buf, func, data); }/**
@@ -1677,7 +1679,7 @@ static efi_status_t eficonfig_add_boot_selection_entry(struct efimenu *efi_menu,utf16_utf8_strcpy (&p, lo.label); info->boot_index = boot_index; info->selected = selected; - ret =append_entry (efi_menu, buf, eficonfig_process_boot_selected, info); + ret =eficonfig_append_menu_entry (efi_menu, buf, eficonfig_process_boot_selected, info);if (ret !=EFI_SUCCESS ) {free (load_option);free (info);
@@ -1736,7 +1738,7 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected)break ; } - ret =append_quit_entry (efi_menu); + ret =eficonfig_append_quit_entry (efi_menu);if (ret !=EFI_SUCCESS ) goto out;
include/efi_config.h +5 -0
@@ -95,4 +95,9 @@ efi_status_t eficonfig_get_unused_bootoption(u16 *buf,efi_status_t eficonfig_append_bootorder (u16 index);efi_status_t eficonfig_generate_media_device_boot_option (void ); +efi_status_t eficonfig_append_menu_entry (struct efimenu *efi_menu, +char *title,eficonfig_entry_func func, +void *data); +efi_status_t eficonfig_append_quit_entry (struct efimenu *efi_menu); +#endif
Signature · 1 line
2.17.1
PATCH v6 3/5 eficonfig: refactor change boot order implementation
In reply to Masahisa KojimaThis commit refactors change boot order implementation to use 'eficonfig_entry' structure.
---
No update since v5
Changes in v5:
- remove direct access mode
newly created in v4
cmd/eficonfig.c | 129 +++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 62 deletions(-)
cmd/eficonfig.c +67 -62
@@ -93,20 +93,14 @@ struct eficonfig_boot_selection_data { };/** -* struct eficonfig_boot_order - structure to be used to update BootOrder variable +* struct eficonfig_boot_order_data - structure to be used to update BootOrder variable * -* @num: index in the menu entry -* @description: pointer to the description string * @boot_index: boot option index * @active: flag to include the boot option into BootOrder variable -* @list: list structure */ -struct eficonfig_boot_order { -u32 num; -u16 *description; +struct eficonfig_boot_order_data {u32 boot_index;bool active; -struct list_head list; };/**
@@ -1814,7 +1808,7 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) {bool reverse;struct list_head *pos, *n; -struct eficonfig_boot_order *entry; +struct eficonfig_entry *entry; printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION"\n ** Change Boot Order **\n"
@@ -1830,7 +1824,7 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu)/* draw boot option list */ list_for_each_safe (pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); reverse = (entry->num == efi_menu->active);printf (ANSI_CURSOR_POSITION , entry->num +4 ,7 );
@@ -1839,13 +1833,13 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu)puts (ANSI_COLOR_REVERSE );if (entry->num < efi_menu->count -2 ) { -if (entry->active) +if (((struct eficonfig_boot_order_data *)entry->data)->active)printf ("[*] " );else printf ("[ ] " ); } -printf ("%ls" , entry->description); +printf ("%s" , entry->title);if (reverse)puts (ANSI_COLOR_RESET );
@@ -1862,9 +1856,8 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) {int esc =0 ;struct list_head *pos, *n; -struct eficonfig_boot_order *tmp;enum bootmenu_key key =KEY_NONE ; -struct eficonfig_boot_order *entry; +struct eficonfig_entry *entry, *tmp;while (1 ) {bootmenu_loop (NULL , &key, &esc);
@@ -1873,11 +1866,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)case KEY_PLUS :if (efi_menu->active >0 ) {list_for_each_safe (pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list);if (entry->num == efi_menu->active)break ; } - tmp = list_entry(pos->prev, struct eficonfig_boot_order, list); + tmp = list_entry(pos->prev, struct eficonfig_entry, list); entry->num--; tmp->num++;list_del (&tmp->list);
@@ -1891,11 +1884,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)case KEY_MINUS :if (efi_menu->active < efi_menu->count -3 ) {list_for_each_safe (pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list);if (entry->num == efi_menu->active)break ; } - tmp = list_entry(pos->next, struct eficonfig_boot_order, list); + tmp = list_entry(pos->next, struct eficonfig_entry, list); entry->num++; tmp->num--;list_del (&entry->list);
@@ -1921,9 +1914,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)case KEY_SPACE :if (efi_menu->active < efi_menu->count -2 ) {list_for_each_safe (pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list);if (entry->num == efi_menu->active) { - entry->active = entry->active ? false : true; +struct eficonfig_boot_order_data *data = entry->data; + + data->active = data->active ? false : true;return EFI_NOT_READY ; } }
@@ -1949,12 +1944,13 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu)static efi_status_t eficonfig_add_change_boot_order_entry (struct efimenu *efi_menu,u32 boot_index,bool active) { +char *title, *p;efi_status_t ret;efi_uintn_t size;void *load_option;struct efi_load_option lo;u16 varname[] =u"Boot####" ; -struct eficonfig_boot_order *entry; +struct eficonfig_boot_order_data *data;efi_create_indexed_name (varname,sizeof (varname),"Boot" , boot_index); load_option =efi_get_var (varname, &efi_global_variable_guid, &size);
@@ -1962,31 +1958,38 @@ static efi_status_t eficonfig_add_change_boot_order_entry(struct efimenu *efi_mereturn EFI_SUCCESS ; ret =efi_deserialize_load_option (&lo, load_option, &size); -if (ret !=EFI_SUCCESS ) { -free (load_option); -return ret; +if (ret !=EFI_SUCCESS ) + goto out; + + data =calloc (1 ,sizeof (struct eficonfig_boot_order_data )); +if (!data) { + ret =EFI_OUT_OF_RESOURCES ; + goto out; } - entry =calloc (1 ,sizeof (struct eficonfig_boot_order )); -if (!entry) { -free (load_option); -return EFI_OUT_OF_RESOURCES ; + title =calloc (1 ,utf16_utf8_strlen (lo.label) +1 ); +if (!title) { +free (data); + ret =EFI_OUT_OF_RESOURCES ; + goto out; } + p = title; +utf16_utf8_strcpy (&p, lo.label); - entry->description =u16_strdup (lo.label); -if (!entry->description) { -free (load_option); -free (entry); -return EFI_OUT_OF_RESOURCES ; + data->boot_index = boot_index; + data->active = active; + + ret =eficonfig_append_menu_entry (efi_menu, title,NULL , data); +if (ret !=EFI_SUCCESS ) { +free (data); +free (title); + goto out; } - entry->num = efi_menu->count++; - entry->boot_index = boot_index; - entry->active = active; -list_add_tail (&entry->list, &efi_menu->list); +out:free (load_option); -return EFI_SUCCESS ; +return ret; }/**
@@ -2001,8 +2004,8 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi u16 *bootorder, efi_uintn_t num) {u32 i; +char *title;efi_status_t ret; -struct eficonfig_boot_order *entry;/* list the load option in the order of BootOrder variable */ for (i =0 ; i < num; i++) {
@@ -2029,27 +2032,25 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi }/* add "Save" and "Quit" entries */ - entry =calloc (1 ,sizeof (struct eficonfig_boot_order )); -if (!entry) + title =strdup ("Save" ); +if (!title) { + ret =EFI_OUT_OF_RESOURCES ; goto out; + } - entry->num = efi_menu->count++; - entry->description =u16_strdup (u"Save" ); -list_add_tail (&entry->list, &efi_menu->list); - - entry =calloc (1 ,sizeof (struct eficonfig_boot_order )); -if (!entry) + ret =eficonfig_append_menu_entry (efi_menu, title,NULL ,NULL ); +if (ret !=EFI_SUCCESS ) goto out; - entry->num = efi_menu->count++; - entry->description =u16_strdup (u"Quit" ); -list_add_tail (&entry->list, &efi_menu->list); + ret =eficonfig_append_quit_entry (efi_menu); +if (ret !=EFI_SUCCESS ) + goto out; efi_menu->active =0 ;return EFI_SUCCESS ; out: -return EFI_OUT_OF_RESOURCES ; +return ret; }/**
@@ -2065,7 +2066,7 @@ static efi_status_t eficonfig_process_change_boot_order(void *data)efi_status_t ret;efi_uintn_t num, size;struct list_head *pos, *n; -struct eficonfig_boot_order *entry; +struct eficonfig_entry *entry;struct efimenu *efi_menu; efi_menu =calloc (1 ,sizeof (struct efimenu ));
@@ -2096,9 +2097,16 @@ static efi_status_t eficonfig_process_change_boot_order(void *data)/* create new BootOrder */ count =0 ;list_for_each_safe (pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); -if (entry->active) - new_bootorder[count++] = entry->boot_index; +struct eficonfig_boot_order_data *data; + + entry = list_entry(pos, struct eficonfig_entry, list); +/* exit the loop when iteration reaches "Save" */ +if (!strncmp (entry->title,"Save" ,strlen ("Save" ))) +break ; + + data = entry->data; +if (data->active) + new_bootorder[count++] = data->boot_index; } size = count *sizeof (u16);
@@ -2117,15 +2125,12 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) } } out: +free (bootorder);list_for_each_safe (pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); -list_del (&entry->list); -free (entry->description); -free (entry); + entry = list_entry(pos, struct eficonfig_entry, list); +free (entry->data); } - -free (bootorder); -free (efi_menu); +eficonfig_destroy (efi_menu);/* to stay the parent menu */ ret = (ret ==EFI_ABORTED ) ?EFI_NOT_READY : ret;
Signature · 1 line
2.17.1
PATCH v6 4/5 eficonfig: add UEFI Secure Boot Key enrollment interface
In reply to Masahisa KojimaThis commit adds the menu-driven UEFI Secure Boot Key enrollment interface. User can enroll the PK, KEK, db and dbx by selecting EFI Signature Lists file. After the PK is enrolled, UEFI Secure Boot is enabled and EFI Signature Lists file must be signed by KEK or PK.
---
Changes in v6:
- use efi_secure_boot_enabled()
- replace with WIN_CERT_REVISION_2_0 from pe.h
- call efi_build_signature_store() to check the valid EFI Signature List
- update comment
Changes in v4:
- add CONFIG_EFI_MM_COMM_TEE dependency
- fix error handling
Changes in v3:
- fix error handling
Changes in v2:
- allow to enroll .esl file
- fix typos
- add function comments
cmd/Makefile | 5 + cmd/eficonfig.c | 3 + cmd/eficonfig_sbkey.c | 333 ++++++++++++++++++++++++++++++++++++++++++ include/efi_config.h | 5 + 4 files changed, 346 insertions(+) create mode 100644 cmd/eficonfig_sbkey.c
cmd/Makefile +5 -0
@@ -66,6 +66,11 @@ obj-$(CONFIG_CMD_EEPROM) += eeprom.o obj-$(CONFIG_EFI) += efi.o obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o +ifdef CONFIG_CMD_EFICONFIG +ifdef CONFIG_EFI_MM_COMM_TEE +obj-$(CONFIG_EFI_SECURE_BOOT) += eficonfig_sbkey.o +endif +endif obj-$(CONFIG_CMD_ELF) += elf.o obj-$(CONFIG_CMD_EROFS) += erofs.o obj-$(CONFIG_HUSH_PARSER) += exit.o
cmd/eficonfig.c +3 -0
@@ -2447,6 +2447,9 @@ static const struct eficonfig_item maintenance_menu_items[] = { {"Edit Boot Option", eficonfig_process_edit_boot_option}, {"Change Boot Order", eficonfig_process_change_boot_order}, {"Delete Boot Option", eficonfig_process_delete_boot_option}, +#if (CONFIG_IS_ENABLED(EFI_SECURE_BOOT) && CONFIG_IS_ENABLED(EFI_MM_COMM_TEE)) + {"Secure Boot Configuration", eficonfig_process_secure_boot_config}, +#endif {"Quit", eficonfig_process_quit}, };
cmd/eficonfig_sbkey.c new file +333 -0
333 lines not on this page · raw message
include/efi_config.h +5 -0
@@ -99,5 +99,10 @@ efi_status_t eficonfig_append_menu_entry(struct efimenu *efi_menu, char *title, eficonfig_entry_func func, void *data);efi_status_t eficonfig_append_quit_entry (struct efimenu *efi_menu); +void *eficonfig_create_fixed_menu (const struct eficonfig_item *items,int count); + +#ifdef CONFIG_EFI_SECURE_BOOT +efi_status_t eficonfig_process_secure_boot_config (void *data); +#endif #endif
Signature · 1 line
2.17.1
Hi,
I intended to send v7, but I'm mistaken to send an older version. Please ignore this series, I will send v7 soon.
Sorry for the spam.
Regards,
Masahisa Kojima
Quoted 26 lines · Masahisa Kojima
This series adds the UEFI Secure Boot key maintenance interface to the eficonfig command.
User can enroll and delete the PK, KEK, db and dbx.Source code can be cloned with:
$ git clone https://git.linaro.org/people/masahisa.kojima/u-boot.git -b kojima/eficonfig_sbkey_v6Masahisa Kojima (5):
eficonfig: refactoreficonfig_select_file_handler()
eficonfig: expose append entry function
eficonfig: refactor change boot order implementation
eficonfig: add UEFI Secure Boot Key enrollment interface
eficonfig: add "Show/Delete Signature Database" menu entrycmd/Makefile | 5 + cmd/eficonfig.c | 177 +++-- cmd/eficonfig_sbkey.c | 727 ++++++++++++++++++ include/efi_config.h | 10 + .../py/tests/test_eficonfig/test_eficonfig.py | 1 + 5 files changed, 835 insertions(+), 85 deletions(-) create mode 100644 cmd/eficonfig_sbkey.c--
2.17.1