From caa7701d871881e512aa46a1689b427bacfc9365 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Tue, 22 Oct 2024 18:10:46 -0300 Subject: [PATCH] Use debug_assert --- src/interpreter.rs | 2 +- src/jit.rs | 11 +++-------- tests/execution.rs | 2 ++ 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index 8134bf905..2a4581903 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -552,7 +552,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ProgramResult::Err(_err) => return false, }; } else { - throw_error!(self, EbpfError::UnsupportedInstruction); + debug_assert!(false, "Invalid syscall should have been detected in the verifier."); } }, ebpf::RETURN diff --git a/src/jit.rs b/src/jit.rs index 1971d61c8..b5f414c89 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -715,14 +715,15 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { // BPF to BPF call self.emit_internal_call(Value::Constant64(target_pc as i64, true)); } else { - self.emit_throw_unsupported_instruction(); + self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, REGISTER_SCRATCH, self.pc as i64)); + self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_CALL_UNSUPPORTED_INSTRUCTION, 5))); } }, ebpf::SYSCALL if self.executable.get_sbpf_version().static_syscalls() => { if let Some((_, function)) = self.executable.get_loader().get_function_registry(self.executable.get_sbpf_version()).lookup_by_key(insn.imm as u32) { self.emit_syscall_dispatch(function); } else { - self.emit_throw_unsupported_instruction(); + debug_assert!(false, "Invalid syscall should have been detected in the verifier.") } }, ebpf::CALL_REG => { @@ -1130,12 +1131,6 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { self.emit_undo_profile_instruction_count(0); } - #[inline] - fn emit_throw_unsupported_instruction(&mut self) { - self.emit_ins(X86Instruction::load_immediate(OperandSize::S64, REGISTER_SCRATCH, self.pc as i64)); - self.emit_ins(X86Instruction::jump_immediate(self.relative_to_anchor(ANCHOR_CALL_UNSUPPORTED_INSTRUCTION, 5))); - } - #[inline] fn emit_address_translation(&mut self, dst: Option, vm_addr: Value, len: u64, value: Option) { debug_assert_ne!(dst.is_some(), value.is_some()); diff --git a/tests/execution.rs b/tests/execution.rs index acd348357..eb25dd42d 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -4089,6 +4089,7 @@ fn test_mod() { } #[test] +#[should_panic(expected = "Invalid syscall should have been detected in the verifier.")] fn test_invalid_exit_or_return() { for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { let inst = if sbpf_version == SBPFVersion::V1 { @@ -4128,6 +4129,7 @@ fn test_invalid_exit_or_return() { } #[test] +#[should_panic(expected = "Invalid syscall should have been detected in the verifier.")] fn test_unregistered_syscall() { let prog = &[ 0xbf, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // mov64 r0, 2