Skip to content

Commit

Permalink
Fix - Interpreter check_pc! (#643)
Browse files Browse the repository at this point in the history
* Adds test_err_callx_oob_max.

* Removes unnecessary debug mode arithmetic guard.
  • Loading branch information
Lichtso authored Dec 9, 2024
1 parent 410a627 commit eee3878
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down

0 comments on commit eee3878

Please sign in to comment.