From 785454e3da3449cf547f5f8839ac3e473958a16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Thu, 21 Nov 2024 17:42:51 +0100 Subject: [PATCH] Adjusts SBPFVersion. --- benches/memory_mapping.rs | 12 +-- benches/vm_execution.rs | 14 +--- examples/disassemble.rs | 2 +- examples/to_json.rs | 2 +- fuzz/fuzz_targets/dumb.rs | 4 +- fuzz/fuzz_targets/smart.rs | 4 +- fuzz/fuzz_targets/smart_jit_diff.rs | 4 +- fuzz/fuzz_targets/smarter_jit_diff.rs | 4 +- fuzz/fuzz_targets/verify_semantic_aware.rs | 2 +- src/assembler.rs | 4 +- src/ebpf.rs | 4 +- src/elf.rs | 78 +++++++++--------- src/jit.rs | 8 +- src/memory_region.rs | 48 +++++------ src/program.rs | 38 +++++---- src/vm.rs | 4 +- tests/assembler.rs | 8 +- tests/disassembler.rs | 6 +- tests/elfs/strict_header.so | Bin 13816 -> 13816 bytes tests/execution.rs | 88 ++++++++++----------- tests/exercise_instructions.rs | 6 +- tests/verifier.rs | 40 +++++----- 22 files changed, 190 insertions(+), 190 deletions(-) diff --git a/benches/memory_mapping.rs b/benches/memory_mapping.rs index 1d78b708..91e77dee 100644 --- a/benches/memory_mapping.rs +++ b/benches/memory_mapping.rs @@ -73,7 +73,7 @@ macro_rules! bench_gapped_randomized_access_with_1024_entries { )]; let config = Config::default(); let memory_mapping = - $mem::new(memory_regions, &config, SBPFVersion::V2).unwrap(); + $mem::new(memory_regions, &config, SBPFVersion::V3).unwrap(); let mut prng = new_prng!(); bencher.iter(|| { assert!(memory_mapping @@ -111,7 +111,7 @@ macro_rules! bench_randomized_access_with_0001_entry { let content = vec![0; 1024 * 2]; let memory_regions = vec![MemoryRegion::new_readonly(&content[..], 0x100000000)]; let config = Config::default(); - let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V2).unwrap(); + let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V3).unwrap(); let mut prng = new_prng!(); bencher.iter(|| { let _ = memory_mapping.map( @@ -145,7 +145,7 @@ macro_rules! bench_randomized_access_with_n_entries { let (memory_regions, end_address) = generate_memory_regions($n, MemoryState::Readable, Some(&mut prng)); let config = Config::default(); - let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V2).unwrap(); + let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V3).unwrap(); bencher.iter(|| { let _ = memory_mapping.map( AccessType::Load, @@ -194,7 +194,7 @@ macro_rules! bench_randomized_mapping_with_n_entries { let (memory_regions, _end_address) = generate_memory_regions($n, MemoryState::Readable, Some(&mut prng)); let config = Config::default(); - let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V2).unwrap(); + let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V3).unwrap(); bencher.iter(|| { let _ = memory_mapping.map(AccessType::Load, 0x100000000, 1); }); @@ -243,7 +243,7 @@ macro_rules! bench_mapping_with_n_entries { let (memory_regions, _end_address) = generate_memory_regions($n, MemoryState::Readable, None); let config = Config::default(); - let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V2).unwrap(); + let memory_mapping = $mem::new(memory_regions, &config, SBPFVersion::V3).unwrap(); bencher.iter(|| { let _ = memory_mapping.map(AccessType::Load, 0x100000000, 1); }); @@ -301,7 +301,7 @@ fn do_bench_mapping_operation(bencher: &mut Bencher, op: MemoryOperation, vm_add MemoryRegion::new_writable(&mut mem2, 0x100000000 + 8), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); diff --git a/benches/vm_execution.rs b/benches/vm_execution.rs index 4404c927..2ad008e5 100644 --- a/benches/vm_execution.rs +++ b/benches/vm_execution.rs @@ -171,7 +171,7 @@ fn bench_jit_vs_interpreter_address_translation_stack_fixed(bencher: &mut Benche bencher, ADDRESS_TRANSLATION_STACK_CODE, Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }, 524289, @@ -185,10 +185,7 @@ fn bench_jit_vs_interpreter_address_translation_stack_dynamic(bencher: &mut Benc bench_jit_vs_interpreter( bencher, ADDRESS_TRANSLATION_STACK_CODE, - Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V2, - ..Config::default() - }, + Config::default(), 524289, &mut [], ); @@ -233,7 +230,7 @@ fn bench_jit_vs_interpreter_call_depth_fixed(bencher: &mut Bencher) { call function_foo exit", Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }, 137218, @@ -263,10 +260,7 @@ fn bench_jit_vs_interpreter_call_depth_dynamic(bencher: &mut Bencher) { call function_foo add r11, 4 exit", - Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V2, - ..Config::default() - }, + Config::default(), 176130, &mut [], ); diff --git a/examples/disassemble.rs b/examples/disassemble.rs index 454fec2e..d668cbaf 100644 --- a/examples/disassemble.rs +++ b/examples/disassemble.rs @@ -35,7 +35,7 @@ fn main() { let executable = Executable::::from_text_bytes( program, loader, - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); diff --git a/examples/to_json.rs b/examples/to_json.rs index db2b35c5..cb6b1e2e 100644 --- a/examples/to_json.rs +++ b/examples/to_json.rs @@ -31,7 +31,7 @@ fn to_json(program: &[u8]) -> String { let executable = Executable::::from_text_bytes( program, Arc::new(BuiltinProgram::new_mock()), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); diff --git a/fuzz/fuzz_targets/dumb.rs b/fuzz/fuzz_targets/dumb.rs index f22eba76..ee624f5b 100644 --- a/fuzz/fuzz_targets/dumb.rs +++ b/fuzz/fuzz_targets/dumb.rs @@ -31,7 +31,7 @@ fuzz_target!(|data: DumbFuzzData| { let function_registry = FunctionRegistry::default(); let syscall_registry = FunctionRegistry::>::default(); - if RequisiteVerifier::verify(&prog, &config, SBPFVersion::V2, &function_registry, &syscall_registry).is_err() { + if RequisiteVerifier::verify(&prog, &config, SBPFVersion::V3, &function_registry, &syscall_registry).is_err() { // verify please return; } @@ -42,7 +42,7 @@ fuzz_target!(|data: DumbFuzzData| { config, FunctionRegistry::default(), )), - SBPFVersion::V2, + SBPFVersion::V3, function_registry, ) .unwrap(); diff --git a/fuzz/fuzz_targets/smart.rs b/fuzz/fuzz_targets/smart.rs index 1bd66e45..9232b0d3 100644 --- a/fuzz/fuzz_targets/smart.rs +++ b/fuzz/fuzz_targets/smart.rs @@ -38,7 +38,7 @@ fuzz_target!(|data: FuzzData| { if RequisiteVerifier::verify( prog.into_bytes(), &config, - SBPFVersion::V2, + SBPFVersion::V3, &function_registry, &syscall_registry, ) @@ -54,7 +54,7 @@ fuzz_target!(|data: FuzzData| { config, FunctionRegistry::default(), )), - SBPFVersion::V2, + SBPFVersion::V3, function_registry, ) .unwrap(); diff --git a/fuzz/fuzz_targets/smart_jit_diff.rs b/fuzz/fuzz_targets/smart_jit_diff.rs index 2bc1c30b..b77ab691 100644 --- a/fuzz/fuzz_targets/smart_jit_diff.rs +++ b/fuzz/fuzz_targets/smart_jit_diff.rs @@ -45,7 +45,7 @@ fuzz_target!(|data: FuzzData| { if RequisiteVerifier::verify( prog.into_bytes(), &config, - SBPFVersion::V2, + SBPFVersion::V3, &function_registry, &syscall_registry, ) @@ -62,7 +62,7 @@ fuzz_target!(|data: FuzzData| { config, FunctionRegistry::default(), )), - SBPFVersion::V2, + SBPFVersion::V3, function_registry, ) .unwrap(); diff --git a/fuzz/fuzz_targets/smarter_jit_diff.rs b/fuzz/fuzz_targets/smarter_jit_diff.rs index 31e84767..ebfa6e04 100644 --- a/fuzz/fuzz_targets/smarter_jit_diff.rs +++ b/fuzz/fuzz_targets/smarter_jit_diff.rs @@ -35,7 +35,7 @@ fuzz_target!(|data: FuzzData| { if RequisiteVerifier::verify( prog.into_bytes(), &config, - SBPFVersion::V2, + SBPFVersion::V3, &function_registry, &syscall_registry, ) @@ -52,7 +52,7 @@ fuzz_target!(|data: FuzzData| { config, FunctionRegistry::default(), )), - SBPFVersion::V2, + SBPFVersion::V3, function_registry, ) .unwrap(); diff --git a/fuzz/fuzz_targets/verify_semantic_aware.rs b/fuzz/fuzz_targets/verify_semantic_aware.rs index b06bd265..68c7d4b1 100644 --- a/fuzz/fuzz_targets/verify_semantic_aware.rs +++ b/fuzz/fuzz_targets/verify_semantic_aware.rs @@ -30,7 +30,7 @@ fuzz_target!(|data: FuzzData| { RequisiteVerifier::verify( prog.into_bytes(), &config, - SBPFVersion::V2, + SBPFVersion::V3, &function_registry, &syscall_registry, ) diff --git a/src/assembler.rs b/src/assembler.rs index 30263794..40f58ba3 100644 --- a/src/assembler.rs +++ b/src/assembler.rs @@ -112,7 +112,7 @@ fn make_instruction_map(sbpf_version: SBPFVersion) -> HashMap HashMap Executable { .ok_or(ElfParserError::OutOfBounds)?, ); let config = loader.get_config(); - let sbpf_version = if config.enabled_sbpf_versions.end() == &SBPFVersion::V1 { + let sbpf_version = if config.enabled_sbpf_versions.end() == &SBPFVersion::V0 { if e_flags == EF_SBPF_V2 { - SBPFVersion::V2 + SBPFVersion::Reserved } else { - SBPFVersion::V1 + SBPFVersion::V0 } } else { match e_flags { - 0 => SBPFVersion::V1, - EF_SBPF_V2 => SBPFVersion::V2, + 0 => SBPFVersion::V0, + 1 => SBPFVersion::V1, + 2 => SBPFVersion::V2, + 3 => SBPFVersion::V3, _ => SBPFVersion::Reserved, } }; @@ -621,9 +623,9 @@ impl Executable { let config = loader.get_config(); let header = elf.file_header(); let sbpf_version = if header.e_flags == EF_SBPF_V2 { - SBPFVersion::V2 + SBPFVersion::Reserved } else { - SBPFVersion::V1 + SBPFVersion::V0 }; Self::validate(config, &elf, elf_bytes.as_slice())?; @@ -748,9 +750,9 @@ impl Executable { } let sbpf_version = if header.e_flags == EF_SBPF_V2 { - SBPFVersion::V2 + SBPFVersion::Reserved } else { - SBPFVersion::V1 + SBPFVersion::V0 }; if !config.enabled_sbpf_versions.contains(&sbpf_version) { return Err(ElfError::UnsupportedSBPFVersion); @@ -1010,9 +1012,9 @@ impl Executable { let mut syscall_cache = BTreeMap::new(); let text_section = get_section(elf, b".text")?; let sbpf_version = if elf.file_header().e_flags == EF_SBPF_V2 { - SBPFVersion::V2 + SBPFVersion::Reserved } else { - SBPFVersion::V1 + SBPFVersion::V0 }; // Fixup all program counter relative call instructions @@ -1086,7 +1088,7 @@ impl Executable { .file_range() .unwrap_or_default() .contains(&r_offset) - || sbpf_version == SBPFVersion::V1 + || sbpf_version == SBPFVersion::V0 { r_offset.saturating_add(BYTE_OFFSET_IMMEDIATE) } else { @@ -1121,7 +1123,7 @@ impl Executable { .file_range() .unwrap_or_default() .contains(&r_offset) - || sbpf_version == SBPFVersion::V1 + || sbpf_version == SBPFVersion::V0 { let imm_low_offset = imm_offset; let imm_high_offset = imm_low_offset.saturating_add(INSN_SIZE); @@ -1227,7 +1229,7 @@ impl Executable { refd_addr.checked_shr(32).unwrap_or_default() as u32, ); } else { - let refd_addr = if sbpf_version != SBPFVersion::V1 { + let refd_addr = if sbpf_version != SBPFVersion::V0 { // We're relocating an address inside a data section (eg .rodata). The // address is encoded as a simple u64. @@ -1298,7 +1300,7 @@ impl Executable { .or_insert_with(|| ebpf::hash_symbol_name(name)); if config.reject_broken_elfs && loader - .get_function_registry(SBPFVersion::V1) + .get_function_registry(SBPFVersion::V0) .lookup_by_key(hash) .is_none() { @@ -1776,7 +1778,7 @@ mod test { assert!(matches!( ElfExecutable::parse_ro_sections( &config, - &SBPFVersion::V1, + &SBPFVersion::V0, sections, &elf_bytes, ), @@ -1803,7 +1805,7 @@ mod test { assert!(matches!( ElfExecutable::parse_ro_sections( &config, - &SBPFVersion::V1, + &SBPFVersion::V0, sections, &elf_bytes, ), @@ -1815,7 +1817,7 @@ mod test { fn test_sh_offset_not_same_as_vaddr() { let config = Config { reject_broken_elfs: true, - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; let elf_bytes = [0u8; 512]; @@ -1826,7 +1828,7 @@ mod test { let sections: [(Option<&[u8]>, &Elf64Shdr); 1] = [(Some(b".text"), &s1)]; assert!(ElfExecutable::parse_ro_sections( &config, - &SBPFVersion::V1, + &SBPFVersion::V0, sections, &elf_bytes ) @@ -1836,7 +1838,7 @@ mod test { s1.sh_offset = 0; let sections: [(Option<&[u8]>, &Elf64Shdr); 1] = [(Some(b".text"), &s1)]; assert_eq!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V1, sections, &elf_bytes), + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V0, sections, &elf_bytes), Err(ElfError::ValueOutOfBounds) ); } @@ -1881,7 +1883,7 @@ mod test { let sections: [(Option<&[u8]>, &Elf64Shdr); 2] = [(Some(b".text"), &s1), (Some(b".rodata"), &s2)]; assert_eq!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V2, sections, &elf_bytes), + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V3, sections, &elf_bytes), Err(ElfError::ValueOutOfBounds) ); } @@ -1903,7 +1905,7 @@ mod test { let sections: [(Option<&[u8]>, &Elf64Shdr); 2] = [(Some(b".text"), &s1), (Some(b".rodata"), &s2)]; assert_eq!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V2, sections, &elf_bytes), + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V3, sections, &elf_bytes), Ok(Section::Borrowed( ebpf::MM_RODATA_START as usize + 10, 100..120 @@ -1927,7 +1929,7 @@ mod test { (Some(b".rodata"), &s3), ]; let ro_section = - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V1, sections, &elf_bytes) + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V0, sections, &elf_bytes) .unwrap(); let ro_region = get_ro_region(&ro_section, &elf_bytes); let owned_section = match &ro_section { @@ -1969,7 +1971,7 @@ mod test { ]; // V2 requires optimize_rodata=true let ro_section = - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V1, sections, &elf_bytes) + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V0, sections, &elf_bytes) .unwrap(); let ro_region = get_ro_region(&ro_section, &elf_bytes); let owned_section = match &ro_section { @@ -2009,7 +2011,7 @@ mod test { (Some(b".rodata"), &s3), ]; let ro_section = - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V1, sections, &elf_bytes) + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V0, sections, &elf_bytes) .unwrap(); let owned_section = match &ro_section { Section::Owned(_offset, data) => data.as_slice(), @@ -2068,7 +2070,7 @@ mod test { assert!(matches!( ElfExecutable::parse_ro_sections( &config, - &SBPFVersion::V1, // v2 requires optimize_rodata=true + &SBPFVersion::V0, // v2 requires optimize_rodata=true sections, &elf_bytes, ), @@ -2081,8 +2083,8 @@ mod test { let config = Config::default(); let elf_bytes = [0u8; 512]; for (vaddr_base, sbpf_version) in [ - (0, SBPFVersion::V1), - (ebpf::MM_RODATA_START, SBPFVersion::V2), + (0, SBPFVersion::V0), + (ebpf::MM_RODATA_START, SBPFVersion::V3), ] { let s1 = new_section(vaddr_base, 10); let s2 = new_section(vaddr_base + 20, 10); @@ -2109,8 +2111,8 @@ mod test { let config = Config::default(); let elf_bytes = [0u8; 512]; for (vaddr_base, sbpf_version) in [ - (0, SBPFVersion::V1), - (ebpf::MM_RODATA_START, SBPFVersion::V2), + (0, SBPFVersion::V0), + (ebpf::MM_RODATA_START, SBPFVersion::V3), ] { let s1 = new_section(vaddr_base, 10); let s2 = new_section(vaddr_base + 10, 10); @@ -2146,8 +2148,8 @@ mod test { let config = Config::default(); let elf_bytes = [0u8; 512]; for (vaddr_base, sbpf_version) in [ - (0, SBPFVersion::V1), - (ebpf::MM_RODATA_START, SBPFVersion::V2), + (0, SBPFVersion::V0), + (ebpf::MM_RODATA_START, SBPFVersion::V3), ] { let s1 = new_section(vaddr_base, 10); let s2 = new_section(vaddr_base + 10, 10); @@ -2199,7 +2201,7 @@ mod test { #[test] fn test_reject_rodata_stack_overlap() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V3, ..Config::default() }; let elf_bytes = [0u8; 512]; @@ -2209,7 +2211,7 @@ mod test { s1.sh_offset = 0; let sections: [(Option<&[u8]>, &Elf64Shdr); 1] = [(Some(b".text"), &s1)]; assert!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V2, sections, &elf_bytes) + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V3, sections, &elf_bytes) .is_ok() ); @@ -2218,7 +2220,7 @@ mod test { s1.sh_offset = 0; let sections: [(Option<&[u8]>, &Elf64Shdr); 1] = [(Some(b".text"), &s1)]; assert!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V2, sections, &elf_bytes) + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V3, sections, &elf_bytes) .is_ok() ); @@ -2227,7 +2229,7 @@ mod test { s1.sh_offset = 0; let sections: [(Option<&[u8]>, &Elf64Shdr); 1] = [(Some(b".text"), &s1)]; assert_eq!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V2, sections, &elf_bytes), + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V3, sections, &elf_bytes), Err(ElfError::ValueOutOfBounds) ); @@ -2236,7 +2238,7 @@ mod test { s1.sh_offset = 0; let sections: [(Option<&[u8]>, &Elf64Shdr); 1] = [(Some(b".text"), &s1)]; assert_eq!( - ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V2, sections, &elf_bytes), + ElfExecutable::parse_ro_sections(&config, &SBPFVersion::V3, sections, &elf_bytes), Err(ElfError::ValueOutOfBounds) ); } @@ -2288,7 +2290,7 @@ mod test { fn test_err_unresolved_syscall_reloc_64_32() { let loader = BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, reject_broken_elfs: true, ..Config::default() }, diff --git a/src/jit.rs b/src/jit.rs index d3d553fd..8dbb7312 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -1774,8 +1774,8 @@ mod tests { prog[pc * ebpf::INSN_SIZE] = ebpf::ADD64_IMM; } - let mut empty_program_machine_code_length_per_version = [0; 2]; - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + let mut empty_program_machine_code_length_per_version = [0; 4]; + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let empty_program_machine_code_length = { let config = Config { noop_instruction_rate: 0, @@ -1802,7 +1802,7 @@ mod tests { let config = Config { instruction_meter_checkpoint_distance: index * INSTRUCTION_COUNT * 2, noop_instruction_rate: 0, - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; let mut executable = create_mockup_executable(config, &prog); @@ -1822,7 +1822,7 @@ mod tests { MACHINE_CODE_PER_INSTRUCTION_METER_CHECKPOINT ); - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let empty_program_machine_code_length = empty_program_machine_code_length_per_version[sbpf_version as usize]; diff --git a/src/memory_region.rs b/src/memory_region.rs index e0ebfe61..de5ffe54 100644 --- a/src/memory_region.rs +++ b/src/memory_region.rs @@ -1026,13 +1026,13 @@ mod test { #[test] fn test_map_empty() { let config = Config::default(); - let m = UnalignedMemoryMapping::new(vec![], &config, SBPFVersion::V2).unwrap(); + let m = UnalignedMemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); assert_error!( m.map(AccessType::Load, ebpf::MM_INPUT_START, 8), "AccessViolation" ); - let m = AlignedMemoryMapping::new(vec![], &config, SBPFVersion::V2).unwrap(); + let m = AlignedMemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); assert_error!( m.map(AccessType::Load, ebpf::MM_INPUT_START, 8), "AccessViolation" @@ -1053,7 +1053,7 @@ mod test { MemoryRegion::new_writable_gapped(&mut mem1, ebpf::MM_STACK_START, 2), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); for frame in 0..4 { @@ -1081,7 +1081,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_INPUT_START + mem1.len() as u64 - 1), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ), "InvalidMemoryRegion(1)" ); @@ -1091,7 +1091,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_INPUT_START + mem1.len() as u64), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .is_ok()); } @@ -1117,7 +1117,7 @@ mod test { ), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1191,7 +1191,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_INPUT_START + 4), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_error!( @@ -1251,7 +1251,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_STACK_START), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_error!( @@ -1325,7 +1325,7 @@ mod test { ), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1367,7 +1367,7 @@ mod test { ), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); m.store(0x1122u16, ebpf::MM_INPUT_START).unwrap(); @@ -1394,7 +1394,7 @@ mod test { let m = MemoryMapping::new( vec![MemoryRegion::new_writable(&mut mem1, ebpf::MM_INPUT_START)], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1428,7 +1428,7 @@ mod test { MemoryRegion::new_writable(&mut mem2, ebpf::MM_INPUT_START + 7), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1456,7 +1456,7 @@ mod test { let m = MemoryMapping::new( vec![MemoryRegion::new_writable(&mut mem1, ebpf::MM_INPUT_START)], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); m.store(0x11u8, ebpf::MM_INPUT_START).unwrap(); @@ -1474,7 +1474,7 @@ mod test { MemoryRegion::new_writable(&mut mem2, ebpf::MM_INPUT_START + 4), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); m.store(0x1122334455667788u64, ebpf::MM_INPUT_START) @@ -1500,7 +1500,7 @@ mod test { let m = MemoryMapping::new( vec![MemoryRegion::new_readonly(&mem1, ebpf::MM_INPUT_START)], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_eq!(m.load::(ebpf::MM_INPUT_START).unwrap(), 0xff); @@ -1516,7 +1516,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_INPUT_START + 4), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); assert_eq!( @@ -1541,7 +1541,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_INPUT_START + mem1.len() as u64), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); m.store(0x11223344, ebpf::MM_INPUT_START).unwrap(); @@ -1559,7 +1559,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_INPUT_START + mem1.len() as u64), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1631,7 +1631,7 @@ mod test { MemoryRegion::new_readonly(&mem2, ebpf::MM_STACK_START), ], &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1688,7 +1688,7 @@ mod test { Ok(c.borrow().as_slice().as_ptr() as u64) }), &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1721,7 +1721,7 @@ mod test { Ok(c.borrow().as_slice().as_ptr() as u64) }), &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1766,7 +1766,7 @@ mod test { Ok(c.borrow().as_slice().as_ptr() as u64) }), &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1786,7 +1786,7 @@ mod test { vec![MemoryRegion::new_cow(&original, ebpf::MM_RODATA_START, 42)], Box::new(|_| Err(())), &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); @@ -1803,7 +1803,7 @@ mod test { vec![MemoryRegion::new_cow(&original, ebpf::MM_RODATA_START, 42)], Box::new(|_| Err(())), &config, - SBPFVersion::V2, + SBPFVersion::V3, ) .unwrap(); diff --git a/src/program.rs b/src/program.rs index c8a2a163..55ae5e5a 100644 --- a/src/program.rs +++ b/src/program.rs @@ -12,9 +12,13 @@ use { #[derive(Debug, PartialEq, PartialOrd, Eq, Clone, Copy)] pub enum SBPFVersion { /// The legacy format + V0, + /// SIMD-0166 V1, - /// The current format + /// SIMD-0174, SIMD-0173 V2, + /// SIMD-0178, SIMD-0179, SIMD-0189 + V3, /// Used for future versions Reserved, } @@ -22,69 +26,69 @@ pub enum SBPFVersion { impl SBPFVersion { /// Enable SIMD-0166: SBPF dynamic stack frames pub fn dynamic_stack_frames(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V1 } /// Enable SIMD-0174: SBPF arithmetics improvements pub fn enable_pqr(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// ... SIMD-0174 pub fn explicit_sign_extension_of_results(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// ... SIMD-0174 pub fn swap_sub_reg_imm_operands(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// ... SIMD-0174 pub fn disable_neg(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// Enable SIMD-0173: SBPF instruction encoding improvements pub fn callx_uses_src_reg(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// ... SIMD-0173 pub fn disable_lddw(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// ... SIMD-0173 pub fn disable_le(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// ... SIMD-0173 pub fn move_memory_instruction_classes(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V2 } /// Enable SIMD-0179: SBPF stricter verification constraints pub fn stricter_controlflow(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V3 } /// Enable SIMD-0178: SBPF Static Syscalls pub fn static_syscalls(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V3 } /// Enable SIMD-0189: SBPF stricter ELF headers pub fn enable_stricter_elf_headers(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V3 } /// ... SIMD-0189 pub fn enable_lower_bytecode_vaddr(self) -> bool { - self != SBPFVersion::V1 + self >= SBPFVersion::V3 } /// Ensure that rodata sections don't exceed their maximum allowed size and /// overlap with the stack pub fn reject_rodata_stack_overlap(self) -> bool { - self != SBPFVersion::V1 + self != SBPFVersion::V0 } /// Allow sh_addr != sh_offset in elf sections. pub fn enable_elf_vaddr(self) -> bool { - self != SBPFVersion::V1 + self != SBPFVersion::V0 } /// Calculate the target program counter for a CALL_IMM instruction depending on @@ -165,7 +169,7 @@ impl FunctionRegistry { ebpf::hash_symbol_name(&usize::from(value).to_le_bytes()) }; if loader - .get_function_registry(SBPFVersion::V1) + .get_function_registry(SBPFVersion::V0) .lookup_by_key(hash) .is_some() { diff --git a/src/vm.rs b/src/vm.rs index 690be74c..18ad7d5d 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -103,7 +103,7 @@ impl Default for Config { sanitize_user_provided_values: true, optimize_rodata: true, aligned_memory_mapping: true, - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V3, } } } @@ -251,7 +251,7 @@ pub struct CallFrame { /// /// let loader = std::sync::Arc::new(BuiltinProgram::new_mock()); /// let function_registry = FunctionRegistry::default(); -/// let mut executable = Executable::::from_text_bytes(prog, loader.clone(), SBPFVersion::V2, function_registry).unwrap(); +/// let mut executable = Executable::::from_text_bytes(prog, loader.clone(), SBPFVersion::V3, function_registry).unwrap(); /// executable.verify::().unwrap(); /// let mut context_object = TestContextObject::new(1); /// let sbpf_version = executable.get_sbpf_version(); diff --git a/tests/assembler.rs b/tests/assembler.rs index 45ce9931..2ce72f09 100644 --- a/tests/assembler.rs +++ b/tests/assembler.rs @@ -58,7 +58,7 @@ fn test_fill() { #[test] fn test_exit() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; assert_eq!( @@ -74,7 +74,7 @@ fn test_exit() { #[test] fn test_static_syscall() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }; @@ -87,7 +87,7 @@ fn test_static_syscall() { #[test] fn test_return() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }; assert_eq!( @@ -519,7 +519,7 @@ fn test_large_immediate() { #[test] fn test_tcp_sack() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }; let executable = assemble::( diff --git a/tests/disassembler.rs b/tests/disassembler.rs index e77d274f..cc55af86 100644 --- a/tests/disassembler.rs +++ b/tests/disassembler.rs @@ -45,7 +45,7 @@ fn test_empty() { #[test] fn test_exit() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; disasm!("entrypoint:\n exit\n", config); @@ -54,7 +54,7 @@ fn test_exit() { #[test] fn test_return() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }; disasm!("entrypoint:\n return\n", config); @@ -63,7 +63,7 @@ fn test_return() { #[test] fn test_static_syscall() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }; disasm!("entrypoint:\n syscall 5\n", config); diff --git a/tests/elfs/strict_header.so b/tests/elfs/strict_header.so index 5bea25c41c9ce0f02cfb7cc1614d9812efe658d8..fac0efc9da6945c07733812ba238f7d7e31c659e 100644 GIT binary patch delta 12 Tcmey7{UdvV0VDH9!{ep^D7OV^ delta 12 Tcmey7{UdvV0i(i3!{ep^DM$r| diff --git a/tests/execution.rs b/tests/execution.rs index 4c6b857c..c69dcb6f 100644 --- a/tests/execution.rs +++ b/tests/execution.rs @@ -179,9 +179,9 @@ macro_rules! test_syscall_asm { enable_instruction_tracing: true, ..Config::default() }; - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { config.enabled_sbpf_versions = sbpf_version..=sbpf_version; - let src = if sbpf_version == SBPFVersion::V1 { + let src = if sbpf_version == SBPFVersion::V0 { format!($source, $($syscall_name, )*) } else { format!($source, $($syscall_number, )*) @@ -813,7 +813,7 @@ fn test_pqr() { let mut executable = Executable::::from_text_bytes( &prog, loader.clone(), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -828,7 +828,7 @@ fn test_pqr() { let mut executable = Executable::::from_text_bytes( &prog, loader.clone(), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -862,7 +862,7 @@ fn test_err_divide_by_zero() { let mut executable = Executable::::from_text_bytes( &prog, loader.clone(), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -904,7 +904,7 @@ fn test_err_divide_overflow() { let mut executable = Executable::::from_text_bytes( &prog, loader.clone(), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -921,7 +921,7 @@ fn test_err_divide_overflow() { #[test] fn test_memory_instructions() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { enabled_sbpf_versions: sbpf_version..=sbpf_version, ..Config::default() @@ -1417,7 +1417,7 @@ fn test_stxb_chain() { #[test] fn test_exit_capped() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { enabled_sbpf_versions: sbpf_version..=sbpf_version, ..Config::default() @@ -1436,7 +1436,7 @@ fn test_exit_capped() { #[test] fn test_exit_without_value() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { enabled_sbpf_versions: sbpf_version..=sbpf_version, ..Config::default() @@ -1455,7 +1455,7 @@ fn test_exit_without_value() { #[test] fn test_exit() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { enabled_sbpf_versions: sbpf_version..=sbpf_version, ..Config::default() @@ -1475,7 +1475,7 @@ fn test_exit() { #[test] fn test_early_exit() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { enabled_sbpf_versions: sbpf_version..=sbpf_version, ..Config::default() @@ -2025,7 +2025,7 @@ fn test_string_stack() { #[test] fn test_err_dynamic_stack_out_of_bound() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V3, max_call_depth: 3, ..Config::default() }; @@ -2159,9 +2159,9 @@ fn test_entrypoint_exit() { // can't infer anything from the stack size so we track call depth // explicitly. Make sure exit still works with both fixed and dynamic // frames. - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, ..Config::default() }; @@ -2186,9 +2186,9 @@ fn test_entrypoint_exit() { #[test] fn test_stack_call_depth_tracking() { - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, max_call_depth: 2, ..Config::default() }; @@ -2247,7 +2247,7 @@ fn test_err_mem_access_out_of_bound() { let mut executable = Executable::::from_text_bytes( &prog, loader.clone(), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -2270,7 +2270,7 @@ fn test_err_mem_access_out_of_bound() { #[test] fn test_relative_call() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_elf!( @@ -2364,7 +2364,7 @@ fn test_err_callx_unregistered() { #[test] fn test_err_callx_oob_low() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -2618,10 +2618,10 @@ declare_builtin_function!( if depth > 0 { let mut config = Config::default(); let syscall_name = if version == 1 { - config.enabled_sbpf_versions = SBPFVersion::V1..=SBPFVersion::V1; + config.enabled_sbpf_versions = SBPFVersion::V0..=SBPFVersion::V0; "nested_vm_syscall" } else { - config.enabled_sbpf_versions = SBPFVersion::V2..=SBPFVersion::V2; + config.enabled_sbpf_versions = SBPFVersion::V3..=SBPFVersion::V3; "1" }; let mut loader = BuiltinProgram::new_loader_with_dense_registration(config); @@ -2655,7 +2655,7 @@ declare_builtin_function!( fn test_nested_vm_syscall() { let config = Config::default(); let mut context_object = TestContextObject::default(); - let mut memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V2).unwrap(); + let mut memory_mapping = MemoryMapping::new(vec![], &config, SBPFVersion::V3).unwrap(); // SBPFv1 let result = SyscallNestedVm::rust(&mut context_object, 1, 0, 1, 0, 0, &mut memory_mapping); @@ -2889,7 +2889,7 @@ fn test_far_jumps() { #[test] fn test_err_call_unresolved() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -2912,7 +2912,7 @@ fn test_err_call_unresolved() { #[test] fn test_syscall_reloc_64_32() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_elf!( @@ -2948,7 +2948,7 @@ fn test_reloc_64_relative_sbpfv1() { // [ 1] .text PROGBITS 0000000000000120 000120 000018 00 AX 0 0 8 // [ 2] .rodata PROGBITS 0000000000000138 000138 00000a 01 AMS 0 0 1 let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_elf!( @@ -2971,7 +2971,7 @@ fn test_reloc_64_relative_data_sbfv1() { // 00000000000001f8 : // 63: 08 01 00 00 00 00 00 00 let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_elf!( @@ -3000,7 +3000,7 @@ fn test_reloc_64_relative_data_sbpfv1() { // 00000000000001f8 : // 63: 00 00 00 00 08 01 00 00 let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_elf!( @@ -3016,7 +3016,7 @@ fn test_reloc_64_relative_data_sbpfv1() { #[test] fn test_load_elf_rodata_sbpfv1() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, optimize_rodata: false, ..Config::default() }; @@ -3036,7 +3036,7 @@ fn test_struct_func_pointer() { // which is a relocatable function pointer is not overwritten when // the function pointer is relocated at load time. let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_elf!( @@ -3274,7 +3274,7 @@ fn execute_generated_program(prog: &[u8]) -> bool { }, FunctionRegistry::default(), )), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ); let mut executable = if let Ok(executable) = executable { @@ -3381,7 +3381,7 @@ fn test_invalid_call_imm() { ]; let config = Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, enable_instruction_tracing: true, ..Config::default() }; @@ -3392,7 +3392,7 @@ fn test_invalid_call_imm() { let mut executable = Executable::::from_text_bytes( prog, Arc::new(loader), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -3409,8 +3409,8 @@ fn test_invalid_call_imm() { #[test] #[should_panic(expected = "Invalid syscall should have been detected in the verifier.")] fn test_invalid_exit_or_return() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { - let inst = if sbpf_version == SBPFVersion::V1 { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { + let inst = if sbpf_version == SBPFVersion::V0 { 0x9d } else { 0x95 @@ -3451,7 +3451,7 @@ fn test_invalid_exit_or_return() { #[test] fn test_err_fixed_stack_out_of_bound() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, max_call_depth: 3, ..Config::default() }; @@ -3474,7 +3474,7 @@ fn test_err_fixed_stack_out_of_bound() { #[test] fn test_execution_overrun() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3506,7 +3506,7 @@ fn test_execution_overrun() { #[test] fn test_mov32_reg_truncating() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3524,7 +3524,7 @@ fn test_mov32_reg_truncating() { #[test] fn test_lddw() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3645,7 +3645,7 @@ fn test_lddw() { #[test] fn test_le() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3703,7 +3703,7 @@ fn test_le() { #[test] fn test_neg() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3751,7 +3751,7 @@ fn test_neg() { #[test] fn test_callx_imm() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3775,7 +3775,7 @@ fn test_callx_imm() { #[test] fn test_mul() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3846,7 +3846,7 @@ fn test_mul() { #[test] fn test_div() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( @@ -3931,7 +3931,7 @@ fn test_div() { #[test] fn test_mod() { let config = Config { - enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1, + enabled_sbpf_versions: SBPFVersion::V0..=SBPFVersion::V0, ..Config::default() }; test_interpreter_and_jit_asm!( diff --git a/tests/exercise_instructions.rs b/tests/exercise_instructions.rs index 659c5770..2538b305 100644 --- a/tests/exercise_instructions.rs +++ b/tests/exercise_instructions.rs @@ -508,7 +508,7 @@ fn fuzz_alu() { } } -fn test_ins(v1: bool, ins: String, prng: &mut SmallRng, cu: u64) { +fn test_ins(v0: bool, ins: String, prng: &mut SmallRng, cu: u64) { let mut input = [0u8; 80]; prng.fill_bytes(&mut input); @@ -539,8 +539,8 @@ fn test_ins(v1: bool, ins: String, prng: &mut SmallRng, cu: u64) { ); let mut config = Config::default(); - if v1 { - config.enabled_sbpf_versions = SBPFVersion::V1..=SBPFVersion::V1; + if v0 { + config.enabled_sbpf_versions = SBPFVersion::V0..=SBPFVersion::V0; } test_interpreter_and_jit_asm!(asm.as_str(), config, input, (), TestContextObject::new(cu)); } diff --git a/tests/verifier.rs b/tests/verifier.rs index be7320f9..6234ba23 100644 --- a/tests/verifier.rs +++ b/tests/verifier.rs @@ -127,7 +127,7 @@ fn test_verifier_err_endian_size() { let executable = Executable::::from_text_bytes( prog, Arc::new(BuiltinProgram::new_mock()), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -146,7 +146,7 @@ fn test_verifier_err_incomplete_lddw() { let executable = Executable::::from_text_bytes( prog, Arc::new(BuiltinProgram::new_mock()), - SBPFVersion::V1, + SBPFVersion::V0, FunctionRegistry::default(), ) .unwrap(); @@ -156,13 +156,13 @@ fn test_verifier_err_incomplete_lddw() { #[test] #[should_panic(expected = "LDDWCannotBeLast")] fn test_verifier_err_lddw_cannot_be_last() { - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let prog = &[0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55]; let executable = Executable::::from_text_bytes( prog, Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, ..Config::default() }, FunctionRegistry::default(), @@ -179,14 +179,14 @@ fn test_verifier_err_lddw_cannot_be_last() { fn test_verifier_err_invalid_reg_dst() { // r11 is disabled when sbpf_version.dynamic_stack_frames()=false, and only sub and add are // allowed when sbpf_version.dynamic_stack_frames()=true - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let executable = assemble::( " mov r11, 1 exit", Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, ..Config::default() }, FunctionRegistry::default(), @@ -202,14 +202,14 @@ fn test_verifier_err_invalid_reg_dst() { fn test_verifier_err_invalid_reg_src() { // r11 is disabled when sbpf_version.dynamic_stack_frames()=false, and only sub and add are // allowed when sbpf_version.dynamic_stack_frames()=true - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let executable = assemble::( " mov r0, r11 exit", Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, ..Config::default() }, FunctionRegistry::default(), @@ -271,7 +271,7 @@ fn test_verifier_err_call_lddw() { #[test] #[should_panic(expected = "InvalidRegister(0)")] fn test_verifier_err_callx_cannot_use_r10() { - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let executable = assemble::( " callx r10 @@ -279,7 +279,7 @@ fn test_verifier_err_callx_cannot_use_r10() { ", Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, ..Config::default() }, FunctionRegistry::default(), @@ -340,7 +340,7 @@ fn test_verifier_err_unknown_opcode() { let executable = Executable::::from_text_bytes( prog, Arc::new(BuiltinProgram::new_mock()), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -357,7 +357,7 @@ fn test_verifier_unknown_sycall() { let executable = Executable::::from_text_bytes( prog, Arc::new(BuiltinProgram::new_mock()), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -378,7 +378,7 @@ fn test_verifier_known_syscall() { let executable = Executable::::from_text_bytes( prog, Arc::new(loader), - SBPFVersion::V2, + SBPFVersion::V3, FunctionRegistry::default(), ) .unwrap(); @@ -446,13 +446,13 @@ fn test_sdiv_disabled() { ]; for (opc, instruction) in instructions { - for highest_sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for highest_sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let assembly = format!("\n{instruction}\nexit"); let executable = assemble::( &assembly, Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V1..=highest_sbpf_version, + enabled_sbpf_versions: SBPFVersion::V0..=highest_sbpf_version, ..Config::default() }, FunctionRegistry::default(), @@ -460,7 +460,7 @@ fn test_sdiv_disabled() { ) .unwrap(); let result = executable.verify::(); - if highest_sbpf_version == SBPFVersion::V2 { + if highest_sbpf_version == SBPFVersion::V3 { assert!(result.is_ok()); } else { assert_error!(result, "VerifierError(UnknownOpCode({}, {}))", opc, 0); @@ -471,7 +471,7 @@ fn test_sdiv_disabled() { #[test] fn return_instr() { - for sbpf_version in [SBPFVersion::V1, SBPFVersion::V2] { + for sbpf_version in [SBPFVersion::V0, SBPFVersion::V3] { let prog = &[ 0xbf, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // mov64 r0, 2 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // exit (v1), syscall (v2) @@ -486,7 +486,7 @@ fn return_instr() { ) .unwrap(); let result = executable.verify::(); - if sbpf_version == SBPFVersion::V2 { + if sbpf_version == SBPFVersion::V3 { assert_error!(result, "VerifierError(InvalidSyscall(0))"); } else { assert_error!(result, "VerifierError(UnknownOpCode(157, 2))"); @@ -501,7 +501,7 @@ fn return_in_v2() { return", Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }, FunctionRegistry::default(), @@ -519,7 +519,7 @@ fn function_without_return() { add64 r0, 5", Arc::new(BuiltinProgram::new_loader( Config { - enabled_sbpf_versions: SBPFVersion::V2..=SBPFVersion::V2, + enabled_sbpf_versions: SBPFVersion::V3..=SBPFVersion::V3, ..Config::default() }, FunctionRegistry::default(),