diff --git a/src/interpreter.rs b/src/interpreter.rs index dcb38f5b..0a0edc95 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -67,7 +67,11 @@ macro_rules! check_pc { ($self:expr, $next_pc:ident, $target_pc:expr) => { if ($target_pc as usize) .checked_mul(ebpf::INSN_SIZE) - .and_then(|offset| $self.program.get(offset..offset + ebpf::INSN_SIZE)) + .and_then(|offset| { + $self + .program + .get(offset..offset.saturating_add(ebpf::INSN_SIZE)) + }) .is_some() { $next_pc = $target_pc; diff --git a/tests/execution.rs b/tests/execution.rs index 0989119e..22439ffa 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -2490,6 +2490,20 @@ fn test_err_callx_oob_high() { ); } +#[test] +fn test_err_callx_oob_max() { + test_interpreter_and_jit_asm!( + " + mov64 r0, -0x8 + hor64 r0, -0x1 + callx r0 + exit", + [], + TestContextObject::new(3), + ProgramResult::Err(EbpfError::CallOutsideTextSegment), + ); +} + #[test] fn test_callx_unaligned_text_section() { test_interpreter_and_jit_elf!(