From cc75f576e2664f15e54668a6c7ccd7e5eab725b9 Mon Sep 17 00:00:00 2001 From: Trent Nelson Date: Mon, 13 Dec 2021 08:48:38 -0700 Subject: [PATCH] Revert "Bump solana_rbpf to version v0.2.14 (#18869)" This reverts commit 9d66458a40bebdfc5f98f73d8071e14920ef3979. --- Cargo.lock | 4 +- cli/Cargo.toml | 2 +- cli/src/program.rs | 3 +- programs/bpf/Cargo.lock | 4 +- programs/bpf/Cargo.toml | 2 +- programs/bpf_loader/Cargo.toml | 2 +- programs/bpf_loader/src/lib.rs | 29 +- programs/bpf_loader/src/syscalls.rs | 428 ++++++++++++---------------- rbpf-cli/src/main.rs | 4 +- sdk/src/feature_set.rs | 5 - 10 files changed, 211 insertions(+), 272 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40083e959462e9..e172c319af92aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5898,9 +5898,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.2.14" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27486ed1c74044866b529076b6aa9ca6fab9ec494d1835439ec84efc5575953" +checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719" dependencies = [ "byteorder", "combine", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 583560fc33796c..7f78587737d985 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -40,7 +40,7 @@ solana-config-program = { path = "../programs/config", version = "=1.8.7" } solana-faucet = { path = "../faucet", version = "=1.8.7" } solana-logger = { path = "../logger", version = "=1.8.7" } solana-net-utils = { path = "../net-utils", version = "=1.8.7" } -solana_rbpf = "=0.2.14" +solana_rbpf = "=0.2.13" solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.7" } solana-sdk = { path = "../sdk", version = "=1.8.7" } solana-transaction-status = { path = "../transaction-status", version = "=1.8.7" } diff --git a/cli/src/program.rs b/cli/src/program.rs index 7e597b6f997b32..c1ba6b2c7c839c 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -1991,10 +1991,9 @@ fn read_and_verify_elf(program_location: &str) -> Result, Box>::from_elf( &program_data, - Some(verifier::check), + Some(|x| verifier::check(x)), 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 57bc4e07c15dc8..faf97729294e8a 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -3698,9 +3698,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.2.14" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27486ed1c74044866b529076b6aa9ca6fab9ec494d1835439ec84efc5575953" +checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719" dependencies = [ "byteorder 1.3.4", "combine", diff --git a/programs/bpf/Cargo.toml b/programs/bpf/Cargo.toml index e0f857743768a2..f919de3674c48d 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.7" } solana-cli-output = { path = "../../cli-output", version = "=1.8.7" } solana-logger = { path = "../../logger", version = "=1.8.7" } solana-measure = { path = "../../measure", version = "=1.8.7" } -solana_rbpf = "=0.2.14" +solana_rbpf = "=0.2.13" solana-runtime = { path = "../../runtime", version = "=1.8.7" } solana-sdk = { path = "../../sdk", version = "=1.8.7" } solana-transaction-status = { path = "../../transaction-status", version = "=1.8.7" } diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index d4de0d89a17251..f1f5879ac187c3 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -21,7 +21,7 @@ sha3 = "0.9.1" solana-measure = { path = "../../measure", version = "=1.8.7" } solana-runtime = { path = "../../runtime", version = "=1.8.7" } solana-sdk = { path = "../../sdk", version = "=1.8.7" } -solana_rbpf = "=0.2.14" +solana_rbpf = "=0.2.13" thiserror = "1.0" [dev-dependencies] diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 73547d922bc78c..13fd075c1fc54d 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -17,8 +17,9 @@ use { solana_measure::measure::Measure, solana_rbpf::{ aligned_memory::AlignedMemory, - ebpf::HOST_ALIGN, + ebpf::{HOST_ALIGN, MM_HEAP_START}, error::{EbpfError, UserDefinedError}, + memory_region::MemoryRegion, static_analysis::Analysis, verifier::{self, VerifierError}, vm::{Config, EbpfVm, Executable, InstructionMeter}, @@ -34,7 +35,7 @@ use { feature_set::{ add_missing_program_error_mappings, close_upgradeable_program_accounts, fix_write_privs, reduce_required_deploy_balance, requestable_heap_size, - stop_verify_mul64_imm_nonzero, upgradeable_close_instruction, + upgradeable_close_instruction, }, ic_logger_msg, ic_msg, instruction::{AccountMeta, InstructionError}, @@ -88,8 +89,6 @@ pub fn create_executor( max_call_depth: bpf_compute_budget.max_call_depth, stack_frame_size: bpf_compute_budget.stack_frame_size, enable_instruction_tracing: log_enabled!(Trace), - verify_mul64_imm_nonzero: !invoke_context - .is_feature_active(&stop_verify_mul64_imm_nonzero::id()), // TODO: Feature gate and then remove me ..Config::default() }; let mut executable = { @@ -105,8 +104,10 @@ pub fn create_executor( ) } .map_err(|e| map_ebpf_error(invoke_context, e))?; - let text_bytes = executable.get_text_bytes().1; - verifier::check(text_bytes, &config) + let (_, elf_bytes) = executable + .get_text_bytes() + .map_err(|e| map_ebpf_error(invoke_context, e))?; + verifier::check(elf_bytes) .map_err(|e| map_ebpf_error(invoke_context, EbpfError::UserError(e.into())))?; if use_jit { if let Err(err) = executable.jit_compile() { @@ -155,11 +156,18 @@ pub fn create_vm<'a>( invoke_context: &'a mut dyn InvokeContext, ) -> Result, EbpfError> { let bpf_compute_budget = invoke_context.get_bpf_compute_budget(); - let mut heap = AlignedMemory::new_with_size( + let heap_size = bpf_compute_budget.heap_size.unwrap_or(HEAP_LENGTH); + if invoke_context.is_feature_active(&requestable_heap_size::id()) { + let _ = invoke_context.get_compute_meter().borrow_mut().consume( + (heap_size as u64 / (32 * 1024)).saturating_sub(1) * bpf_compute_budget.heap_cost, + ); + } + let heap = AlignedMemory::new_with_size( bpf_compute_budget.heap_size.unwrap_or(HEAP_LENGTH), HOST_ALIGN, ); - let mut vm = EbpfVm::new(program, heap.as_slice_mut(), parameter_bytes)?; + 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])?; syscalls::bind_syscall_context_objects(loader_id, &mut vm, invoke_context, heap)?; Ok(vm) } @@ -1061,8 +1069,7 @@ mod tests { ) .unwrap(); let mut vm = - EbpfVm::::new(program.as_ref(), &mut [], input) - .unwrap(); + EbpfVm::::new(program.as_ref(), input, &[]).unwrap(); let mut instruction_meter = TestInstructionMeter { remaining: 10 }; vm.execute_program_interpreted(&mut instruction_meter) .unwrap(); @@ -1074,7 +1081,7 @@ mod tests { let prog = &[ 0x18, 0x00, 0x00, 0x00, 0x88, 0x77, 0x66, 0x55, // first half of lddw ]; - verifier::check(prog, &Config::default()).unwrap(); + verifier::check(prog).unwrap(); } #[test] diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index d8803dfc6e7ce7..32075bc9e56b2b 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -3,7 +3,7 @@ use { alloc::Alloc, solana_rbpf::{ aligned_memory::AlignedMemory, - ebpf, + ebpf::MM_HEAP_START, error::EbpfError, memory_region::{AccessType, MemoryMapping}, question_mark, @@ -455,7 +455,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, ebpf::MM_HEAP_START), + allocator: BpfAllocator::new(heap, MM_HEAP_START), }), None, )?; @@ -2781,9 +2781,7 @@ 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::StackAccessViolation(_, _, va, len, _)) - if $va == va && $len == len => {} + Err(EbpfError::AccessViolation(_, _, va, len, _)) if $va == va && len == len => (), _ => panic!(), } }; @@ -2797,16 +2795,13 @@ mod tests { #[test] fn test_translate() { - const START: u64 = 0x100000000; + const START: u64 = 100; 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::default(), - MemoryRegion::new_from_slice(&data, START, 0, false), - ], + vec![MemoryRegion::new_from_slice(&data, START, 0, false)], &config, ) .unwrap(); @@ -2846,22 +2841,18 @@ mod tests { let addr = &pubkey as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: std::mem::size_of::() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: std::mem::size_of::() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); let translated_pubkey = - translate_type::(&memory_mapping, 0x100000000, &bpf_loader::id(), true) - .unwrap(); + translate_type::(&memory_mapping, 100, &bpf_loader::id(), true).unwrap(); assert_eq!(pubkey, *translated_pubkey); // Instruction @@ -2872,31 +2863,23 @@ mod tests { ); let addr = &instruction as *const _ as u64; let mut memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: std::mem::size_of::() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 96, + len: std::mem::size_of::() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); let translated_instruction = - translate_type::(&memory_mapping, 0x100000000, &bpf_loader::id(), true) - .unwrap(); + translate_type::(&memory_mapping, 96, &bpf_loader::id(), true).unwrap(); assert_eq!(instruction, *translated_instruction); - memory_mapping.resize_region::(1, 1).unwrap(); - assert!(translate_type::( - &memory_mapping, - 0x100000000, - &bpf_loader::id(), - true - ) - .is_err()); + memory_mapping.resize_region::(0, 1).unwrap(); + assert!( + translate_type::(&memory_mapping, 100, &bpf_loader::id(), true).is_err() + ); } #[test] @@ -2908,16 +2891,13 @@ mod tests { let addr = good_data.as_ptr() as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: good_data.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: good_data.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); @@ -2936,22 +2916,19 @@ 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::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: data.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: data.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); let translated_data = translate_slice::( &memory_mapping, - 0x100000000, + 100, data.len() as u64, &bpf_loader::id(), true, @@ -2971,7 +2948,7 @@ mod tests { assert!(translate_slice::( &memory_mapping, - 0x100000000 - 1, + 100 - 1, data.len() as u64, &bpf_loader::id(), true, @@ -2982,22 +2959,19 @@ 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::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: (data.len() * size_of::()) as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 96, + len: (data.len() * size_of::()) as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); let translated_data = translate_slice::( &memory_mapping, - 0x100000000, + 96, data.len() as u64, &bpf_loader::id(), true, @@ -3006,35 +2980,28 @@ mod tests { assert_eq!(data, translated_data); data[0] = 10; assert_eq!(data, translated_data); - assert!(translate_slice::( - &memory_mapping, - 0x100000000, - u64::MAX, - &bpf_loader::id(), - true, - ) - .is_err()); + assert!( + translate_slice::(&memory_mapping, 96, 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::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: (data.len() * std::mem::size_of::()) as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + 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, - 0x100000000, + 100, data.len() as u64, &bpf_loader::id(), true, @@ -3051,16 +3018,13 @@ mod tests { let addr = string.as_ptr() as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: string.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: string.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); @@ -3068,7 +3032,7 @@ mod tests { 42, translate_string_and_do( &memory_mapping, - 0x100000000, + 100, string.len() as u64, &bpf_loader::id(), true, @@ -3108,16 +3072,13 @@ mod tests { let addr = string.as_ptr() as *const _ as u64; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: string.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: string.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); @@ -3133,7 +3094,7 @@ mod tests { }; let mut result: Result> = Ok(0); syscall_panic.call( - 0x100000000, + 100, string.len() as u64, 42, 84, @@ -3159,7 +3120,7 @@ mod tests { }; let mut result: Result> = Ok(0); syscall_panic.call( - 0x100000000, + 100, string.len() as u64, 42, 84, @@ -3188,23 +3149,20 @@ mod tests { }; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: string.len() as u64, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: string.len() as u64, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); let mut result: Result> = Ok(0); syscall_sol_log.call( - 0x100000000, + 100, string.len() as u64, 0, 0, @@ -3218,7 +3176,7 @@ mod tests { let mut result: Result> = Ok(0); syscall_sol_log.call( - 0x100000001, // AccessViolation + 101, // AccessViolation string.len() as u64, 0, 0, @@ -3226,10 +3184,10 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, 0x100000001, string.len() as u64); + assert_access_violation!(result, 101, string.len() as u64); let mut result: Result> = Ok(0); syscall_sol_log.call( - 0x100000000, + 100, string.len() as u64 * 2, // AccessViolation 0, 0, @@ -3237,10 +3195,10 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, 0x100000000, string.len() as u64 * 2); + assert_access_violation!(result, 100, string.len() as u64 * 2); let mut result: Result> = Ok(0); syscall_sol_log.call( - 0x100000000, + 100, string.len() as u64, 0, 0, @@ -3262,7 +3220,7 @@ mod tests { }; let mut result: Result> = Ok(0); syscall_sol_log.call( - 0x100000000, + 100, string.len() as u64, 0, 0, @@ -3273,7 +3231,7 @@ mod tests { result.unwrap(); let mut result: Result> = Ok(0); syscall_sol_log.call( - 0x100000000, + 100, string.len() as u64, 0, 0, @@ -3333,22 +3291,19 @@ mod tests { }; let config = Config::default(); let memory_mapping = MemoryMapping::new::( - vec![ - MemoryRegion::default(), - MemoryRegion { - host_addr: addr, - vm_addr: 0x100000000, - len: 32, - vm_gap_shift: 63, - is_writable: false, - }, - ], + vec![MemoryRegion { + host_addr: addr, + vm_addr: 100, + len: 32, + vm_gap_shift: 63, + is_writable: false, + }], &config, ) .unwrap(); let mut result: Result> = Ok(0); - syscall_sol_pubkey.call(0x100000000, 0, 0, 0, 0, &memory_mapping, &mut result); + syscall_sol_pubkey.call(100, 0, 0, 0, 0, &memory_mapping, &mut result); result.unwrap(); assert_eq!(log.borrow().len(), 1); assert_eq!( @@ -3357,7 +3312,7 @@ mod tests { ); let mut result: Result> = Ok(0); syscall_sol_pubkey.call( - 0x100000001, // AccessViolation + 101, // AccessViolation 32, 0, 0, @@ -3365,7 +3320,7 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, 0x100000001, 32); + assert_access_violation!(result, 101, 32); let mut result: Result> = Ok(0); syscall_sol_pubkey.call(100, 32, 0, 0, 0, &memory_mapping, &mut result); assert_eq!( @@ -3383,19 +3338,18 @@ mod tests { { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let memory_mapping = MemoryMapping::new::( - 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), - ], + vec![MemoryRegion::new_from_slice( + heap.as_slice(), + MM_HEAP_START, + 0, + true, + )], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: true, - allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), + allocator: BpfAllocator::new(heap, MM_HEAP_START), }; let mut result: Result> = Ok(0); syscall.call(100, 0, 0, 0, 0, &memory_mapping, &mut result); @@ -3411,19 +3365,18 @@ mod tests { { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let memory_mapping = MemoryMapping::new::( - 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), - ], + vec![MemoryRegion::new_from_slice( + heap.as_slice(), + MM_HEAP_START, + 0, + true, + )], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: false, - allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), + allocator: BpfAllocator::new(heap, MM_HEAP_START), }; for _ in 0..100 { let mut result: Result> = Ok(0); @@ -3438,19 +3391,18 @@ mod tests { { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let memory_mapping = MemoryMapping::new::( - 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), - ], + vec![MemoryRegion::new_from_slice( + heap.as_slice(), + MM_HEAP_START, + 0, + true, + )], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: true, - allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), + allocator: BpfAllocator::new(heap, MM_HEAP_START), }; for _ in 0..12 { let mut result: Result> = Ok(0); @@ -3467,19 +3419,18 @@ mod tests { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); let config = Config::default(); let memory_mapping = MemoryMapping::new::( - 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), - ], + vec![MemoryRegion::new_from_slice( + heap.as_slice(), + MM_HEAP_START, + 0, + true, + )], &config, ) .unwrap(); let mut syscall = SyscallAllocFree { aligned: true, - allocator: BpfAllocator::new(heap, ebpf::MM_HEAP_START), + allocator: BpfAllocator::new(heap, MM_HEAP_START), }; let mut result: Result> = Ok(0); syscall.call( @@ -3508,49 +3459,48 @@ mod tests { let bytes2 = "flurbos"; let mock_slice1 = MockSlice { - vm_addr: 0x300000000, + vm_addr: 4096, len: bytes1.len(), }; let mock_slice2 = MockSlice { - vm_addr: 0x400000000, + vm_addr: 8192, 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 = 0x100000000; - let rw_va = 0x200000000; + let ro_va = 96; + let rw_va = 192; let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![ - MemoryRegion::default(), MemoryRegion { - host_addr: bytes_to_hash.as_ptr() as *const _ as u64, - vm_addr: ro_va, - len: 32, + host_addr: bytes1.as_ptr() as *const _ as u64, + vm_addr: 4096, + 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: 8192, + len: bytes2.len() as u64, vm_gap_shift: 63, - is_writable: true, + is_writable: false, }, MemoryRegion { - host_addr: bytes1.as_ptr() as *const _ as u64, - vm_addr: bytes_to_hash[0].vm_addr, - len: bytes1.len() as u64, + host_addr: bytes_to_hash.as_ptr() as *const _ as u64, + vm_addr: 96, + len: 32, vm_gap_shift: 63, is_writable: false, }, MemoryRegion { - host_addr: bytes2.as_ptr() as *const _ as u64, - vm_addr: bytes_to_hash[1].vm_addr, - 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, }, ], &config, @@ -3584,7 +3534,7 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, ro_va - 1, 32); + assert_access_violation!(result, ro_va - 1, ro_len); let mut result: Result> = Ok(0); syscall.call( ro_va, @@ -3595,7 +3545,7 @@ mod tests { &memory_mapping, &mut result, ); - assert_access_violation!(result, ro_va, 48); + assert_access_violation!(result, ro_va, ro_len + 1); let mut result: Result> = Ok(0); syscall.call( ro_va, @@ -3623,19 +3573,16 @@ mod tests { // Test clock sysvar { let got_clock = Clock::default(); - let got_clock_va = 0x100000000; + let got_clock_va = 2048; let memory_mapping = MemoryMapping::new::( - 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, - }, - ], + 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, + }], &config, ) .unwrap(); @@ -3668,19 +3615,16 @@ mod tests { // Test epoch_schedule sysvar { let got_epochschedule = EpochSchedule::default(); - let got_epochschedule_va = 0x100000000; + let got_epochschedule_va = 2048; let memory_mapping = MemoryMapping::new::( - 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, - }, - ], + 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, + }], &config, ) .unwrap(); @@ -3721,19 +3665,16 @@ mod tests { // Test fees sysvar { let got_fees = Fees::default(); - let got_fees_va = 0x100000000; + let got_fees_va = 2048; let memory_mapping = MemoryMapping::new::( - 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, - }, - ], + 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, + }], &config, ) .unwrap(); @@ -3764,19 +3705,16 @@ mod tests { // Test rent sysvar { let got_rent = Rent::default(); - let got_rent_va = 0x100000000; + let got_rent_va = 2048; let memory_mapping = MemoryMapping::new::( - 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, - }, - ], + 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, + }], &config, ) .unwrap(); diff --git a/rbpf-cli/src/main.rs b/rbpf-cli/src/main.rs index 985f2ea0f0d181..39ba349bddcece 100644 --- a/rbpf-cli/src/main.rs +++ b/rbpf-cli/src/main.rs @@ -205,8 +205,8 @@ native machine code before execting it in the virtual machine.", .unwrap(); if matches.is_present("verify") { - let text_bytes = executable.get_text_bytes().1; - check(text_bytes, &config).unwrap(); + let (_, elf_bytes) = executable.get_text_bytes().unwrap(); + check(elf_bytes).unwrap(); } executable.jit_compile().unwrap(); let analysis = Analysis::from_executable(executable.as_ref()); diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index fe6d843a76cf0d..c3dc05879a1187 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -165,10 +165,6 @@ pub mod libsecp256k1_0_5_upgrade_enabled { solana_sdk::declare_id!("DhsYfRjxfnh2g7HKJYSzT79r74Afa1wbHkAgHndrA1oy"); } -pub mod stop_verify_mul64_imm_nonzero { - solana_sdk::declare_id!("EHFwHg2vhwUb7ifm7BuY9RMbsyt1rS1rUii7yeDJtGnN"); -} - pub mod merge_nonce_error_into_system_error { solana_sdk::declare_id!("21AWDosvp3pBamFW91KB35pNoaoZVTM7ess8nr2nt53B"); } @@ -302,7 +298,6 @@ lazy_static! { (neon_evm_compute_budget::id(), "bump neon_evm's compute budget"), (rent_for_sysvars::id(), "collect rent from accounts owned by sysvars"), (libsecp256k1_0_5_upgrade_enabled::id(), "upgrade libsecp256k1 to v0.5.0"), - (stop_verify_mul64_imm_nonzero::id(), "Sets rbpf vm config verify_mul64_imm_nonzero to false"), (merge_nonce_error_into_system_error::id(), "merge NonceError into SystemError"), (spl_token_v2_set_authority_fix::id(), "spl-token set_authority fix"), (stake_merge_with_unmatched_credits_observed::id(), "allow merging active stakes with unmatched credits_observed #18985"),