From a6723c423ed7046cfa6e86bffe1ecbadfa3a54b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Fri, 23 Jul 2021 15:52:51 +0200 Subject: [PATCH] Bumps solana_rbpf to v0.2.14 --- Cargo.lock | 4 +- cli/Cargo.toml | 2 +- cli/src/program.rs | 3 +- programs/bpf/Cargo.lock | 4 +- programs/bpf/Cargo.toml | 2 +- programs/bpf/tests/programs.rs | 7 +- programs/bpf_loader/Cargo.toml | 2 +- programs/bpf_loader/src/lib.rs | 20 +- programs/bpf_loader/src/syscalls.rs | 431 ++++++++++++++++------------ rbpf-cli/Cargo.toml | 2 +- rbpf-cli/src/main.rs | 4 +- 11 files changed, 271 insertions(+), 210 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 88eb92b07d01f8..952fa80aa1b10c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5830,9 +5830,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719" +checksum = "e27486ed1c74044866b529076b6aa9ca6fab9ec494d1835439ec84efc5575953" dependencies = [ "byteorder", "combine", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 631ce8c521e4ea..124bf07a632751 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -39,7 +39,7 @@ solana-config-program = { path = "../programs/config", version = "=1.8.0" } solana-faucet = { path = "../faucet", version = "=1.8.0" } solana-logger = { path = "../logger", version = "=1.8.0" } solana-net-utils = { path = "../net-utils", version = "=1.8.0" } -solana_rbpf = "=0.2.13" +solana_rbpf = "=0.2.14" solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.0" } solana-sdk = { path = "../sdk", version = "=1.8.0" } solana-transaction-status = { path = "../transaction-status", version = "=1.8.0" } diff --git a/cli/src/program.rs b/cli/src/program.rs index 8e5f1b77bcaf9c..07d33d558d7e03 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -1791,9 +1791,10 @@ fn read_and_verify_elf(program_location: &str) -> Result, Box>::from_elf( &program_data, - Some(|x| verifier::check(x)), + Some(verifier::check), Config { reject_unresolved_syscalls: true, + verify_mul64_imm_nonzero: true, // TODO: Remove me after feature gate ..Config::default() }, register_syscalls(&mut invoke_context).unwrap(), diff --git a/programs/bpf/Cargo.lock b/programs/bpf/Cargo.lock index ea8b23fb485c4b..18224175ae6807 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -3532,9 +3532,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719" +checksum = "e27486ed1c74044866b529076b6aa9ca6fab9ec494d1835439ec84efc5575953" dependencies = [ "byteorder 1.4.3", "combine", diff --git a/programs/bpf/Cargo.toml b/programs/bpf/Cargo.toml index 74881704c799ad..0f2e1cbbd3e31f 100644 --- a/programs/bpf/Cargo.toml +++ b/programs/bpf/Cargo.toml @@ -30,7 +30,7 @@ solana-bpf-loader-program = { path = "../bpf_loader", version = "=1.8.0" } solana-cli-output = { path = "../../cli-output", version = "=1.8.0" } solana-logger = { path = "../../logger", version = "=1.8.0" } solana-measure = { path = "../../measure", version = "=1.8.0" } -solana_rbpf = "=0.2.13" +solana_rbpf = "=0.2.14" solana-runtime = { path = "../../runtime", version = "=1.8.0" } solana-sdk = { path = "../../sdk", version = "=1.8.0" } solana-transaction-status = { path = "../../transaction-status", version = "=1.8.0" } diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index e652b1d66a3f8b..19b7ddb0a12ed1 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -1258,11 +1258,8 @@ fn test_program_bpf_call_depth() { let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction); assert!(result.is_ok()); - let instruction = Instruction::new_with_bincode( - program_id, - &ComputeBudget::default().max_call_depth, - vec![], - ); + let instruction = + Instruction::new_with_bincode(program_id, &ComputeBudget::default().max_call_depth, vec![]); let result = bank_client.send_and_confirm_instruction(&mint_keypair, instruction); assert!(result.is_err()); } diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index 1f35b74a03aad1..a113e94fe15856 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -24,7 +24,7 @@ sha3 = "0.9.1" solana-measure = { path = "../../measure", version = "=1.8.0" } solana-runtime = { path = "../../runtime", version = "=1.8.0" } solana-sdk = { path = "../../sdk", version = "=1.8.0" } -solana_rbpf = "=0.2.13" +solana_rbpf = "=0.2.14" thiserror = "1.0" [dev-dependencies] diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index b2b9a4d364de28..9186d97a6886fc 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -16,9 +16,8 @@ use log::{log_enabled, trace, Level::Trace}; use solana_measure::measure::Measure; use solana_rbpf::{ aligned_memory::AlignedMemory, - ebpf::{HOST_ALIGN, MM_HEAP_START}, + ebpf::HOST_ALIGN, error::{EbpfError, UserDefinedError}, - memory_region::MemoryRegion, static_analysis::Analysis, verifier::{self, VerifierError}, vm::{Config, EbpfVm, Executable, InstructionMeter}, @@ -83,6 +82,7 @@ pub fn create_executor( max_call_depth: compute_budget.max_call_depth, stack_frame_size: compute_budget.stack_frame_size, enable_instruction_tracing: log_enabled!(Trace), + verify_mul64_imm_nonzero: true, // TODO: Feature gate and then remove me ..Config::default() }; let mut executable = { @@ -98,10 +98,8 @@ pub fn create_executor( ) } .map_err(|e| map_ebpf_error(invoke_context, e))?; - let (_, elf_bytes) = executable - .get_text_bytes() - .map_err(|e| map_ebpf_error(invoke_context, e))?; - verifier::check(elf_bytes) + let text_bytes = executable.get_text_bytes().1; + verifier::check(text_bytes, &config) .map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?; if use_jit { if let Err(err) = executable.jit_compile() { @@ -150,10 +148,9 @@ pub fn create_vm<'a>( invoke_context: &'a mut dyn InvokeContext, ) -> Result, EbpfError> { let compute_budget = invoke_context.get_compute_budget(); - let heap = + let mut heap = AlignedMemory::new_with_size(compute_budget.heap_size.unwrap_or(HEAP_LENGTH), HOST_ALIGN); - let heap_region = MemoryRegion::new_from_slice(heap.as_slice(), MM_HEAP_START, 0, true); - let mut vm = EbpfVm::new(program, parameter_bytes, &[heap_region])?; + let mut vm = EbpfVm::new(program, heap.as_slice_mut(), parameter_bytes)?; syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?; Ok(vm) } @@ -915,7 +912,8 @@ mod tests { ) .unwrap(); let mut vm = - EbpfVm::::new(program.as_ref(), input, &[]).unwrap(); + EbpfVm::::new(program.as_ref(), &mut [], input) + .unwrap(); let mut instruction_meter = TestInstructionMeter { remaining: 10 }; vm.execute_program_interpreted(&mut instruction_meter) .unwrap(); @@ -927,7 +925,7 @@ mod tests { let prog = &[ 0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, // first half of lddw ]; - verifier::check(prog).unwrap(); + verifier::check(prog, &Config::default()).unwrap(); } #[test] diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index cb43dff22bdb87..81dfcdfdf71bc0 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -2,7 +2,7 @@ use crate::{alloc, BpfError}; use alloc::Alloc; use solana_rbpf::{ aligned_memory::AlignedMemory, - ebpf::MM_HEAP_START, + ebpf, error::EbpfError, memory_region::{AccessType, MemoryMapping}, question_mark, @@ -408,7 +408,7 @@ pub fn bind_syscall_context_objects<'a>( vm.bind_syscall_context_object( Box::new(SyscallAllocFree { aligned: *loader_id != bpf_loader_deprecated::id(), - allocator: BpfAllocator::new(heap, MM_HEAP_START), + allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), }), None, )?; @@ -2484,7 +2484,12 @@ mod tests { macro_rules! assert_access_violation { ($result:expr, $va:expr, $len:expr) => { match $result { - Err(EbpfError::AccessViolation(_, _, va, len, _)) if $va == va && len == len => (), + Err(EbpfError::AccessViolation(_, _, va, len, _)) if $va == va && $len == len => (), + Err(EbpfError::StackAccessViolation(_, _, va, len, _)) + if $va == va && $len == len => + { + () + } _ => panic!(), } }; @@ -2492,13 +2497,16 @@ mod tests { #[test] fn test_translate() { - const START: u64 = 100; + const START: u64 = 0x100000000; const LENGTH: u64 = 1000; let data = vec![0u8; LENGTH as usize]; let addr = data.as_ptr() as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion::new_from_slice(&data, START, 0, false)], + vec![ + MemoryRegion::default(), + MemoryRegion::new_from_slice(&data, START, 0, false), + ], &config, ) .unwrap(); @@ -2538,18 +2546,22 @@ mod tests { let addr = &pubkey as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: std::mem::size_of::() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: std::mem::size_of::() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let translated_pubkey = - translate_type::(&memory_mapping, 100, &bpf_loader::id(), true).unwrap(); + translate_type::(&memory_mapping, 0x100000000, &bpf_loader::id(), true) + .unwrap(); assert_eq!(pubkey, *translated_pubkey); // Instruction @@ -2560,23 +2572,31 @@ mod tests { ); let addr = &instruction as *const _ as u64; let mut memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 96, - len: std::mem::size_of::() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: std::mem::size_of::() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let translated_instruction = - translate_type::(&memory_mapping, 96, &bpf_loader::id(), true).unwrap(); + translate_type::(&memory_mapping, 0x100000000, &bpf_loader::id(), true) + .unwrap(); assert_eq!(instruction, *translated_instruction); - memory_mapping.resize_region::(0, 1).unwrap(); - assert!( - translate_type::(&memory_mapping, 100, &bpf_loader::id(), true).is_err() - ); + memory_mapping.resize_region::(1, 1).unwrap(); + assert!(translate_type::( + &memory_mapping, + 0x100000000, + &bpf_loader::id(), + true + ) + .is_err()); } #[test] @@ -2588,13 +2608,16 @@ mod tests { let addr = good_data.as_ptr() as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: good_data.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: good_data.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); @@ -2613,19 +2636,22 @@ mod tests { let mut data = vec![1u8, 2, 3, 4, 5]; let addr = data.as_ptr() as *const _ as u64; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: data.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: data.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let translated_data = translate_slice::( &memory_mapping, - 100, + 0x100000000, data.len() as u64, &bpf_loader::id(), true, @@ -2645,7 +2671,7 @@ mod tests { assert!(translate_slice::( &memory_mapping, - 100 - 1, + 0x100000000 - 1, data.len() as u64, &bpf_loader::id(), true, @@ -2656,19 +2682,22 @@ mod tests { let mut data = vec![1u64, 2, 3, 4, 5]; let addr = data.as_ptr() as *const _ as u64; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 96, - len: (data.len() * size_of::()) as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: (data.len() * size_of::()) as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let translated_data = translate_slice::( &memory_mapping, - 96, + 0x100000000, data.len() as u64, &bpf_loader::id(), true, @@ -2677,28 +2706,35 @@ mod tests { assert_eq!(data, translated_data); data[0] = 10; assert_eq!(data, translated_data); - assert!( - translate_slice::(&memory_mapping, 96, u64::MAX, &bpf_loader::id(), true,) - .is_err() - ); + assert!(translate_slice::( + &memory_mapping, + 0x100000000, + u64::MAX, + &bpf_loader::id(), + true, + ) + .is_err()); // Pubkeys let mut data = vec![solana_sdk::pubkey::new_rand(); 5]; let addr = data.as_ptr() as *const _ as u64; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: (data.len() * std::mem::size_of::()) as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: (data.len() * std::mem::size_of::()) as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let translated_data = translate_slice::( &memory_mapping, - 100, + 0x100000000, data.len() as u64, &bpf_loader::id(), true, @@ -2715,13 +2751,16 @@ mod tests { let addr = string.as_ptr() as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: string.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: string.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); @@ -2729,7 +2768,7 @@ mod tests { 42, translate_string_and_do( &memory_mapping, - 100, + 0x100000000, string.len() as u64, &bpf_loader::id(), true, @@ -2769,13 +2808,16 @@ mod tests { let addr = string.as_ptr() as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: string.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: string.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); @@ -2791,7 +2833,7 @@ mod tests { }; let mut result: Result> = Ok(0); syscall_panic.call( - 100, + 0x100000000, string.len() as u64, 42, 84, @@ -2817,7 +2859,7 @@ mod tests { }; let mut result: Result> = Ok(0); syscall_panic.call( - 100, + 0x100000000, string.len() as u64, 42, 84, @@ -2846,20 +2888,23 @@ mod tests { }; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: string.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: string.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let mut result: Result> = Ok(0); syscall_sol_log.call( - 100, + 0x100000000, string.len() as u64, 0, 0, @@ -2873,7 +2918,7 @@ mod tests { let mut result: Result> = Ok(0); syscall_sol_log.call( - 101, // AccessViolation + 0x100000001, // AccessViolation string.len() as u64, 0, 0, @@ -2881,10 +2926,10 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, 101, string.len() as u64); + assert_access_violation!(result, 0x100000001, string.len() as u64); let mut result: Result> = Ok(0); syscall_sol_log.call( - 100, + 0x100000000, string.len() as u64 * 2, // AccessViolation 0, 0, @@ -2892,10 +2937,10 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, 100, string.len() as u64 * 2); + assert_access_violation!(result, 0x100000000, string.len() as u64 * 2); let mut result: Result> = Ok(0); syscall_sol_log.call( - 100, + 0x100000000, string.len() as u64, 0, 0, @@ -2917,7 +2962,7 @@ mod tests { }; let mut result: Result> = Ok(0); syscall_sol_log.call( - 100, + 0x100000000, string.len() as u64, 0, 0, @@ -2928,7 +2973,7 @@ mod tests { result.unwrap(); let mut result: Result> = Ok(0); syscall_sol_log.call( - 100, + 0x100000000, string.len() as u64, 0, 0, @@ -2988,19 +3033,22 @@ mod tests { }; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: addr, - vm_addr: 100, - len: 32, - vm_gap_shift: 63, - is_writable: false, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: addr, + vm_addr: 0x100000000, + len: 32, + vm_gap_shift: 63, + is_writable: false, + }, + ], &config, ) .unwrap(); let mut result: Result> = Ok(0); - syscall_sol_pubkey.call(100, 0, 0, 0, 0, &memory_mapping, &mut result); + syscall_sol_pubkey.call(0x100000000, 0, 0, 0, 0, &memory_mapping, &mut result); result.unwrap(); assert_eq!(log.borrow().len(), 1); assert_eq!( @@ -3009,7 +3057,7 @@ mod tests { ); let mut result: Result> = Ok(0); syscall_sol_pubkey.call( - 101, // AccessViolation + 0x100000001, // AccessViolation 32, 0, 0, @@ -3017,7 +3065,7 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, 101, 32); + assert_access_violation!(result, 0x100000001, 32); let mut result: Result> = Ok(0); syscall_sol_pubkey.call(100, 32, 0, 0, 0, &memory_mapping, &mut result); assert_eq!( @@ -3035,18 +3083,19 @@ mod tests { { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion::new_from_slice( - heap.as_slice(), - MM_HEAP_START, - 0, - true, - )], + vec![ + MemoryRegion::default(), + MemoryRegion::new_from_slice(&[], ebpf::MM_PROGRAM_START, 0, false), + MemoryRegion::new_from_slice(&[], ebpf::MM_STACK_START, 4096, true), + MemoryRegion::new_from_slice(heap.as_slice(), ebpf::MM_HEAP_START, 0, true), + MemoryRegion::new_from_slice(&[], ebpf::MM_INPUT_START, 0, true), + ], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: true, - allocator: BpfAllocator::new(heap, MM_HEAP_START), + allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), }; let mut result: Result> = Ok(0); syscall.call(100, 0, 0, 0, 0, &memory_mapping, &mut result); @@ -3062,18 +3111,19 @@ mod tests { { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion::new_from_slice( - heap.as_slice(), - MM_HEAP_START, - 0, - true, - )], + vec![ + MemoryRegion::default(), + MemoryRegion::new_from_slice(&[], ebpf::MM_PROGRAM_START, 0, false), + MemoryRegion::new_from_slice(&[], ebpf::MM_STACK_START, 4096, true), + MemoryRegion::new_from_slice(heap.as_slice(), ebpf::MM_HEAP_START, 0, true), + MemoryRegion::new_from_slice(&[], ebpf::MM_INPUT_START, 0, true), + ], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: false, - allocator: BpfAllocator::new(heap, MM_HEAP_START), + allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), }; for _ in 0..100 { let mut result: Result> = Ok(0); @@ -3088,18 +3138,19 @@ mod tests { { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion::new_from_slice( - heap.as_slice(), - MM_HEAP_START, - 0, - true, - )], + vec![ + MemoryRegion::default(), + MemoryRegion::new_from_slice(&[], ebpf::MM_PROGRAM_START, 0, false), + MemoryRegion::new_from_slice(&[], ebpf::MM_STACK_START, 4096, true), + MemoryRegion::new_from_slice(heap.as_slice(), ebpf::MM_HEAP_START, 0, true), + MemoryRegion::new_from_slice(&[], ebpf::MM_INPUT_START, 0, true), + ], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: true, - allocator: BpfAllocator::new(heap, MM_HEAP_START), + allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), }; for _ in 0..12 { let mut result: Result> = Ok(0); @@ -3116,18 +3167,19 @@ mod tests { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion::new_from_slice( - heap.as_slice(), - MM_HEAP_START, - 0, - true, - )], + vec![ + MemoryRegion::default(), + MemoryRegion::new_from_slice(&[], ebpf::MM_PROGRAM_START, 0, false), + MemoryRegion::new_from_slice(&[], ebpf::MM_STACK_START, 4096, true), + MemoryRegion::new_from_slice(heap.as_slice(), ebpf::MM_HEAP_START, 0, true), + MemoryRegion::new_from_slice(&[], ebpf::MM_INPUT_START, 0, true), + ], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: true, - allocator: BpfAllocator::new(heap, MM_HEAP_START), + allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), }; let mut result: Result> = Ok(0); syscall.call( @@ -3161,48 +3213,49 @@ mod tests { pub len: usize, } let mock_slice1 = MockSlice { - addr: 4096, + addr: 0x300000000, len: bytes1.len(), }; let mock_slice2 = MockSlice { - addr: 8192, + addr: 0x400000000, len: bytes2.len(), }; let bytes_to_hash = [mock_slice1, mock_slice2]; let hash_result = [0; HASH_BYTES]; let ro_len = bytes_to_hash.len() as u64; - let ro_va = 96; - let rw_va = 192; + let ro_va = 0x100000000; + let rw_va = 0x200000000; let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![ + MemoryRegion::default(), MemoryRegion { - host_addr: bytes1.as_ptr() as *const _ as u64, - vm_addr: 4096, - len: bytes1.len() as u64, + host_addr: bytes_to_hash.as_ptr() as *const _ as u64, + vm_addr: ro_va, + len: 32, vm_gap_shift: 63, is_writable: false, }, MemoryRegion { - host_addr: bytes2.as_ptr() as *const _ as u64, - vm_addr: 8192, - len: bytes2.len() as u64, + host_addr: hash_result.as_ptr() as *const _ as u64, + vm_addr: rw_va, + len: HASH_BYTES as u64, vm_gap_shift: 63, - is_writable: false, + is_writable: true, }, MemoryRegion { - host_addr: bytes_to_hash.as_ptr() as *const _ as u64, - vm_addr: 96, - len: 32, + host_addr: bytes1.as_ptr() as *const _ as u64, + vm_addr: bytes_to_hash[0].addr, + len: bytes1.len() as u64, vm_gap_shift: 63, is_writable: false, }, MemoryRegion { - host_addr: hash_result.as_ptr() as *const _ as u64, - vm_addr: rw_va, - len: HASH_BYTES as u64, + host_addr: bytes2.as_ptr() as *const _ as u64, + vm_addr: bytes_to_hash[1].addr, + len: bytes2.len() as u64, vm_gap_shift: 63, - is_writable: true, + is_writable: false, }, ], &config, @@ -3236,7 +3289,7 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, ro_va - 1, ro_len); + assert_access_violation!(result, ro_va - 1, 32); let mut result: Result> = Ok(0); syscall.call( ro_va, @@ -3247,7 +3300,7 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, ro_va, ro_len + 1); + assert_access_violation!(result, ro_va, 48); let mut result: Result> = Ok(0); syscall.call( ro_va, @@ -3275,16 +3328,19 @@ mod tests { // Test clock sysvar { let got_clock = Clock::default(); - let got_clock_va = 2048; + let got_clock_va = 0x100000000; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: &got_clock as *const _ as u64, - vm_addr: got_clock_va, - len: size_of::() as u64, - vm_gap_shift: 63, - is_writable: true, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: &got_clock as *const _ as u64, + vm_addr: got_clock_va, + len: size_of::() as u64, + vm_gap_shift: 63, + is_writable: true, + }, + ], &config, ) .unwrap(); @@ -3317,16 +3373,19 @@ mod tests { // Test epoch_schedule sysvar { let got_epochschedule = EpochSchedule::default(); - let got_epochschedule_va = 2048; + let got_epochschedule_va = 0x100000000; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: &got_epochschedule as *const _ as u64, - vm_addr: got_epochschedule_va, - len: size_of::() as u64, - vm_gap_shift: 63, - is_writable: true, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: &got_epochschedule as *const _ as u64, + vm_addr: got_epochschedule_va, + len: size_of::() as u64, + vm_gap_shift: 63, + is_writable: true, + }, + ], &config, ) .unwrap(); @@ -3367,16 +3426,19 @@ mod tests { // Test fees sysvar { let got_fees = Fees::default(); - let got_fees_va = 2048; + let got_fees_va = 0x100000000; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: &got_fees as *const _ as u64, - vm_addr: got_fees_va, - len: size_of::() as u64, - vm_gap_shift: 63, - is_writable: true, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: &got_fees as *const _ as u64, + vm_addr: got_fees_va, + len: size_of::() as u64, + vm_gap_shift: 63, + is_writable: true, + }, + ], &config, ) .unwrap(); @@ -3407,16 +3469,19 @@ mod tests { // Test rent sysvar { let got_rent = Rent::default(); - let got_rent_va = 2048; + let got_rent_va = 0x100000000; let memory_mapping = MemoryMapping::new::( - vec![MemoryRegion { - host_addr: &got_rent as *const _ as u64, - vm_addr: got_rent_va, - len: size_of::() as u64, - vm_gap_shift: 63, - is_writable: true, - }], + vec![ + MemoryRegion::default(), + MemoryRegion { + host_addr: &got_rent as *const _ as u64, + vm_addr: got_rent_va, + len: size_of::() as u64, + vm_gap_shift: 63, + is_writable: true, + }, + ], &config, ) .unwrap(); diff --git a/rbpf-cli/Cargo.toml b/rbpf-cli/Cargo.toml index 2ff5384da4b842..9e5f43bc708fbb 100644 --- a/rbpf-cli/Cargo.toml +++ b/rbpf-cli/Cargo.toml @@ -15,5 +15,5 @@ serde_json = "1.0.64" solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.8.0" } solana-logger = { path = "../logger", version = "=1.8.0" } solana-sdk = { path = "../sdk", version = "=1.8.0" } -solana_rbpf = "=0.2.13" +solana_rbpf = "=0.2.14" time = "0.2.25" diff --git a/rbpf-cli/src/main.rs b/rbpf-cli/src/main.rs index 3f64587c91fe19..b8f4ed4e1f64c7 100644 --- a/rbpf-cli/src/main.rs +++ b/rbpf-cli/src/main.rs @@ -206,8 +206,8 @@ native machine code before execting it in the virtual machine.", .unwrap(); if matches.is_present("verify") { - let (_, elf_bytes) = executable.get_text_bytes().unwrap(); - check(elf_bytes).unwrap(); + let text_bytes = executable.get_text_bytes().1; + check(text_bytes, &config).unwrap(); } executable.jit_compile().unwrap(); let analysis = Analysis::from_executable(executable.as_ref());