Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi: libstub: Clone memcmp() into the stub

We will no longer be able to call into the kernel image once we merge
the decompressor with the EFI stub, so we need our own implementation of
memcmp(). Let's add the one from lib/string.c and simplify it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

+19 -13
-1
arch/arm64/kernel/image-vars.h
··· 21 21 * linked at. The routines below are all implemented in assembler in a 22 22 * position independent manner 23 23 */ 24 - PROVIDE(__efistub_memcmp = __pi_memcmp); 25 24 PROVIDE(__efistub_memchr = __pi_memchr); 26 25 PROVIDE(__efistub_strlen = __pi_strlen); 27 26 PROVIDE(__efistub_strnlen = __pi_strnlen);
-1
arch/loongarch/kernel/image-vars.h
··· 7 7 8 8 #ifdef CONFIG_EFI_STUB 9 9 10 - __efistub_memcmp = memcmp; 11 10 __efistub_memchr = memchr; 12 11 __efistub_strcat = strcat; 13 12 __efistub_strcmp = strcmp;
-1
arch/riscv/kernel/image-vars.h
··· 23 23 * linked at. The routines below are all implemented in assembler in a 24 24 * position independent manner 25 25 */ 26 - __efistub_memcmp = memcmp; 27 26 __efistub_memchr = memchr; 28 27 __efistub_strlen = strlen; 29 28 __efistub_strnlen = strnlen;
+18
drivers/firmware/efi/libstub/intrinsics.c
··· 28 28 efi_bs_call(set_mem, dst, len, c & U8_MAX); 29 29 return dst; 30 30 } 31 + 32 + /** 33 + * memcmp - Compare two areas of memory 34 + * @cs: One area of memory 35 + * @ct: Another area of memory 36 + * @count: The size of the area. 37 + */ 38 + #undef memcmp 39 + int memcmp(const void *cs, const void *ct, size_t count) 40 + { 41 + const unsigned char *su1, *su2; 42 + int res = 0; 43 + 44 + for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) 45 + if ((res = *su1 - *su2) != 0) 46 + break; 47 + return res; 48 + }
+1 -10
drivers/firmware/efi/libstub/zboot.c
··· 47 47 log(L"error() called from decompressor library\n"); 48 48 } 49 49 50 - // Local version to avoid pulling in memcmp() 51 - static bool guids_eq(const efi_guid_t *a, const efi_guid_t *b) 52 - { 53 - const u32 *l = (u32 *)a; 54 - const u32 *r = (u32 *)b; 55 - 56 - return l[0] == r[0] && l[1] == r[1] && l[2] == r[2] && l[3] == r[3]; 57 - } 58 - 59 50 static efi_status_t __efiapi 60 51 load_file(efi_load_file_protocol_t *this, efi_device_path_protocol_t *rem, 61 52 bool boot_policy, unsigned long *bufsize, void *buffer) ··· 67 76 if (rem->type == EFI_DEV_MEDIA && 68 77 rem->sub_type == EFI_DEV_MEDIA_VENDOR) { 69 78 vendor_dp = container_of(rem, struct efi_vendor_dev_path, header); 70 - if (!guids_eq(&vendor_dp->vendorguid, &LINUX_EFI_ZBOOT_MEDIA_GUID)) 79 + if (efi_guidcmp(vendor_dp->vendorguid, LINUX_EFI_ZBOOT_MEDIA_GUID)) 71 80 return EFI_NOT_FOUND; 72 81 73 82 decompress = true;