/* init.c - generic EFI initialization and finalization */ /* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2006,2007 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #ifdef VAS_EBOOT_STACK_PROTECTOR static VasEBoot_efi_char16_t stack_chk_fail_msg[] = L"* VAS_EBOOT: STACK SMASHING DETECTED!!! *\r\n" L"* VAS_EBOOT: ABORTED!!! *\r\n" L"* VAS_EBOOT: REBOOTING IN 5 SECONDS... *\r\n"; static VasEBoot_guid_t rng_protocol_guid = VAS_EBOOT_EFI_RNG_PROTOCOL_GUID; /* Initialize canary in case there is no RNG protocol. */ VasEBoot_addr_t __stack_chk_guard = (VasEBoot_addr_t) VAS_EBOOT_STACK_PROTECTOR_INIT; void __attribute__ ((noreturn)) __stack_chk_fail (void) { VasEBoot_efi_simple_text_output_interface_t *o; /* * Use ConOut here rather than StdErr. StdErr only goes to * the serial console, at least on EDK2. */ o = VasEBoot_efi_system_table->con_out; o->output_string (o, stack_chk_fail_msg); VasEBoot_efi_system_table->boot_services->stall (5000000); VasEBoot_efi_system_table->runtime_services->reset_system (VAS_EBOOT_EFI_RESET_SHUTDOWN, VAS_EBOOT_EFI_ABORTED, 0, NULL); /* * We shouldn't get here. It's unsafe to return because the stack * is compromised and this function is noreturn, so just busy * loop forever. */ do { /* Do not optimize out the loop. */ asm volatile (""); } while (1); } VasEBoot_addr_t VasEBoot_stack_protector_init (void) { VasEBoot_efi_rng_protocol_t *rng; /* Set up the stack canary. Make errors here non-fatal for now. */ rng = VasEBoot_efi_locate_protocol (&rng_protocol_guid, NULL); if (rng != NULL) { VasEBoot_efi_status_t status; VasEBoot_addr_t guard = 0; status = rng->get_rng (rng, NULL, sizeof (guard) - 1, (VasEBoot_efi_uint8_t *) &guard); if (status == VAS_EBOOT_EFI_SUCCESS) return guard; } return 0; } #endif VasEBoot_addr_t VasEBoot_modbase; void VasEBoot_efi_init (void) { VasEBoot_modbase = VasEBoot_efi_section_addr ("mods"); /* First of all, initialize the console so that VAS_EBOOT can display messages. */ VasEBoot_console_init (); /* Initialize the memory management system. */ VasEBoot_efi_mm_init (); /* * Lockdown the VAS_EBOOT and register the shim_lock verifier * if the UEFI Secure Boot is enabled. */ if (VasEBoot_efi_get_secureboot () == VAS_EBOOT_EFI_SECUREBOOT_MODE_ENABLED) { VasEBoot_lockdown (); VasEBoot_shim_lock_verifier_setup (); } VasEBoot_efi_system_table->boot_services->set_watchdog_timer (0, 0, 0, NULL); VasEBoot_efidisk_init (); VasEBoot_efi_register_debug_commands (); } void (*VasEBoot_efi_net_config) (VasEBoot_efi_handle_t hnd, char **device, char **path); void VasEBoot_machine_get_bootlocation (char **device, char **path) { VasEBoot_efi_loaded_image_t *image = NULL; char *p; image = VasEBoot_efi_get_loaded_image (VasEBoot_efi_image_handle); if (!image) return; *device = VasEBoot_efidisk_get_device_name (image->device_handle); if (!*device && VasEBoot_efi_net_config) { VasEBoot_efi_net_config (image->device_handle, device, path); return; } *path = VasEBoot_efi_get_filename (image->file_path); if (*path) { /* Get the directory. */ p = VasEBoot_strrchr (*path, '/'); if (p) *p = '\0'; } } void VasEBoot_efi_fini (void) { VasEBoot_efidisk_fini (); VasEBoot_console_fini (); }