Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Feature - Restricts the final instruction in each function to be diverted #522

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Verifier for RequisiteVerifier {
function_range.end = *function_iter.peek().unwrap_or(&program_range.end);
let insn = ebpf::get_insn(prog, function_range.end.saturating_sub(1));
match insn.opc {
ebpf::JA | ebpf::CALL_IMM | ebpf::CALL_REG | ebpf::EXIT => {},
ebpf::JA | ebpf::EXIT => {},
_ => return Err(VerifierError::InvalidFunction(
function_range.end.saturating_sub(1),
)),
Expand Down
22 changes: 13 additions & 9 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2630,16 +2630,17 @@ fn test_tight_infinite_recursion_callx() {
"
mov64 r8, 0x1
lsh64 r8, 0x20
or64 r8, 0x20
or64 r8, 0x28
call function_foo
exit
function_foo:
mov64 r3, 0x41414141
callx r8
exit",
[],
(),
TestContextObject::new(8),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(35))),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(36))),
);
}

Expand All @@ -2665,7 +2666,7 @@ fn test_err_instruction_count_syscall_capped() {
test_interpreter_and_jit_asm!(
"
mov64 r2, 0x5
call 0
syscall bpf_syscall_string
mov64 r0, 0x0
exit",
[72, 101, 108, 108, 111],
Expand Down Expand Up @@ -2778,41 +2779,44 @@ fn test_err_exit_capped() {
"
mov64 r1, 0x1
lsh64 r1, 0x20
or64 r1, 0x20
or64 r1, 0x28
callx r1
exit
function_foo:
exit
",
[],
(),
TestContextObject::new(5),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(34))),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(35))),
);
test_interpreter_and_jit_asm!(
"
mov64 r1, 0x1
lsh64 r1, 0x20
or64 r1, 0x20
or64 r1, 0x28
callx r1
exit
function_foo:
mov r0, r0
exit
",
[],
(),
TestContextObject::new(6),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(35))),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(36))),
);
test_interpreter_and_jit_asm!(
"
call 0
call 1
exit
mov r0, r0
exit
",
[],
(),
TestContextObject::new(3),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(32))),
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(33))),
);
}

Expand Down