Skip to content

Commit

Permalink
Restricts the final instruction in each function to be diverted.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtso committed Sep 23, 2023
1 parent 7d8ede8 commit 7ddd6e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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

0 comments on commit 7ddd6e8

Please sign in to comment.