Skip to content

Commit

Permalink
Fix - Interpreter ExceededMaxInstructions and ExecutionOverrun (#592
Browse files Browse the repository at this point in the history
)

* Fixes EbpfError::ExecutionOverrun in interpreter.

* Fixes EbpfError::ExceededMaxInstructions in interpreter.

* Adds test coverage.
  • Loading branch information
Lichtso authored Sep 12, 2024
1 parent 8747f87 commit 1223789
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,14 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> {
pub fn step(&mut self) -> bool {
let config = &self.executable.get_config();

if config.enable_instruction_meter && self.vm.due_insn_count >= self.vm.previous_instruction_meter {
throw_error!(self, EbpfError::ExceededMaxInstructions);
}
self.vm.due_insn_count += 1;
let mut next_pc = self.reg[11] + 1;
if next_pc as usize * ebpf::INSN_SIZE > self.program.len() {
if self.reg[11] as usize * ebpf::INSN_SIZE >= self.program.len() {
throw_error!(self, EbpfError::ExecutionOverrun);
}
let mut next_pc = self.reg[11] + 1;
let mut insn = ebpf::get_insn_unchecked(self.program, self.reg[11] as usize);
let dst = insn.dst as usize;
let src = insn.src as usize;
Expand Down
9 changes: 9 additions & 0 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3499,6 +3499,15 @@ fn test_execution_overrun() {
TestContextObject::new(1),
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
);
test_interpreter_and_jit_asm!(
"
add r1, 0",
config.clone(),
[],
(),
TestContextObject::new(0),
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
);
}

#[test]
Expand Down

0 comments on commit 1223789

Please sign in to comment.