From 6768eb37c16af2351d318856caf92e0b575740d3 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 d5b3d690c..2e516ec49 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -4132,3 +4132,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), + ); +}