-
Notifications
You must be signed in to change notification settings - Fork 155
Description
Context
The ElfInfo::get_va_size() function is used for determining the size of the gest_code slot during the construction of the sand memory layout.
This function calculates the size based on the loadable program headers, which represent the size of the ELF binary when loaded into memory.
Problem
Although the current implementation works, it does not account for guest binaries that have non-loadable segments which still occupy memory at runtime, such as the BSS segment. As a result, the size computation for these binaries will be incorrect.
Solution
To fix this, we should consider arithmetic on sections that are tagged as SHF_ALLOC. From the ELF Specification [1]:
The section occupies memory during process execution. Some control
sections do not reside in the memory image of an object file; this attribute
is off for those sections.
Code References
hyperlight/src/hyperlight_host/src/mem/elf.rs
Lines 62 to 70 in b0ea748
| pub(crate) fn get_va_size(&self) -> usize { | |
| let max_phdr = self | |
| .phdrs | |
| .iter() | |
| .rev() | |
| .find(|phdr| phdr.p_type == PT_LOAD) | |
| .unwrap(); // guaranteed not to panic because of the check in new() | |
| (max_phdr.p_vaddr + max_phdr.p_memsz - self.get_base_va()) as usize | |
| } |
hyperlight/src/hyperlight_host/src/mem/layout.rs
Lines 321 to 326 in b0ea748
| pub(super) fn new( | |
| cfg: SandboxConfiguration, | |
| code_size: usize, | |
| stack_size: usize, | |
| heap_size: usize, | |
| ) -> Result<Self> { |
External References
Metadata
Metadata
Assignees
Labels
Type
Projects
Status