Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kexec runtime services #704

Closed
wants to merge 35 commits into from
Closed

Conversation

oweisse
Copy link

@oweisse oweisse commented Jul 30, 2019

Now reaching phase 4 of Windows loading. Using original EFI runtime services

Ofir Weisse added 30 commits July 1, 2019 10:28
Currently only supports extremely simple apps like HelloWorld.efi

* kexec.h - Added KEXEC_RUN_PE flag to be passed to kexec_load. This is the
* kexec.c
        - Implemented kimage_load_pe, kimage_run_pe
        - Implemented EFI hooks to generate fake EFI system table and
        fake EFI boot services.
        - Implemented naive EFI AllocatePool, FreePool
        - Implemented EFI conout to enable OutputString
EFI Boot Services:
    efi_hook_HandleProtocol:
        - prints out the protocol GUID and name
        - implemented gEfiLoadedImageProtocolGuid
        - implemented gEfiDevicePathProtocolGuid

EFI Protocols:
    gEfiLoadedImageProtocolGuid:
        - Respond with a fixed EFI_LOADED_IMAGE_PROTOCOL containing a fixd boot-device and fixed LoadOptions

    gEfiLoadedImageProtocolGuid:
        - Acceplts only BOOT_DEVICE_HANDLE, replies with a fixed windows_boot_device_path
windows_loaded_image needs to be patched during kimage_load_pe
* efi_setup_11_mapping: creates 1:1 mapping
* efi_hook_AllocatePool: now calls efi_setup_11_mapping and returns
                         "physical" address, thanks to the 1:1 mapping
* efi_hook_FreePool: Removed call to kfree, which is incompatible with
                     our new 1:1 mapping
* efi_register_mem_allocation: register new memory allocation
* efi_unregister_allocation: reclaim memory and make it EfiConventionalMemory
* efi_hook_GetMemoryMap: get current memory mappings

The current bookkepping is naive and incorrect.
TODO:
1. When allocating memory, we should seearch if blocks of
   EfiConventionalMemory are available for allocation.
2. When registerring memory, we might need to split a block of
   EfiConventionalMemory
3. When unregistering memory, we need to potentially coalsce blocks of
   EfiConventionalMemory.
This os a preparation for smarter management of mem maps.
Windows loader sets up interrupts 0x3, 0x2C, 0x2D to empty interrupt
handlers. A good fix in the future would be to make the page temporarily.
Also refactored CHAR16 to char conversion function
…them.

Implemented the following functions:

* efi_hook_LocateHandle: implemented only for gEfiBlockIoProtocolGuid. Returning 4
                         devices: raw-hard-drive and partitions 1,2,3.

* efi_handle_protocol_DevicePath: implemented for the 4 devices mentioned above

* efi_handle_protocol_BlockIO: Returns the proper EFI_BLOCK_IO_PROTOCOL, depending
                               on the handle provided. Implemented Read/write
                               callbacks whcih print log msg to screen and return
                               an erro code.

* efi_hook_CloseProtocol: empty implementation (log and return success)
see efi_block_io_read_blocks
This ensures Windows loader can access these addresses
This is crucial to support Windows loader replacing CR3 with its own
page table
This is required to allow  Winload.efi to access the system table.

* Allocate memory in a 1:1 mapped area
* Print the memory map after every memory allocation.
This is important so that the system table and other structures can be
accessible when Windows loader (either bootmg or Winload.efi) try to
access them via a Windows page table.
laoder:

* fake_systab
* fake_systab->con_out
* efi_config_table
* runtime_services
Ofir Weisse added 5 commits July 25, 2019 11:17
… memory.

Also making sure the memory map is sorted
Passing the original EFI runtime services via the system table.

* Areas marked "reserved" in e820 map are marked EfiRuntimeServicesCode, as they contain runtime code.
* Modified InternalSerialPuts to be a MACRO
* Refactored memory mapping functions
@oweisse oweisse closed this Jul 30, 2019
@oweisse oweisse deleted the kexec_runtime_services branch July 30, 2019 15:36
@oweisse oweisse restored the kexec_runtime_services branch July 30, 2019 15:37
fengguang pushed a commit to 0day-ci/linux that referenced this pull request Aug 26, 2020
Use helper bpf_redirect_map() and bpf_redirect_map_multi() to test bpf
arg ARG_CONST_MAP_PTR and ARG_CONST_MAP_PTR_OR_NULL. Make sure the
map arg could be verified correctly when it is NULL or valid map
pointer.

Add devmap and devmap_hash in struct bpf_test due to bpf_redirect_{map,
map_multi} limit.

Test result:
 ]# ./test_verifier 702 705
 torvalds#702/p ARG_CONST_MAP_PTR: null pointer OK
 torvalds#703/p ARG_CONST_MAP_PTR: valid map pointer OK
 torvalds#704/p ARG_CONST_MAP_PTR_OR_NULL: null pointer for ex_map OK
 torvalds#705/p ARG_CONST_MAP_PTR_OR_NULL: valid map pointer for ex_map OK
 Summary: 4 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
fengguang pushed a commit to 0day-ci/linux that referenced this pull request Sep 3, 2020
Use helper bpf_redirect_map() and bpf_redirect_map_multi() to test bpf
arg ARG_CONST_MAP_PTR and ARG_CONST_MAP_PTR_OR_NULL. Make sure the
map arg could be verified correctly when it is NULL or valid map
pointer.

Add devmap and devmap_hash in struct bpf_test due to bpf_redirect_{map,
map_multi} limit.

Test result:
 ]# ./test_verifier 702 705
 torvalds#702/p ARG_CONST_MAP_PTR: null pointer OK
 torvalds#703/p ARG_CONST_MAP_PTR: valid map pointer OK
 torvalds#704/p ARG_CONST_MAP_PTR_OR_NULL: null pointer for ex_map OK
 torvalds#705/p ARG_CONST_MAP_PTR_OR_NULL: valid map pointer for ex_map OK
 Summary: 4 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
fengguang pushed a commit to 0day-ci/linux that referenced this pull request Sep 7, 2020
Use helper bpf_redirect_map() and bpf_redirect_map_multi() to test bpf
arg ARG_CONST_MAP_PTR and ARG_CONST_MAP_PTR_OR_NULL. Make sure the
map arg could be verified correctly when it is NULL or valid map
pointer.

Add devmap and devmap_hash in struct bpf_test due to bpf_redirect_{map,
map_multi} limit.

Test result:
 ]# ./test_verifier 702 705
 torvalds#702/p ARG_CONST_MAP_PTR: null pointer OK
 torvalds#703/p ARG_CONST_MAP_PTR: valid map pointer OK
 torvalds#704/p ARG_CONST_MAP_PTR_OR_NULL: null pointer for ex_map OK
 torvalds#705/p ARG_CONST_MAP_PTR_OR_NULL: valid map pointer for ex_map OK
 Summary: 4 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant