From c886625c83340f71382e041e7f2dbaff2aaa67d9 Mon Sep 17 00:00:00 2001 From: jackcmay Date: Tue, 16 Oct 2018 13:13:54 -0700 Subject: [PATCH] Move from solana/rbpf fork to qmonnet/rbpf (#1511) --- Cargo.toml | 1 - programs/bpf/noop_rust/Cargo.toml | 2 +- programs/native/sobpf/Cargo.toml | 2 +- programs/native/sobpf/src/bpf_verifier.rs | 170 ++++++------ programs/native/sobpf/src/lib.rs | 24 +- src/bpf_verifier.rs | 314 ---------------------- src/lib.rs | 2 - 7 files changed, 111 insertions(+), 404 deletions(-) delete mode 100644 src/bpf_verifier.rs diff --git a/Cargo.toml b/Cargo.toml index 982fa7fef..1a0ac07eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,7 +94,6 @@ matches = "0.1.6" nix = "0.11.0" pnet_datalink = "0.21.0" rand = "0.5.1" -rbpf = { git = "https://github.com/solana-labs/rbpf" } rayon = "1.0.0" reqwest = "0.9.0" ring = "0.13.2" diff --git a/programs/bpf/noop_rust/Cargo.toml b/programs/bpf/noop_rust/Cargo.toml index 4c26ab918..686aee365 100644 --- a/programs/bpf/noop_rust/Cargo.toml +++ b/programs/bpf/noop_rust/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["Solana Maintainers "] [dependencies] -rbpf = { git = "https://github.com/solana-labs/rbpf" } +rbpf = { git = "https://github.com/qmonnet/rbpf", rev="bc41ec47d9b51751585f6ddcde1d1eb1afe2be69" } solana = { path = "../../.." } diff --git a/programs/native/sobpf/Cargo.toml b/programs/native/sobpf/Cargo.toml index 149885075..e9669565a 100644 --- a/programs/native/sobpf/Cargo.toml +++ b/programs/native/sobpf/Cargo.toml @@ -9,7 +9,7 @@ byteorder = "1.2.1" elf = "0.0.10" libc = "0.2.43" log = "0.4.2" -rbpf = { git = "https://github.com/solana-labs/rbpf" } +rbpf = { git = "https://github.com/qmonnet/rbpf", rev="bc41ec47d9b51751585f6ddcde1d1eb1afe2be69" } serde = "1.0.27" serde_derive = "1.0.27" solana_program_interface = { path = "../../../common" } diff --git a/programs/native/sobpf/src/bpf_verifier.rs b/programs/native/sobpf/src/bpf_verifier.rs index ca0045834..aff486564 100644 --- a/programs/native/sobpf/src/bpf_verifier.rs +++ b/programs/native/sobpf/src/bpf_verifier.rs @@ -1,108 +1,118 @@ use rbpf::ebpf; +use std::io::{Error, ErrorKind}; -// This “verifier” performs simple checks when the eBPF program is loaded into the VM (before it is -// interpreted or JIT-compiled). +fn reject>(msg: S) -> Result<(), Error> { + let full_msg = format!("[Verifier] Error: {}", msg.as_ref()); + Err(Error::new(ErrorKind::Other, full_msg)) +} -fn verify_prog_len(prog: &[u8]) { +fn check_prog_len(prog: &[u8]) -> Result<(), Error> { if prog.len() % ebpf::INSN_SIZE != 0 { - panic!( - "[Verifier] Error: eBPF program length must be a multiple of {:?} octets", + reject(format!( + "eBPF program length must be a multiple of {:?} octets", ebpf::INSN_SIZE - ); + ))?; } if prog.len() > ebpf::PROG_MAX_SIZE { - panic!( - "[Verifier] Error: eBPF program length limited to {:?}, here {:?}", + reject(format!( + "eBPF program length limited to {:?}, here {:?}", ebpf::PROG_MAX_INSNS, prog.len() / ebpf::INSN_SIZE - ); + ))?; } + if prog.is_empty() { - panic!("[Verifier] Error: program is empty"); + reject("No program set, call prog_set() to load one".to_string())?; } + // TODO BPF program may deterministically exit even if the last // instruction in the block is not an exit (might be earlier and jumped to) // TODO need to validate more intelligently // let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1); // if last_insn.opc != ebpf::EXIT { - // panic!("[Verifier] Error: program does not end with “EXIT” instruction"); + // reject("program does not end with “EXIT” instruction".to_string())?; // } + + Ok(()) } -fn verify_imm_nonzero(insn: &ebpf::Insn, insn_ptr: usize) { +fn check_imm_nonzero(insn: &ebpf::Insn, insn_ptr: usize) -> Result<(), Error> { if insn.imm == 0 { - panic!("[Verifier] Error: division by 0 (insn #{:?})", insn_ptr); + reject(format!("division by 0 (insn #{:?})", insn_ptr))?; } + + Ok(()) } -fn verify_imm_endian(insn: &ebpf::Insn, insn_ptr: usize) { +fn check_imm_endian(insn: &ebpf::Insn, insn_ptr: usize) -> Result<(), Error> { match insn.imm { - 16 | 32 | 64 => return, - _ => panic!( - "[Verifier] Error: unsupported argument for LE/BE (insn #{:?})", + 16 | 32 | 64 => Ok(()), + _ => reject(format!( + "unsupported argument for LE/BE (insn #{:?})", insn_ptr - ), + )), } } -fn verify_load_dw(prog: &[u8], insn_ptr: usize) { +fn check_load_dw(prog: &[u8], insn_ptr: usize) -> Result<(), Error> { // We know we can reach next insn since we enforce an EXIT insn at the end of program, while // this function should be called only for LD_DW insn, that cannot be last in program. let next_insn = ebpf::get_insn(prog, insn_ptr + 1); if next_insn.opc != 0 { - panic!( - "[Verifier] Error: incomplete LD_DW instruction (insn #{:?})", + reject(format!( + "incomplete LD_DW instruction (insn #{:?})", insn_ptr - ); + ))?; } + + Ok(()) } -fn verify_jmp_offset(prog: &[u8], insn_ptr: usize) { +fn check_jmp_offset(prog: &[u8], insn_ptr: usize) -> Result<(), Error> { let insn = ebpf::get_insn(prog, insn_ptr); if insn.off == -1 { - panic!("[Verifier] Error: infinite loop (insn #{:?})", insn_ptr); + reject(format!("infinite loop (insn #{:?})", insn_ptr))?; } let dst_insn_ptr = insn_ptr as isize + 1 + insn.off as isize; if dst_insn_ptr < 0 || dst_insn_ptr as usize >= (prog.len() / ebpf::INSN_SIZE) { - panic!( - "[Verifier] Error: jump out of code to #{:?} (insn #{:?})", + reject(format!( + "jump out of code to #{:?} (insn #{:?})", dst_insn_ptr, insn_ptr - ); + ))?; } let dst_insn = ebpf::get_insn(prog, dst_insn_ptr as usize); if dst_insn.opc == 0 { - panic!( - "[Verifier] Error: jump to middle of LD_DW at #{:?} (insn #{:?})", + reject(format!( + "jump to middle of LD_DW at #{:?} (insn #{:?})", dst_insn_ptr, insn_ptr - ); + ))?; } + + Ok(()) } -fn verify_registers(insn: &ebpf::Insn, store: bool, insn_ptr: usize) { +fn check_registers(insn: &ebpf::Insn, store: bool, insn_ptr: usize) -> Result<(), Error> { if insn.src > 10 { - panic!( - "[Verifier] Error: invalid source register (insn #{:?})", - insn_ptr - ); + reject(format!("invalid source register (insn #{:?})", insn_ptr))?; } match (insn.dst, store) { - (0...9, _) | (10, true) => {} - (10, false) => panic!( - "[Verifier] Error: cannot write into register r10 (insn #{:?})", + (0...9, _) | (10, true) => Ok(()), + (10, false) => reject(format!( + "cannot write into register r10 (insn #{:?})", insn_ptr - ), - (_, _) => panic!( - "[Verifier] Error: invalid destination register (insn #{:?})", + )), + (_, _) => reject(format!( + "invalid destination register (insn #{:?})", insn_ptr - ), + )), } } -pub fn verifier(prog: &[u8]) -> bool { - verify_prog_len(prog); +pub fn check(prog: &[u8]) -> Result<(), Error> { + check_prog_len(prog)?; let mut insn_ptr: usize = 0; while insn_ptr * ebpf::INSN_SIZE < prog.len() { @@ -122,7 +132,7 @@ pub fn verifier(prog: &[u8]) -> bool { ebpf::LD_DW_IMM => { store = true; - verify_load_dw(prog, insn_ptr); + check_load_dw(prog, insn_ptr)?; insn_ptr += 1; } @@ -158,7 +168,7 @@ pub fn verifier(prog: &[u8]) -> bool { ebpf::MUL32_IMM => {} ebpf::MUL32_REG => {} ebpf::DIV32_IMM => { - verify_imm_nonzero(&insn, insn_ptr); + check_imm_nonzero(&insn, insn_ptr)?; } ebpf::DIV32_REG => {} ebpf::OR32_IMM => {} @@ -171,7 +181,7 @@ pub fn verifier(prog: &[u8]) -> bool { ebpf::RSH32_REG => {} ebpf::NEG32 => {} ebpf::MOD32_IMM => { - verify_imm_nonzero(&insn, insn_ptr); + check_imm_nonzero(&insn, insn_ptr)?; } ebpf::MOD32_REG => {} ebpf::XOR32_IMM => {} @@ -181,10 +191,10 @@ pub fn verifier(prog: &[u8]) -> bool { ebpf::ARSH32_IMM => {} ebpf::ARSH32_REG => {} ebpf::LE => { - verify_imm_endian(&insn, insn_ptr); + check_imm_endian(&insn, insn_ptr)?; } ebpf::BE => { - verify_imm_endian(&insn, insn_ptr); + check_imm_endian(&insn, insn_ptr)?; } // BPF_ALU64 class @@ -193,11 +203,11 @@ pub fn verifier(prog: &[u8]) -> bool { ebpf::SUB64_IMM => {} ebpf::SUB64_REG => {} ebpf::MUL64_IMM => { - verify_imm_nonzero(&insn, insn_ptr); + check_imm_nonzero(&insn, insn_ptr)?; } ebpf::MUL64_REG => {} ebpf::DIV64_IMM => { - verify_imm_nonzero(&insn, insn_ptr); + check_imm_nonzero(&insn, insn_ptr)?; } ebpf::DIV64_REG => {} ebpf::OR64_IMM => {} @@ -220,95 +230,95 @@ pub fn verifier(prog: &[u8]) -> bool { // BPF_JMP class ebpf::JA => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JEQ_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JEQ_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JGT_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JGT_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JGE_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JGE_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JLT_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JLT_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JLE_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JLE_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSET_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSET_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JNE_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JNE_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSGT_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSGT_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSGE_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSGE_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSLT_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSLT_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSLE_IMM => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::JSLE_REG => { - verify_jmp_offset(prog, insn_ptr); + check_jmp_offset(prog, insn_ptr)?; } ebpf::CALL => {} ebpf::TAIL_CALL => unimplemented!(), ebpf::EXIT => {} _ => { - panic!( - "[Verifier] Error: unknown eBPF opcode {:#2x} (insn #{:?})", + reject(format!( + "unknown eBPF opcode {:#2x} (insn #{:?})", insn.opc, insn_ptr - ); + ))?; } } - verify_registers(&insn, store, insn_ptr); + check_registers(&insn, store, insn_ptr)?; insn_ptr += 1; } // insn_ptr should now be equal to number of instructions. if insn_ptr != prog.len() / ebpf::INSN_SIZE { - panic!("[Verifier] Error: jumped out of code to #{:?}", insn_ptr); + reject(format!("jumped out of code to #{:?}", insn_ptr))?; } - true + Ok(()) } diff --git a/programs/native/sobpf/src/lib.rs b/programs/native/sobpf/src/lib.rs index c34aa85f6..1d50435d5 100644 --- a/programs/native/sobpf/src/lib.rs +++ b/programs/native/sobpf/src/lib.rs @@ -18,6 +18,7 @@ use solana_program_interface::loader_instruction::LoaderInstruction; use solana_program_interface::pubkey::Pubkey; use std::env; use std::io::prelude::*; +use std::io::Error; use std::mem; use std::path::PathBuf; use std::str; @@ -44,6 +45,17 @@ fn create_path(name: &str) -> PathBuf { ) } +fn create_vm(prog: &[u8]) -> Result { + let mut vm = rbpf::EbpfVmRaw::new(None)?; + vm.set_verifier(bpf_verifier::check)?; + vm.set_prog(&prog)?; + vm.register_helper( + rbpf::helpers::BPF_TRACE_PRINTK_IDX, + rbpf::helpers::bpf_trace_printf, + ); + Ok(vm) +} + #[allow(dead_code)] fn dump_prog(name: &str, prog: &[u8]) { let mut eight_bytes: Vec = Vec::new(); @@ -141,11 +153,13 @@ pub extern "C" fn process(keyed_accounts: &mut [KeyedAccount], tx_data: &[u8]) - } trace!("Call BPF, {} Instructions", prog.len() / 8); - let mut vm = rbpf::EbpfVmRaw::new(&prog, Some(bpf_verifier::verifier)); - vm.register_helper( - rbpf::helpers::BPF_TRACE_PRINTK_IDX, - rbpf::helpers::bpf_trace_printf, - ); + let vm = match create_vm(&prog) { + Ok(vm) => vm, + Err(e) => { + warn!("{}", e); + return false; + } + }; let mut v = serialize_state(&mut keyed_accounts[1..], &tx_data); if 0 == vm.prog_exec(v.as_mut_slice()) { diff --git a/src/bpf_verifier.rs b/src/bpf_verifier.rs deleted file mode 100644 index ca0045834..000000000 --- a/src/bpf_verifier.rs +++ /dev/null @@ -1,314 +0,0 @@ -use rbpf::ebpf; - -// This “verifier” performs simple checks when the eBPF program is loaded into the VM (before it is -// interpreted or JIT-compiled). - -fn verify_prog_len(prog: &[u8]) { - if prog.len() % ebpf::INSN_SIZE != 0 { - panic!( - "[Verifier] Error: eBPF program length must be a multiple of {:?} octets", - ebpf::INSN_SIZE - ); - } - if prog.len() > ebpf::PROG_MAX_SIZE { - panic!( - "[Verifier] Error: eBPF program length limited to {:?}, here {:?}", - ebpf::PROG_MAX_INSNS, - prog.len() / ebpf::INSN_SIZE - ); - } - if prog.is_empty() { - panic!("[Verifier] Error: program is empty"); - } - // TODO BPF program may deterministically exit even if the last - // instruction in the block is not an exit (might be earlier and jumped to) - // TODO need to validate more intelligently - // let last_insn = ebpf::get_insn(prog, (prog.len() / ebpf::INSN_SIZE) - 1); - // if last_insn.opc != ebpf::EXIT { - // panic!("[Verifier] Error: program does not end with “EXIT” instruction"); - // } -} - -fn verify_imm_nonzero(insn: &ebpf::Insn, insn_ptr: usize) { - if insn.imm == 0 { - panic!("[Verifier] Error: division by 0 (insn #{:?})", insn_ptr); - } -} - -fn verify_imm_endian(insn: &ebpf::Insn, insn_ptr: usize) { - match insn.imm { - 16 | 32 | 64 => return, - _ => panic!( - "[Verifier] Error: unsupported argument for LE/BE (insn #{:?})", - insn_ptr - ), - } -} - -fn verify_load_dw(prog: &[u8], insn_ptr: usize) { - // We know we can reach next insn since we enforce an EXIT insn at the end of program, while - // this function should be called only for LD_DW insn, that cannot be last in program. - let next_insn = ebpf::get_insn(prog, insn_ptr + 1); - if next_insn.opc != 0 { - panic!( - "[Verifier] Error: incomplete LD_DW instruction (insn #{:?})", - insn_ptr - ); - } -} - -fn verify_jmp_offset(prog: &[u8], insn_ptr: usize) { - let insn = ebpf::get_insn(prog, insn_ptr); - if insn.off == -1 { - panic!("[Verifier] Error: infinite loop (insn #{:?})", insn_ptr); - } - - let dst_insn_ptr = insn_ptr as isize + 1 + insn.off as isize; - if dst_insn_ptr < 0 || dst_insn_ptr as usize >= (prog.len() / ebpf::INSN_SIZE) { - panic!( - "[Verifier] Error: jump out of code to #{:?} (insn #{:?})", - dst_insn_ptr, insn_ptr - ); - } - - let dst_insn = ebpf::get_insn(prog, dst_insn_ptr as usize); - if dst_insn.opc == 0 { - panic!( - "[Verifier] Error: jump to middle of LD_DW at #{:?} (insn #{:?})", - dst_insn_ptr, insn_ptr - ); - } -} - -fn verify_registers(insn: &ebpf::Insn, store: bool, insn_ptr: usize) { - if insn.src > 10 { - panic!( - "[Verifier] Error: invalid source register (insn #{:?})", - insn_ptr - ); - } - - match (insn.dst, store) { - (0...9, _) | (10, true) => {} - (10, false) => panic!( - "[Verifier] Error: cannot write into register r10 (insn #{:?})", - insn_ptr - ), - (_, _) => panic!( - "[Verifier] Error: invalid destination register (insn #{:?})", - insn_ptr - ), - } -} - -pub fn verifier(prog: &[u8]) -> bool { - verify_prog_len(prog); - - let mut insn_ptr: usize = 0; - while insn_ptr * ebpf::INSN_SIZE < prog.len() { - let insn = ebpf::get_insn(prog, insn_ptr); - let mut store = false; - - match insn.opc { - // BPF_LD class - ebpf::LD_ABS_B => {} - ebpf::LD_ABS_H => {} - ebpf::LD_ABS_W => {} - ebpf::LD_ABS_DW => {} - ebpf::LD_IND_B => {} - ebpf::LD_IND_H => {} - ebpf::LD_IND_W => {} - ebpf::LD_IND_DW => {} - - ebpf::LD_DW_IMM => { - store = true; - verify_load_dw(prog, insn_ptr); - insn_ptr += 1; - } - - // BPF_LDX class - ebpf::LD_B_REG => {} - ebpf::LD_H_REG => {} - ebpf::LD_W_REG => {} - ebpf::LD_DW_REG => {} - - // BPF_ST class - ebpf::ST_B_IMM => store = true, - ebpf::ST_H_IMM => store = true, - ebpf::ST_W_IMM => store = true, - ebpf::ST_DW_IMM => store = true, - - // BPF_STX class - ebpf::ST_B_REG => store = true, - ebpf::ST_H_REG => store = true, - ebpf::ST_W_REG => store = true, - ebpf::ST_DW_REG => store = true, - ebpf::ST_W_XADD => { - unimplemented!(); - } - ebpf::ST_DW_XADD => { - unimplemented!(); - } - - // BPF_ALU class - ebpf::ADD32_IMM => {} - ebpf::ADD32_REG => {} - ebpf::SUB32_IMM => {} - ebpf::SUB32_REG => {} - ebpf::MUL32_IMM => {} - ebpf::MUL32_REG => {} - ebpf::DIV32_IMM => { - verify_imm_nonzero(&insn, insn_ptr); - } - ebpf::DIV32_REG => {} - ebpf::OR32_IMM => {} - ebpf::OR32_REG => {} - ebpf::AND32_IMM => {} - ebpf::AND32_REG => {} - ebpf::LSH32_IMM => {} - ebpf::LSH32_REG => {} - ebpf::RSH32_IMM => {} - ebpf::RSH32_REG => {} - ebpf::NEG32 => {} - ebpf::MOD32_IMM => { - verify_imm_nonzero(&insn, insn_ptr); - } - ebpf::MOD32_REG => {} - ebpf::XOR32_IMM => {} - ebpf::XOR32_REG => {} - ebpf::MOV32_IMM => {} - ebpf::MOV32_REG => {} - ebpf::ARSH32_IMM => {} - ebpf::ARSH32_REG => {} - ebpf::LE => { - verify_imm_endian(&insn, insn_ptr); - } - ebpf::BE => { - verify_imm_endian(&insn, insn_ptr); - } - - // BPF_ALU64 class - ebpf::ADD64_IMM => {} - ebpf::ADD64_REG => {} - ebpf::SUB64_IMM => {} - ebpf::SUB64_REG => {} - ebpf::MUL64_IMM => { - verify_imm_nonzero(&insn, insn_ptr); - } - ebpf::MUL64_REG => {} - ebpf::DIV64_IMM => { - verify_imm_nonzero(&insn, insn_ptr); - } - ebpf::DIV64_REG => {} - ebpf::OR64_IMM => {} - ebpf::OR64_REG => {} - ebpf::AND64_IMM => {} - ebpf::AND64_REG => {} - ebpf::LSH64_IMM => {} - ebpf::LSH64_REG => {} - ebpf::RSH64_IMM => {} - ebpf::RSH64_REG => {} - ebpf::NEG64 => {} - ebpf::MOD64_IMM => {} - ebpf::MOD64_REG => {} - ebpf::XOR64_IMM => {} - ebpf::XOR64_REG => {} - ebpf::MOV64_IMM => {} - ebpf::MOV64_REG => {} - ebpf::ARSH64_IMM => {} - ebpf::ARSH64_REG => {} - - // BPF_JMP class - ebpf::JA => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JEQ_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JEQ_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JGT_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JGT_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JGE_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JGE_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JLT_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JLT_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JLE_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JLE_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSET_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSET_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JNE_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JNE_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSGT_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSGT_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSGE_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSGE_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSLT_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSLT_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSLE_IMM => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::JSLE_REG => { - verify_jmp_offset(prog, insn_ptr); - } - ebpf::CALL => {} - ebpf::TAIL_CALL => unimplemented!(), - ebpf::EXIT => {} - - _ => { - panic!( - "[Verifier] Error: unknown eBPF opcode {:#2x} (insn #{:?})", - insn.opc, insn_ptr - ); - } - } - - verify_registers(&insn, store, insn_ptr); - - insn_ptr += 1; - } - - // insn_ptr should now be equal to number of instructions. - if insn_ptr != prog.len() / ebpf::INSN_SIZE { - panic!("[Verifier] Error: jumped out of code to #{:?}", insn_ptr); - } - - true -} diff --git a/src/lib.rs b/src/lib.rs index 00756bc7b..eeb91d366 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,6 @@ pub mod choose_gossip_peer_strategy; pub mod client; #[macro_use] pub mod cluster_info; -pub mod bpf_verifier; pub mod budget_program; pub mod drone; pub mod dynamic_program; @@ -96,7 +95,6 @@ extern crate log; extern crate nix; extern crate pnet_datalink; extern crate rayon; -extern crate rbpf; extern crate reqwest; extern crate ring; extern crate serde;