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

Commit

Permalink
Adds symbol name length limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Jun 7, 2021
1 parent aeb1822 commit 6e7020d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
// +-----------------+
Expand Down
10 changes: 10 additions & 0 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GoblinError> for ElfError {
fn from(error: GoblinError) -> Self {
match error {
Expand Down Expand Up @@ -621,6 +625,9 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
.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)) {
Expand Down Expand Up @@ -660,6 +667,9 @@ impl<'a, E: UserDefinedError, I: InstructionMeter> EBpfElf<E, I> {
.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)?;
}

Expand Down

0 comments on commit 6e7020d

Please sign in to comment.