From 88f6d59afacf4e934862bba676a9bcb42b319b74 Mon Sep 17 00:00:00 2001 From: Lucas Steuernagel Date: Sun, 20 Oct 2024 11:28:36 -0300 Subject: [PATCH] Add invalid syscall test --- tests/execution.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/execution.rs b/tests/execution.rs index 91b86ea93..dae3255c8 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -4126,3 +4126,35 @@ fn test_invalid_exit_or_return() { ); } } + +#[test] +fn test_unregistered_syscall() { + let prog = &[ + 0xbf, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // mov64 r0, 2 + 0x95, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // syscall 2 + 0x9d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // return + ]; + + let config = Config { + enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enable_instruction_tracing: true, + ..Config::default() + }; + + let loader = Arc::new(BuiltinProgram::new_loader_with_dense_registration(config)); + let mut executable = Executable::::from_text_bytes( + prog, + loader, + SBPFVersion::V2, + FunctionRegistry::default(), + ) + .unwrap(); + + test_interpreter_and_jit!( + false, + executable, + [], + TestContextObject::new(2), + ProgramResult::Err(EbpfError::UnsupportedInstruction), + ); +}