|
| 1 | +efi/libstub: Check return value of efi_parse_options |
| 2 | + |
| 3 | +jira LE-4066 |
| 4 | +Rebuild_History Non-Buildable kernel-4.18.0-553.72.1.el8_10 |
| 5 | +commit-author Arvind Sankar <nivedita@alum.mit.edu> |
| 6 | +commit 055042bedd4e0af8186266b189b81e73e708b82b |
| 7 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 8 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 9 | +ciq/ciq_backports/kernel-4.18.0-553.72.1.el8_10/055042be.failed |
| 10 | + |
| 11 | +efi_parse_options can fail if it is unable to allocate space for a copy |
| 12 | +of the command line. Check the return value to make sure it succeeded. |
| 13 | + |
| 14 | + Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> |
| 15 | +Link: https://lore.kernel.org/r/20200430182843.2510180-12-nivedita@alum.mit.edu |
| 16 | + Signed-off-by: Ard Biesheuvel <ardb@kernel.org> |
| 17 | +(cherry picked from commit 055042bedd4e0af8186266b189b81e73e708b82b) |
| 18 | + Signed-off-by: Jonathan Maple <jmaple@ciq.com> |
| 19 | + |
| 20 | +# Conflicts: |
| 21 | +# drivers/firmware/efi/libstub/arm-stub.c |
| 22 | +# drivers/firmware/efi/libstub/x86-stub.c |
| 23 | +diff --cc drivers/firmware/efi/libstub/arm-stub.c |
| 24 | +index 3658b6e086e5,c2484bf75c5d..000000000000 |
| 25 | +--- a/drivers/firmware/efi/libstub/arm-stub.c |
| 26 | ++++ b/drivers/firmware/efi/libstub/arm-stub.c |
| 27 | +@@@ -173,29 -207,41 +173,44 @@@ unsigned long efi_entry(void *handle, e |
| 28 | + |
| 29 | + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || |
| 30 | + IS_ENABLED(CONFIG_CMDLINE_FORCE) || |
| 31 | +- cmdline_size == 0) |
| 32 | +- efi_parse_options(CONFIG_CMDLINE); |
| 33 | ++ cmdline_size == 0) { |
| 34 | ++ status = efi_parse_options(CONFIG_CMDLINE); |
| 35 | ++ if (status != EFI_SUCCESS) { |
| 36 | ++ efi_err("Failed to parse options\n"); |
| 37 | ++ goto fail_free_cmdline; |
| 38 | ++ } |
| 39 | ++ } |
| 40 | + |
| 41 | +- if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) |
| 42 | +- efi_parse_options(cmdline_ptr); |
| 43 | ++ if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && cmdline_size > 0) { |
| 44 | ++ status = efi_parse_options(cmdline_ptr); |
| 45 | ++ if (status != EFI_SUCCESS) { |
| 46 | ++ efi_err("Failed to parse options\n"); |
| 47 | ++ goto fail_free_cmdline; |
| 48 | ++ } |
| 49 | ++ } |
| 50 | + |
| 51 | + - efi_info("Booting Linux Kernel...\n"); |
| 52 | + + pr_efi(sys_table, "Booting Linux Kernel...\n"); |
| 53 | + |
| 54 | + - si = setup_graphics(); |
| 55 | + + si = setup_graphics(sys_table); |
| 56 | + |
| 57 | + - status = handle_kernel_image(&image_addr, &image_size, |
| 58 | + + status = handle_kernel_image(sys_table, image_addr, &image_size, |
| 59 | + &reserve_addr, |
| 60 | + &reserve_size, |
| 61 | + dram_base, image); |
| 62 | + if (status != EFI_SUCCESS) { |
| 63 | +++<<<<<<< HEAD:drivers/firmware/efi/libstub/arm-stub.c |
| 64 | + + pr_efi_err(sys_table, "Failed to relocate kernel\n"); |
| 65 | + + goto fail_free_cmdline; |
| 66 | +++======= |
| 67 | ++ efi_err("Failed to relocate kernel\n"); |
| 68 | ++ goto fail_free_screeninfo; |
| 69 | +++>>>>>>> 055042bedd4e (efi/libstub: Check return value of efi_parse_options):drivers/firmware/efi/libstub/efi-stub.c |
| 70 | + } |
| 71 | + |
| 72 | + - efi_retrieve_tpm2_eventlog(); |
| 73 | + - |
| 74 | + /* Ask the firmware to clear memory on unclean shutdown */ |
| 75 | + - efi_enable_reset_attack_mitigation(); |
| 76 | + + efi_enable_reset_attack_mitigation(sys_table); |
| 77 | + |
| 78 | + - secure_boot = efi_get_secureboot(); |
| 79 | + + secure_boot = efi_get_secureboot(sys_table); |
| 80 | + |
| 81 | + /* |
| 82 | + * Unauthenticated device tree data is a security hazard, so ignore |
| 83 | +@@@ -259,73 -315,33 +274,82 @@@ |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + - install_memreserve_table(); |
| 88 | + + install_memreserve_table(sys_table); |
| 89 | + |
| 90 | + - status = allocate_new_fdt_and_exit_boot(handle, &fdt_addr, |
| 91 | + - efi_get_max_fdt_addr(dram_base), |
| 92 | + - initrd_addr, initrd_size, |
| 93 | + - cmdline_ptr, fdt_addr, fdt_size); |
| 94 | + - if (status != EFI_SUCCESS) |
| 95 | + - goto fail_free_initrd; |
| 96 | + + new_fdt_addr = fdt_addr; |
| 97 | + + status = allocate_new_fdt_and_exit_boot(sys_table, handle, |
| 98 | + + &new_fdt_addr, efi_get_max_fdt_addr(dram_base), |
| 99 | + + initrd_addr, initrd_size, cmdline_ptr, |
| 100 | + + fdt_addr, fdt_size); |
| 101 | + |
| 102 | + - efi_enter_kernel(image_addr, fdt_addr, fdt_totalsize((void *)fdt_addr)); |
| 103 | + - /* not reached */ |
| 104 | + + /* |
| 105 | + + * If all went well, we need to return the FDT address to the |
| 106 | + + * calling function so it can be passed to kernel as part of |
| 107 | + + * the kernel boot protocol. |
| 108 | + + */ |
| 109 | + + if (status == EFI_SUCCESS) |
| 110 | + + return new_fdt_addr; |
| 111 | + |
| 112 | + -fail_free_initrd: |
| 113 | + - efi_err("Failed to update FDT and exit boot services\n"); |
| 114 | + + pr_efi_err(sys_table, "Failed to update FDT and exit boot services\n"); |
| 115 | + |
| 116 | + - efi_free(initrd_size, initrd_addr); |
| 117 | + - efi_free(fdt_size, fdt_addr); |
| 118 | + + efi_free(sys_table, initrd_size, initrd_addr); |
| 119 | + + efi_free(sys_table, fdt_size, fdt_addr); |
| 120 | + |
| 121 | + fail_free_image: |
| 122 | +++<<<<<<< HEAD:drivers/firmware/efi/libstub/arm-stub.c |
| 123 | + + efi_free(sys_table, image_size, *image_addr); |
| 124 | + + efi_free(sys_table, reserve_size, reserve_addr); |
| 125 | + +fail_free_cmdline: |
| 126 | + + free_screen_info(sys_table, si); |
| 127 | + + efi_free(sys_table, cmdline_size, (unsigned long)cmdline_ptr); |
| 128 | +++======= |
| 129 | ++ efi_free(image_size, image_addr); |
| 130 | ++ efi_free(reserve_size, reserve_addr); |
| 131 | ++ fail_free_screeninfo: |
| 132 | ++ free_screen_info(si); |
| 133 | ++ fail_free_cmdline: |
| 134 | ++ efi_free(cmdline_size, (unsigned long)cmdline_ptr); |
| 135 | +++>>>>>>> 055042bedd4e (efi/libstub: Check return value of efi_parse_options):drivers/firmware/efi/libstub/efi-stub.c |
| 136 | + fail: |
| 137 | + - return status; |
| 138 | + + return EFI_ERROR; |
| 139 | + +} |
| 140 | + + |
| 141 | + +static int cmp_mem_desc(const void *l, const void *r) |
| 142 | + +{ |
| 143 | + + const efi_memory_desc_t *left = l, *right = r; |
| 144 | + + |
| 145 | + + return (left->phys_addr > right->phys_addr) ? 1 : -1; |
| 146 | + +} |
| 147 | + + |
| 148 | + +/* |
| 149 | + + * Returns whether region @left ends exactly where region @right starts, |
| 150 | + + * or false if either argument is NULL. |
| 151 | + + */ |
| 152 | + +static bool regions_are_adjacent(efi_memory_desc_t *left, |
| 153 | + + efi_memory_desc_t *right) |
| 154 | + +{ |
| 155 | + + u64 left_end; |
| 156 | + + |
| 157 | + + if (left == NULL || right == NULL) |
| 158 | + + return false; |
| 159 | + + |
| 160 | + + left_end = left->phys_addr + left->num_pages * EFI_PAGE_SIZE; |
| 161 | + + |
| 162 | + + return left_end == right->phys_addr; |
| 163 | + +} |
| 164 | + + |
| 165 | + +/* |
| 166 | + + * Returns whether region @left and region @right have compatible memory type |
| 167 | + + * mapping attributes, and are both EFI_MEMORY_RUNTIME regions. |
| 168 | + + */ |
| 169 | + +static bool regions_have_compatible_memory_type_attrs(efi_memory_desc_t *left, |
| 170 | + + efi_memory_desc_t *right) |
| 171 | + +{ |
| 172 | + + static const u64 mem_type_mask = EFI_MEMORY_WB | EFI_MEMORY_WT | |
| 173 | + + EFI_MEMORY_WC | EFI_MEMORY_UC | |
| 174 | + + EFI_MEMORY_RUNTIME; |
| 175 | + + |
| 176 | + + return ((left->attribute ^ right->attribute) & mem_type_mask) == 0; |
| 177 | + } |
| 178 | + |
| 179 | + /* |
| 180 | +* Unmerged path drivers/firmware/efi/libstub/x86-stub.c |
| 181 | +* Unmerged path drivers/firmware/efi/libstub/arm-stub.c |
| 182 | +* Unmerged path drivers/firmware/efi/libstub/x86-stub.c |
0 commit comments