diff --git a/src/ebpf.rs b/src/ebpf.rs index c92f6a3d2..23b790ea6 100644 --- a/src/ebpf.rs +++ b/src/ebpf.rs @@ -21,8 +21,6 @@ use byteorder::{ByteOrder, LittleEndian}; use hash32::{Hash, Hasher, Murmur3Hasher}; use std::fmt; -/// Maximum number of instructions in an eBPF program. -pub const PROG_MAX_INSNS: usize = 65_536; /// Size of an eBPF instructions, in bytes. pub const INSN_SIZE: usize = 8; /// Stack register @@ -35,6 +33,8 @@ pub const SCRATCH_REGS: usize = 4; /// Instruction numbers typically start at 29 in the ELF dump, use this offset /// when reporting so that trace aligns with the dump. pub const ELF_INSN_DUMP_OFFSET: usize = 29; +/// Maximum number of characters in a symbol name. +pub const MAX_SYMBOL_NAME_LENGTH: usize = 256; // Memory map // +-----------------+ diff --git a/src/elf.rs b/src/elf.rs index b7e7fc3ae..b67ed8f3a 100644 --- a/src/elf.rs +++ b/src/elf.rs @@ -86,10 +86,14 @@ pub enum ElfError { /// Unknown symbol #[error("Unknown symbol with index {0}")] UnknownSymbol(usize), + /// Symbol name too long + #[error("The name of a symbol is too long")] + SymbolNameTooLong, /// Offset or value is out of bounds #[error("Offset or value is out of bounds")] OutOfBounds, } + impl From for ElfError { fn from(error: GoblinError) -> Self { match error { @@ -621,6 +625,9 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { .dynstrtab .get_at(sym.st_name) .ok_or(ElfError::UnknownSymbol(sym.st_name))?; + if name.len() > ebpf::MAX_SYMBOL_NAME_LENGTH { + return Err(ElfError::SymbolNameTooLong); + } let hash = if sym.is_function() && sym.st_value != 0 { // bpf call if !text_section.vm_range().contains(&(sym.st_value as usize)) { @@ -660,6 +667,9 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf { .strtab .get_at(symbol.st_name) .ok_or(ElfError::UnknownSymbol(symbol.st_name))?; + if name.len() > ebpf::MAX_SYMBOL_NAME_LENGTH { + return Err(ElfError::SymbolNameTooLong); + } register_bpf_function(bpf_functions, target_pc, &name)?; }