From eee38788c5b26d2b98afe43583d37f54ecd60113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Mon, 9 Dec 2024 17:48:23 +0100 Subject: [PATCH] Fix - Interpreter `check_pc!` (#643) * Adds test_err_callx_oob_max. * Removes unnecessary debug mode arithmetic guard. --- src/interpreter.rs | 6 +++++- tests/execution.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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!(