Skip to content

Commit

Permalink
Fix - JIT instruction meter in ExecutionOverrun (#591)
Browse files Browse the repository at this point in the history
* Fixes missing pc reporting in JIT when throwing EbpfError::ExecutionOverrun.

* Adds missing test coverage for EbpfError::ExecutionOverrun.
  • Loading branch information
Lichtso authored Sep 12, 2024
1 parent 9f8d7cb commit 8747f87
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/jit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,9 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> {
// Bumper in case there was no final exit
if self.offset_in_text_section + MAX_MACHINE_CODE_LENGTH_PER_INSTRUCTION * 2 >= self.result.text_section.len() {
return Err(EbpfError::ExhaustedTextSegment(self.pc));
}
self.emit_validate_and_profile_instruction_count(true, false, Some(self.pc + 2));
}
self.emit_validate_and_profile_instruction_count(true, false, Some(self.pc + 1));
self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, REGISTER_SCRATCH, self.pc as i64)); // Save pc
self.emit_set_exception_kind(EbpfError::ExecutionOverrun);
self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_THROW_EXCEPTION, 5)));

Expand Down
35 changes: 35 additions & 0 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3475,12 +3475,47 @@ fn test_err_fixed_stack_out_of_bound() {
);
}

#[test]
fn test_execution_overrun() {
let config = Config {
enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1,
..Config::default()
};
test_interpreter_and_jit_asm!(
"
add r1, 0",
config.clone(),
[],
(),
TestContextObject::new(2),
ProgramResult::Err(EbpfError::ExecutionOverrun),
);
test_interpreter_and_jit_asm!(
"
add r1, 0",
config.clone(),
[],
(),
TestContextObject::new(1),
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
);
}

#[test]
fn test_lddw() {
let config = Config {
enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1,
..Config::default()
};
test_interpreter_and_jit_asm!(
"
lddw r0, 0x1122334455667788",
config.clone(),
[],
(),
TestContextObject::new(2),
ProgramResult::Err(EbpfError::ExecutionOverrun),
);
test_interpreter_and_jit_asm!(
"
lddw r0, 0x1122334455667788
Expand Down

0 comments on commit 8747f87

Please sign in to comment.