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

Fix - Makes functions starting in the middle of lddw fail verification in SBFv2 #440

Merged
merged 1 commit into from
Feb 16, 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
14 changes: 13 additions & 1 deletion src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,21 @@ pub struct RequisiteVerifier {}
impl Verifier for RequisiteVerifier {
/// Check the program against the verifier's rules
#[rustfmt::skip]
fn verify(prog: &[u8], config: &Config, _function_registry: &FunctionRegistry) -> Result<(), VerifierError> {
fn verify(prog: &[u8], config: &Config, function_registry: &FunctionRegistry) -> Result<(), VerifierError> {
check_prog_len(prog)?;

if config.static_syscalls {
for (_key, (dst_insn_ptr, _name)) in function_registry.iter() {
let dst_insn = ebpf::get_insn(prog, *dst_insn_ptr);
if dst_insn.opc == 0 {
return Err(VerifierError::JumpToMiddleOfLDDW(
*dst_insn_ptr,
adj_insn_ptr(*dst_insn_ptr),
));
}
}
}

let mut insn_ptr: usize = 0;
while (insn_ptr + 1) * ebpf::INSN_SIZE <= prog.len() {
let insn = ebpf::get_insn(prog, insn_ptr);
Expand Down
19 changes: 0 additions & 19 deletions tests/ubpf_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2777,25 +2777,6 @@ fn test_err_static_jmp_lddw() {
TestContextObject::new(9),
{ |_vm, res: ProgramResult| { res.unwrap() == 0x2 } },
);
test_interpreter_and_jit_asm!(
"
call 3
mov r0, r0
mov r0, r0
lddw r0, 0x1122334455667788
exit
",
[],
(),
TestContextObject::new(2),
{
|_vm, res: ProgramResult| {
matches!(res.unwrap_err(),
EbpfError::UnsupportedInstruction(pc) if pc == 33
)
}
},
);
}

#[test]
Expand Down
16 changes: 16 additions & 0 deletions tests/ubpf_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ fn test_verifier_err_jmp_lddw() {
.unwrap();
}

#[test]
#[should_panic(expected = "JumpToMiddleOfLDDW(2, 31)")]
fn test_verifier_err_call_lddw() {
let executable = assemble::<TestContextObject>(
"
call 1
lddw r0, 0x1122334455667788
exit",
Arc::new(BuiltInProgram::new_loader(Config::default())),
)
.unwrap();
let _verified_executable =
VerifiedExecutable::<RequisiteVerifier, TestContextObject>::from_executable(executable)
.unwrap();
}

#[test]
#[should_panic(expected = "JumpOutOfCode(3, 29)")]
fn test_verifier_err_jmp_out() {
Expand Down