From b00cdb7ad11a8e049330e166ee2c1a7b41a6286b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 31 May 2021 14:06:22 +0200 Subject: [PATCH] Use patched goblin dependency. --- Cargo.lock | 5 ++--- Cargo.toml | 2 +- cli/Cargo.lock | 5 ++--- cli/src/main.rs | 2 +- src/elf.rs | 30 +++++++++++++++--------------- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a7d5550c6..a7c856872 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -65,9 +65,8 @@ dependencies = [ [[package]] name = "goblin" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c" +version = "0.4.0" +source = "git+https://github.com/Lichtso/goblin.git?branch=parse_strtab_in_constructor#0b6475c8d060b6bbc12a105559ad6b84d10c2748" dependencies = [ "log", "plain", diff --git a/Cargo.toml b/Cargo.toml index 39a1bf017..4ca4171a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/cli/Cargo.lock b/cli/Cargo.lock index c8d355384..10a188a47 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -105,9 +105,8 @@ dependencies = [ [[package]] name = "goblin" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c" +version = "0.4.0" +source = "git+https://github.com/Lichtso/goblin.git?branch=parse_strtab_in_constructor#0b6475c8d060b6bbc12a105559ad6b84d10c2748" dependencies = [ "log", "plain", diff --git a/cli/src/main.rs b/cli/src/main.rs index e688302b0..c6e12c20e 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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::::from_elf(&elf, verifier, config) + >::from_elf(&elf, verifier, config) .map_err(|err| format!("Executable constructor failed: {:?}", err)) } } diff --git a/src/elf.rs b/src/elf.rs index 4a1e9e50b..0608b6c71 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -305,8 +305,7 @@ impl Executable for EBpfElf EBpfElf { .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); @@ -408,14 +406,14 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { .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(), }); } } @@ -487,7 +485,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { } 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; } @@ -499,7 +497,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { } 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); } @@ -530,7 +528,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { /// Get a section by name fn get_section(elf: &Elf, name: &str) -> Result { 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 @@ -553,7 +551,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { 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)?, )?; @@ -587,7 +585,11 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { 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 @@ -623,8 +625,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { 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)) { @@ -669,8 +670,7 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { 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)?; }