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

Commit c10ce31

Browse files
authored
Restricts the final instruction in each function to be diverted. (#522)
1 parent b834cf8 commit c10ce31

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/verifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl Verifier for RequisiteVerifier {
243243
function_range.end = *function_iter.peek().unwrap_or(&program_range.end);
244244
let insn = ebpf::get_insn(prog, function_range.end.saturating_sub(1));
245245
match insn.opc {
246-
ebpf::JA | ebpf::CALL_IMM | ebpf::CALL_REG | ebpf::EXIT => {},
246+
ebpf::JA | ebpf::EXIT => {},
247247
_ => return Err(VerifierError::InvalidFunction(
248248
function_range.end.saturating_sub(1),
249249
)),

tests/execution.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,16 +2639,17 @@ fn test_tight_infinite_recursion_callx() {
26392639
"
26402640
mov64 r8, 0x1
26412641
lsh64 r8, 0x20
2642-
or64 r8, 0x20
2642+
or64 r8, 0x28
26432643
call function_foo
2644+
exit
26442645
function_foo:
26452646
mov64 r3, 0x41414141
26462647
callx r8
26472648
exit",
26482649
[],
26492650
(),
26502651
TestContextObject::new(8),
2651-
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(35))),
2652+
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(36))),
26522653
);
26532654
}
26542655

@@ -2674,7 +2675,7 @@ fn test_err_instruction_count_syscall_capped() {
26742675
test_interpreter_and_jit_asm!(
26752676
"
26762677
mov64 r2, 0x5
2677-
call 0
2678+
syscall bpf_syscall_string
26782679
mov64 r0, 0x0
26792680
exit",
26802681
[72, 101, 108, 108, 111],
@@ -2787,41 +2788,44 @@ fn test_err_exit_capped() {
27872788
"
27882789
mov64 r1, 0x1
27892790
lsh64 r1, 0x20
2790-
or64 r1, 0x20
2791+
or64 r1, 0x28
27912792
callx r1
2793+
exit
27922794
function_foo:
27932795
exit
27942796
",
27952797
[],
27962798
(),
27972799
TestContextObject::new(5),
2798-
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(34))),
2800+
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(35))),
27992801
);
28002802
test_interpreter_and_jit_asm!(
28012803
"
28022804
mov64 r1, 0x1
28032805
lsh64 r1, 0x20
2804-
or64 r1, 0x20
2806+
or64 r1, 0x28
28052807
callx r1
2808+
exit
28062809
function_foo:
28072810
mov r0, r0
28082811
exit
28092812
",
28102813
[],
28112814
(),
28122815
TestContextObject::new(6),
2813-
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(35))),
2816+
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(36))),
28142817
);
28152818
test_interpreter_and_jit_asm!(
28162819
"
2817-
call 0
2820+
call 1
2821+
exit
28182822
mov r0, r0
28192823
exit
28202824
",
28212825
[],
28222826
(),
28232827
TestContextObject::new(3),
2824-
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(32))),
2828+
ProgramResult::Err(Box::new(EbpfError::ExceededMaxInstructions(33))),
28252829
);
28262830
}
28272831

0 commit comments

Comments
 (0)