From f4dc1bc9f0ad0ee1d23aa185a4e8d9e904e6d88e Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Sat, 27 Mar 2021 10:56:07 +0200 Subject: efi_loader: Cleanup get_var duplication get_var() is defined statically in efi_bootmgr.c and doesn't properly check a buffer allocation. Remove it completely and use the exported function from efi_var_common.c that does the same thing Signed-off-by: Ilias Apalodimas Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_bootmgr.c | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 46c8011344b..1fe19237f9a 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -30,38 +30,6 @@ static const struct efi_runtime_services *rs; * should do normal or recovery boot. */ -/** - * get_var() - get UEFI variable - * - * It is the caller's duty to free the returned buffer. - * - * @name: name of variable - * @vendor: vendor GUID of variable - * @size: size of allocated buffer - * Return: buffer with variable data or NULL - */ -static void *get_var(u16 *name, const efi_guid_t *vendor, - efi_uintn_t *size) -{ - efi_status_t ret; - void *buf = NULL; - - *size = 0; - ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); - if (ret == EFI_BUFFER_TOO_SMALL) { - buf = malloc(*size); - ret = efi_get_variable_int(name, vendor, NULL, size, buf, NULL); - } - - if (ret != EFI_SUCCESS) { - free(buf); - *size = 0; - return NULL; - } - - return buf; -} - /** * try_load_entry() - try to load image for boot option * @@ -89,7 +57,7 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle, varname[6] = hexmap[(n & 0x00f0) >> 4]; varname[7] = hexmap[(n & 0x000f) >> 0]; - load_option = get_var(varname, &efi_global_variable_guid, &size); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); if (!load_option) return EFI_LOAD_ERROR; @@ -210,7 +178,7 @@ efi_status_t efi_bootmgr_load(efi_handle_t *handle, void **load_options) } /* BootOrder */ - bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size); + bootorder = efi_get_var(L"BootOrder", &efi_global_variable_guid, &size); if (!bootorder) { log_info("BootOrder not defined\n"); ret = EFI_NOT_FOUND; -- cgit v1.3.1 From dd40cf6f1fa4a6828de19c3479934ed7409af303 Mon Sep 17 00:00:00 2001 From: Sughosh Ganu Date: Wed, 7 Apr 2021 17:23:31 +0530 Subject: efi_loader: Kconfig: Select IMAGE_SIGN_INFO when capsule authentication is enabled Enable building of the crypto helper functions used during capsule authentication by selecting IMAGE_SIGN_INFO. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index e44f004f3f8..0b99d7c7749 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -173,6 +173,7 @@ config EFI_CAPSULE_AUTHENTICATE select X509_CERTIFICATE_PARSER select PKCS7_MESSAGE_PARSER select PKCS7_VERIFY + select IMAGE_SIGN_INFO default n help Select this option if you want to enable capsule -- cgit v1.3.1 From 5c3de47caa8163955b0df4761b7fb1a253aae1e8 Mon Sep 17 00:00:00 2001 From: Sughosh Ganu Date: Thu, 8 Apr 2021 12:30:55 +0530 Subject: efi_loader: efi_esrt: Fix the build warning for 32 bit systems MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the build warning when building for 32 bit systems by using the length modifier for size_t. lib/efi_loader/efi_esrt.c: In function ‘efi_esrt_populate’: include/efi_loader.h:126:8: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 8 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt --- lib/efi_loader/efi_esrt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c index 947bdb5e95f..8815e56e156 100644 --- a/lib/efi_loader/efi_esrt.c +++ b/lib/efi_loader/efi_esrt.c @@ -341,7 +341,7 @@ efi_status_t efi_esrt_populate(void) return EFI_SUCCESS; } - EFI_PRINT("ESRT populate esrt from (%ld) available FMP handles\n", + EFI_PRINT("ESRT populate esrt from (%zd) available FMP handles\n", no_handles); /* -- cgit v1.3.1 From 7631c9d0a4796e3c79b731c072720f2b5b217053 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 8 Apr 2021 12:15:26 +0200 Subject: efi_loader: use correct printf codes For printing u32 use %u not %d. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_esrt.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c index 8815e56e156..a750164bc4c 100644 --- a/lib/efi_loader/efi_esrt.c +++ b/lib/efi_loader/efi_esrt.c @@ -120,8 +120,8 @@ efi_status_t efi_esrt_allocate_install(u32 num_entries) (void **)&new_esrt); if (ret != EFI_SUCCESS) { - EFI_PRINT("ESRT cannot allocate memory for %d entries (%d bytes)\n", - num_entries, efi_esrt_entries_to_size(num_entries)); + EFI_PRINT("ESRT cannot allocate memory for %u entries (%u bytes)\n", + num_entries, size); return ret; } @@ -180,7 +180,7 @@ struct efi_system_resource_entry *esrt_find_entry(efi_guid_t *img_fw_class) /* Check if the image with img_fw_class is already in the ESRT. */ for (u32 idx = 0; idx < filled_entries; idx++) { if (!guidcmp(&entry[idx].fw_class, img_fw_class)) { - EFI_PRINT("ESRT found entry for image %pUl at index %d\n", + EFI_PRINT("ESRT found entry for image %pUl at index %u\n", img_fw_class, idx); return &entry[idx]; } @@ -202,7 +202,7 @@ struct efi_system_resource_entry *esrt_find_entry(efi_guid_t *img_fw_class) */ esrt->fw_resource_count++; entry[filled_entries].fw_class = *img_fw_class; - EFI_PRINT("ESRT allocated new entry for image %pUl at index %d\n", + EFI_PRINT("ESRT allocated new entry for image %pUl at index %u\n", img_fw_class, filled_entries); return &entry[filled_entries]; @@ -363,7 +363,7 @@ efi_status_t efi_esrt_populate(void) &handler); if (ret != EFI_SUCCESS) { - EFI_PRINT("ESRT Unable to find FMP handle (%d)\n", + EFI_PRINT("ESRT Unable to find FMP handle (%u)\n", idx); goto out; } @@ -414,7 +414,7 @@ efi_status_t efi_esrt_populate(void) EFI_CALL(efi_free_pool(img_info)); } - EFI_PRINT("ESRT create table with %d entries\n", num_entries); + EFI_PRINT("ESRT create table with %u entries\n", num_entries); /* * Allocate an ESRT with the sufficient number of entries to accommodate * all the FMPs in the system. @@ -435,7 +435,7 @@ efi_status_t efi_esrt_populate(void) &handler)); if (ret != EFI_SUCCESS) { - EFI_PRINT("ESRT unable to find FMP handle (%d)\n", + EFI_PRINT("ESRT unable to find FMP handle (%u)\n", idx); break; } -- cgit v1.3.1 From 8c4488677fdf27b8f8aae9ddcc0041205196f5c3 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 8 Apr 2021 09:15:52 +0200 Subject: efi_loader: esrt: wrong type for LocateHandleBuffer() efi_locate_handle_buffer() expects no_handles to be of type efi_uintn_t *. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_esrt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c index a750164bc4c..40f53260e4d 100644 --- a/lib/efi_loader/efi_esrt.c +++ b/lib/efi_loader/efi_esrt.c @@ -316,7 +316,7 @@ efi_status_t efi_esrt_populate(void) { efi_handle_t *base_handle = NULL; efi_handle_t *it_handle; - size_t no_handles = 0; + efi_uintn_t no_handles = 0; struct efi_firmware_management_protocol *fmp; efi_status_t ret; u32 num_entries = 0; -- cgit v1.3.1 From f8cd72d1ac6aac8cfa48777b5c0681ee2f9e3671 Mon Sep 17 00:00:00 2001 From: Ilias Apalodimas Date: Tue, 30 Mar 2021 00:42:36 +0300 Subject: efi_loader: Change ptr arithmetics tcg eventlog buffer Although ptr arithmetics are allowed with extensions in gcc, they are not allowed by the C spec. So switch to (void *)(uintptr_t) instead Signed-off-by: Ilias Apalodimas Reviewed-by: Alexandru Gagniuc --- lib/efi_loader/efi_tcg2.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index 09046844c72..ed86a220fbd 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -176,13 +176,14 @@ static efi_status_t tcg2_agile_log_append(u32 pcr_index, u32 event_type, struct tpml_digest_values *digest_list, u32 size, u8 event[]) { - void *log = event_log.buffer + event_log.pos; + void *log = (void *)((uintptr_t)event_log.buffer + event_log.pos); size_t pos; int i; u32 event_size; if (event_log.get_event_called) - log = event_log.final_buffer + event_log.final_pos; + log = (void *)((uintptr_t)event_log.final_buffer + + event_log.final_pos); /* * size refers to the length of event[] only, we need to check against @@ -197,24 +198,24 @@ static efi_status_t tcg2_agile_log_append(u32 pcr_index, u32 event_type, put_unaligned_le32(pcr_index, log); pos = offsetof(struct tcg_pcr_event2, event_type); - put_unaligned_le32(event_type, log + pos); + put_unaligned_le32(event_type, (void *)((uintptr_t)log + pos)); pos = offsetof(struct tcg_pcr_event2, digests); /* count */ - put_unaligned_le32(digest_list->count, log + pos); + put_unaligned_le32(digest_list->count, (void *)((uintptr_t)log + pos)); pos += offsetof(struct tpml_digest_values, digests); for (i = 0; i < digest_list->count; i++) { u16 hash_alg = digest_list->digests[i].hash_alg; u8 *digest = (u8 *)&digest_list->digests[i].digest; - put_unaligned_le16(hash_alg, log + pos); + put_unaligned_le16(hash_alg, (void *)((uintptr_t)log + pos)); pos += offsetof(struct tpmt_ha, digest); - memcpy(log + pos, digest, alg_to_len(hash_alg)); + memcpy((void *)((uintptr_t)log + pos), digest, alg_to_len(hash_alg)); pos += alg_to_len(hash_alg); } - put_unaligned_le32(size, log + pos); + put_unaligned_le32(size, (void *)((uintptr_t)log + pos)); pos += sizeof(u32); /* tcg_pcr_event2 event_size*/ - memcpy(log + pos, event, size); + memcpy((void *)((uintptr_t)log + pos), event, size); pos += size; /* make sure the calculated buffer is what we checked against */ @@ -1046,7 +1047,7 @@ static efi_status_t efi_init_event_log(void) put_unaligned_le32(0, &event_header->pcr_index); put_unaligned_le32(EV_NO_ACTION, &event_header->event_type); memset(&event_header->digest, 0, sizeof(event_header->digest)); - ret = create_specid_event(dev, event_log.buffer + sizeof(*event_header), + ret = create_specid_event(dev, (void *)((uintptr_t)event_log.buffer + sizeof(*event_header)), &spec_event_size); if (ret != EFI_SUCCESS) goto out; -- cgit v1.3.1