Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Use patched goblin dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed May 31, 2021
1 parent 02288d0 commit b00cdb7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include = [
[dependencies]
byteorder = "1.2"
combine = "3.8.1"
goblin = "0.3.0"
goblin = { git = "https://github.com/Lichtso/goblin.git", branch = "parse_strtab_in_constructor" } # "0.4.1"
hash32 = "0.1.0"
libc = "0.2"
log = "0.4.2"
Expand Down
5 changes: 2 additions & 3 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn main() {
let mut file = File::open(&Path::new(matches.value_of("elf").unwrap())).unwrap();
let mut elf = Vec::new();
file.read_to_end(&mut elf).unwrap();
Executable::<UserError, TestInstructionMeter>::from_elf(&elf, verifier, config)
<dyn Executable::<UserError, TestInstructionMeter>>::from_elf(&elf, verifier, config)
.map_err(|err| format!("Executable constructor failed: {:?}", err))
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ impl<E: UserDefinedError, I: InstructionMeter> Executable<E, I> for EBpfElf<E, I
name = elf
.dynstrtab
.get(sym.st_name)
.ok_or(ElfError::UnknownSymbol(sym.st_name))?
.map_err(|_| ElfError::UnknownSymbol(sym.st_name))?;
.ok_or(ElfError::UnknownSymbol(sym.st_name))?;
}
}
}
Expand Down Expand Up @@ -375,10 +374,9 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
.shdr_strtab
.get(text_section.sh_name)
.unwrap()
.unwrap()
.to_string(),
vaddr: text_section.sh_addr.saturating_add(ebpf::MM_PROGRAM_START),
offset_range: text_section.file_range(),
offset_range: text_section.file_range().unwrap_or_default(),
};
if text_section_info.vaddr > ebpf::MM_STACK_START {
return Err(ElfError::OutOfBounds);
Expand Down Expand Up @@ -408,14 +406,14 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
.section_headers
.iter()
.filter_map(|section_header| {
if let Some(Ok(name)) = elf.shdr_strtab.get(section_header.sh_name) {
if let Some(name) = elf.shdr_strtab.get(section_header.sh_name) {
if name == ".rodata" || name == ".data.rel.ro" || name == ".eh_frame" {
return Some(SectionInfo {
name: name.to_string(),
vaddr: section_header
.sh_addr
.saturating_add(ebpf::MM_PROGRAM_START),
offset_range: section_header.file_range(),
offset_range: section_header.file_range().unwrap_or_default(),
});
}
}
Expand Down Expand Up @@ -487,7 +485,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
}

let num_text_sections = elf.section_headers.iter().fold(0, |count, section_header| {
if let Some(Ok(this_name)) = elf.shdr_strtab.get(section_header.sh_name) {
if let Some(this_name) = elf.shdr_strtab.get(section_header.sh_name) {
if this_name == ".text" {
return count + 1;
}
Expand All @@ -499,7 +497,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
}

for section_header in elf.section_headers.iter() {
if let Some(Ok(this_name)) = elf.shdr_strtab.get(section_header.sh_name) {
if let Some(this_name) = elf.shdr_strtab.get(section_header.sh_name) {
if this_name.starts_with(".bss") {
return Err(ElfError::BssNotSupported);
}
Expand Down Expand Up @@ -530,7 +528,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
/// Get a section by name
fn get_section(elf: &Elf, name: &str) -> Result<SectionHeader, ElfError> {
match elf.section_headers.iter().find(|section_header| {
if let Some(Ok(this_name)) = elf.shdr_strtab.get(section_header.sh_name) {
if let Some(this_name) = elf.shdr_strtab.get(section_header.sh_name) {
return this_name == name;
}
false
Expand All @@ -553,7 +551,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
Self::fixup_relative_calls(
bpf_function_symbols,
&mut elf_bytes
.get_mut(text_section.file_range())
.get_mut(text_section.file_range().unwrap_or_default())
.ok_or(ElfError::OutOfBounds)?,
)?;

Expand Down Expand Up @@ -587,7 +585,11 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
let refd_pa = ebpf::MM_PROGRAM_START.saturating_add(refd_va);

// Write the physical address back into the target location
if text_section.file_range().contains(&r_offset) {
if text_section
.file_range()
.unwrap_or_default()
.contains(&r_offset)
{
// Instruction lddw spans two instruction slots, split the
// physical address into a high and low and write into both slot's imm field

Expand Down Expand Up @@ -623,8 +625,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
let name = elf
.dynstrtab
.get(sym.st_name)
.ok_or(ElfError::UnknownSymbol(sym.st_name))?
.map_err(|_| ElfError::UnknownSymbol(sym.st_name))?;
.ok_or(ElfError::UnknownSymbol(sym.st_name))?;
let hash = if sym.is_function() && sym.st_value != 0 {
// bpf call
if !text_section.vm_range().contains(&(sym.st_value as usize)) {
Expand Down Expand Up @@ -669,8 +670,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
let name = elf
.strtab
.get(symbol.st_name)
.ok_or(ElfError::UnknownSymbol(symbol.st_name))?
.map_err(|_| ElfError::UnknownSymbol(symbol.st_name))?;
.ok_or(ElfError::UnknownSymbol(symbol.st_name))?;
register_bpf_function(bpf_function_symbols, target_pc, &name)?;
}

Expand Down

0 comments on commit b00cdb7

Please sign in to comment.