diff --git a/Cargo.lock b/Cargo.lock index 86bacec2e38a45..6db656d1f43103 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1671,9 +1671,9 @@ dependencies = [ [[package]] name = "goblin" -version = "0.3.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c" +checksum = "0b1800b95efee8ad4ef04517d4d69f8e209e763b1668f1179aeeedd0e454da55" dependencies = [ "log 0.4.14", "plain", @@ -5939,9 +5939,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c44596a3613a44f76a7f6e5205464a1e78d1529fa19e8eacde0b9e55a6387f50" +checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719" dependencies = [ "byteorder", "combine", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 7d02882a419ff0..9180183b30d460 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -40,7 +40,7 @@ solana-config-program = { path = "../programs/config", version = "=1.8.5" } solana-faucet = { path = "../faucet", version = "=1.8.5" } solana-logger = { path = "../logger", version = "=1.8.5" } solana-net-utils = { path = "../net-utils", version = "=1.8.5" } -solana_rbpf = "=0.2.12" +solana_rbpf = "=0.2.13" solana-remote-wallet = { path = "../remote-wallet", version = "=1.8.5" } solana-sdk = { path = "../sdk", version = "=1.8.5" } solana-transaction-status = { path = "../transaction-status", version = "=1.8.5" } diff --git a/cli/src/program.rs b/cli/src/program.rs index 7a931f0c3a642a..060ca9502a7298 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -9,7 +9,7 @@ use bip39::{Language, Mnemonic, MnemonicType, Seed}; use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; use log::*; use solana_account_decoder::{UiAccountEncoding, UiDataSliceConfig}; -use solana_bpf_loader_program::{BpfError, ThisInstructionMeter}; +use solana_bpf_loader_program::{syscalls::register_syscalls, BpfError, ThisInstructionMeter}; use solana_clap_utils::{self, input_parsers::*, input_validators::*, keypair::*}; use solana_cli_output::{ CliProgram, CliProgramAccountType, CliProgramAuthority, CliProgramBuffer, CliProgramId, @@ -40,6 +40,7 @@ use solana_sdk::{ message::Message, native_token::Sol, packet::PACKET_DATA_SIZE, + process_instruction::MockInvokeContext, pubkey::Pubkey, signature::{keypair_from_seed, read_keypair_file, Keypair, Signature, Signer}, system_instruction::{self, SystemError}, @@ -1986,12 +1987,17 @@ fn read_and_verify_elf(program_location: &str) -> Result, Box>::from_elf( &program_data, Some(|x| verifier::check(x)), - Config::default(), + Config { + reject_unresolved_syscalls: true, + ..Config::default() + }, + register_syscalls(&mut invoke_context).unwrap(), ) .map_err(|err| format!("ELF error: {}", err))?; diff --git a/cli/tests/fixtures/noop.so b/cli/tests/fixtures/noop.so index 17ea5290910bc7..502681cf6e5f1b 100755 Binary files a/cli/tests/fixtures/noop.so and b/cli/tests/fixtures/noop.so differ diff --git a/programs/bpf/Cargo.lock b/programs/bpf/Cargo.lock index ae502e9b265087..545e7a756c9188 100644 --- a/programs/bpf/Cargo.lock +++ b/programs/bpf/Cargo.lock @@ -1159,9 +1159,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "goblin" -version = "0.3.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c69552f48b18aa6102ce0c82dd9bc9d3f8af5fc0a5797069b1b466b90570e39c" +checksum = "0b1800b95efee8ad4ef04517d4d69f8e209e763b1668f1179aeeedd0e454da55" dependencies = [ "log", "plain", @@ -3699,9 +3699,9 @@ dependencies = [ [[package]] name = "solana_rbpf" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c44596a3613a44f76a7f6e5205464a1e78d1529fa19e8eacde0b9e55a6387f50" +checksum = "fc1dced9892c2b0273318ef4d8486112ea7c7a7b8eb563a20e7858ad921b4719" dependencies = [ "byteorder 1.3.4", "combine", diff --git a/programs/bpf/Cargo.toml b/programs/bpf/Cargo.toml index 3d6a87079236fb..1342f23b18737b 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.5" } solana-cli-output = { path = "../../cli-output", version = "=1.8.5" } solana-logger = { path = "../../logger", version = "=1.8.5" } solana-measure = { path = "../../measure", version = "=1.8.5" } -solana_rbpf = "=0.2.12" +solana_rbpf = "=0.2.13" solana-runtime = { path = "../../runtime", version = "=1.8.5" } solana-sdk = { path = "../../sdk", version = "=1.8.5" } solana-transaction-status = { path = "../../transaction-status", version = "=1.8.5" } diff --git a/programs/bpf/benches/bpf_loader.rs b/programs/bpf/benches/bpf_loader.rs index 0ca7dea17e6ade..852a8e1949e864 100644 --- a/programs/bpf/benches/bpf_loader.rs +++ b/programs/bpf/benches/bpf_loader.rs @@ -11,7 +11,7 @@ use solana_bpf_loader_program::{ ThisInstructionMeter, }; use solana_measure::measure::Measure; -use solana_rbpf::vm::{Config, Executable, InstructionMeter}; +use solana_rbpf::vm::{Config, Executable, InstructionMeter, SyscallRegistry}; use solana_runtime::{ bank::Bank, bank_client::BankClient, @@ -79,6 +79,7 @@ fn bench_program_create_executable(bencher: &mut Bencher) { &elf, None, Config::default(), + SyscallRegistry::default(), ) .unwrap(); }); @@ -97,10 +98,13 @@ fn bench_program_alu(bencher: &mut Bencher) { let mut invoke_context = MockInvokeContext::new(vec![]); let elf = load_elf("bench_alu").unwrap(); - let mut executable = - >::from_elf(&elf, None, Config::default()) - .unwrap(); - executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap()); + let mut executable = >::from_elf( + &elf, + None, + Config::default(), + register_syscalls(&mut invoke_context).unwrap(), + ) + .unwrap(); executable.jit_compile().unwrap(); let compute_meter = invoke_context.get_compute_meter(); let mut instruction_meter = ThisInstructionMeter { compute_meter }; @@ -273,10 +277,13 @@ fn bench_instruction_count_tuner(_bencher: &mut Bencher) { .unwrap(); let elf = load_elf("tuner").unwrap(); - let mut executable = - >::from_elf(&elf, None, Config::default()) - .unwrap(); - executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap()); + let executable = >::from_elf( + &elf, + None, + Config::default(), + register_syscalls(&mut invoke_context).unwrap(), + ) + .unwrap(); let compute_meter = invoke_context.get_compute_meter(); let mut instruction_meter = ThisInstructionMeter { compute_meter }; let mut vm = create_vm( diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index 853f85d163e427..e437449c349fc6 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -211,14 +211,16 @@ fn run_program( let mut instruction_meter = ThisInstructionMeter { compute_meter }; let config = Config { - max_call_depth: 20, - stack_frame_size: 4096, - enable_instruction_meter: true, enable_instruction_tracing: true, + ..Config::default() }; - let mut executable = - >::from_elf(&data, None, config).unwrap(); - executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap()); + let mut executable = >::from_elf( + &data, + None, + config, + register_syscalls(&mut invoke_context).unwrap(), + ) + .unwrap(); executable.jit_compile().unwrap(); let mut instruction_count = 0; diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index 959697257138a5..0caca8d8a94027 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -22,7 +22,7 @@ sha3 = "0.9.1" solana-measure = { path = "../../measure", version = "=1.8.5" } solana-runtime = { path = "../../runtime", version = "=1.8.5" } solana-sdk = { path = "../../sdk", version = "=1.8.5" } -solana_rbpf = "=0.2.12" +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 8bc01fb3aee8a7..cc01f61d8fc595 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -85,15 +85,20 @@ pub fn create_executor( let config = Config { max_call_depth: bpf_compute_budget.max_call_depth, stack_frame_size: bpf_compute_budget.stack_frame_size, - enable_instruction_meter: true, enable_instruction_tracing: log_enabled!(Trace), + ..Config::default() }; let mut executable = { let keyed_accounts = invoke_context.get_keyed_accounts()?; let program = keyed_account_at_index(keyed_accounts, program_account_index)?; let account = program.try_account_ref()?; let data = &account.data()[program_data_offset..]; - >::from_elf(data, None, config) + >::from_elf( + data, + None, + config, + syscall_registry, + ) } .map_err(|e| map_ebpf_error(invoke_context, e))?; let (_, elf_bytes) = executable @@ -101,7 +106,6 @@ pub fn create_executor( .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())))?; - executable.set_syscall_registry(syscall_registry); if use_jit { if let Err(err) = executable.jit_compile() { ic_msg!(invoke_context, "Failed to compile program {:?}", err); @@ -1000,6 +1004,7 @@ impl Executor for BpfExecutor { mod tests { use super::*; use rand::Rng; + use solana_rbpf::vm::SyscallRegistry; use solana_runtime::{bank::Bank, bank_client::BankClient}; use solana_sdk::{ account::{ @@ -1053,9 +1058,10 @@ mod tests { solana_rbpf::elf::register_bpf_function(&mut bpf_functions, 0, "entrypoint").unwrap(); let program = >::from_text_bytes( program, - bpf_functions, None, Config::default(), + SyscallRegistry::default(), + bpf_functions, ) .unwrap(); let mut vm = diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index 0bc3e3f5f1d204..409899b7f79699 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -2764,13 +2764,6 @@ mod tests { }; use std::str::FromStr; - const DEFAULT_CONFIG: Config = Config { - max_call_depth: 20, - stack_frame_size: 4_096, - enable_instruction_meter: true, - enable_instruction_tracing: false, - }; - macro_rules! assert_access_violation { ($result:expr, $va:expr, $len:expr) => { match $result { @@ -2792,9 +2785,10 @@ mod tests { 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)], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -2831,6 +2825,7 @@ mod tests { // Pubkey let pubkey = solana_sdk::pubkey::new_rand(); let addr = &pubkey as *const _ as u64; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![MemoryRegion { host_addr: addr, @@ -2839,7 +2834,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let translated_pubkey = @@ -2861,7 +2856,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let translated_instruction = @@ -2880,6 +2875,7 @@ mod tests { let data: Vec = vec![]; assert_eq!(0x1 as *const u8, data.as_ptr()); let addr = good_data.as_ptr() as *const _ as u64; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![MemoryRegion { host_addr: addr, @@ -2888,7 +2884,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let translated_data = translate_slice::( @@ -2913,7 +2909,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let translated_data = translate_slice::( @@ -2956,7 +2952,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let translated_data = translate_slice::( @@ -2986,7 +2982,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let translated_data = translate_slice::( @@ -3006,6 +3002,7 @@ mod tests { fn test_translate_string_and_do() { let string = "Gaggablaghblagh!"; let addr = string.as_ptr() as *const _ as u64; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![MemoryRegion { host_addr: addr, @@ -3014,7 +3011,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); assert_eq!( @@ -3037,9 +3034,9 @@ mod tests { #[test] #[should_panic(expected = "UserError(SyscallError(Abort))")] fn test_syscall_abort() { + let config = Config::default(); let memory_mapping = - MemoryMapping::new::(vec![MemoryRegion::default()], &DEFAULT_CONFIG) - .unwrap(); + MemoryMapping::new::(vec![MemoryRegion::default()], &config).unwrap(); let mut result: Result> = Ok(0); SyscallAbort::call( &mut SyscallAbort {}, @@ -3059,6 +3056,7 @@ mod tests { fn test_syscall_sol_panic() { let string = "Gaggablaghblagh!"; let addr = string.as_ptr() as *const _ as u64; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![MemoryRegion { host_addr: addr, @@ -3067,7 +3065,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -3135,6 +3133,7 @@ mod tests { loader_id: &bpf_loader::id(), enforce_aligned_host_addrs: true, }; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![MemoryRegion { host_addr: addr, @@ -3143,7 +3142,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -3248,7 +3247,8 @@ mod tests { compute_meter, logger, }; - let memory_mapping = MemoryMapping::new::(vec![], &DEFAULT_CONFIG).unwrap(); + let config = Config::default(); + let memory_mapping = MemoryMapping::new::(vec![], &config).unwrap(); let mut result: Result> = Ok(0); syscall_sol_log_u64.call(1, 2, 3, 4, 5, &memory_mapping, &mut result); @@ -3275,6 +3275,7 @@ mod tests { loader_id: &bpf_loader::id(), enforce_aligned_host_addrs: true, }; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![MemoryRegion { host_addr: addr, @@ -3283,7 +3284,7 @@ mod tests { vm_gap_shift: 63, is_writable: false, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -3318,6 +3319,7 @@ mod tests { #[test] fn test_syscall_sol_alloc_free() { + let config = Config::default(); // large alloc { let heap = AlignedMemory::new_with_size(100, HOST_ALIGN); @@ -3328,7 +3330,7 @@ mod tests { 0, true, )], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let mut syscall = SyscallAllocFree { @@ -3355,7 +3357,7 @@ mod tests { 0, true, )], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let mut syscall = SyscallAllocFree { @@ -3381,7 +3383,7 @@ mod tests { 0, true, )], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let mut syscall = SyscallAllocFree { @@ -3401,6 +3403,7 @@ mod tests { fn check_alignment() { 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(), @@ -3408,7 +3411,7 @@ mod tests { 0, true, )], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let mut syscall = SyscallAllocFree { @@ -3454,6 +3457,7 @@ mod tests { let ro_len = bytes_to_hash.len() as u64; let ro_va = 96; let rw_va = 192; + let config = Config::default(); let memory_mapping = MemoryMapping::new::( vec![ MemoryRegion { @@ -3485,7 +3489,7 @@ mod tests { is_writable: true, }, ], - &DEFAULT_CONFIG, + &config, ) .unwrap(); let compute_meter: Rc> = @@ -3551,6 +3555,7 @@ mod tests { #[test] fn test_syscall_get_sysvar() { + let config = Config::default(); // Test clock sysvar { let got_clock = Clock::default(); @@ -3564,7 +3569,7 @@ mod tests { vm_gap_shift: 63, is_writable: true, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -3606,7 +3611,7 @@ mod tests { vm_gap_shift: 63, is_writable: true, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -3656,7 +3661,7 @@ mod tests { vm_gap_shift: 63, is_writable: true, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); @@ -3696,7 +3701,7 @@ mod tests { vm_gap_shift: 63, is_writable: true, }], - &DEFAULT_CONFIG, + &config, ) .unwrap(); diff --git a/rbpf-cli/Cargo.toml b/rbpf-cli/Cargo.toml index a16e8c414fec4c..b22481ba4f09df 100644 --- a/rbpf-cli/Cargo.toml +++ b/rbpf-cli/Cargo.toml @@ -15,4 +15,4 @@ serde_json = "1.0.56" solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.8.5" } solana-logger = { path = "../logger", version = "=1.8.5" } solana-sdk = { path = "../sdk", version = "=1.8.5" } -solana_rbpf = "=0.2.12" +solana_rbpf = "=0.2.13" diff --git a/rbpf-cli/src/main.rs b/rbpf-cli/src/main.rs index 2f22d4378e42b3..82f843ec390938 100644 --- a/rbpf-cli/src/main.rs +++ b/rbpf-cli/src/main.rs @@ -185,14 +185,21 @@ native machine code before execting it in the virtual machine.", file.seek(SeekFrom::Start(0)).unwrap(); let mut contents = Vec::new(); file.read_to_end(&mut contents).unwrap(); + let syscall_registry = register_syscalls(&mut invoke_context).unwrap(); let mut executable = if magic == [0x7f, 0x45, 0x4c, 0x46] { - >::from_elf(&contents, None, config) - .map_err(|err| format!("Executable constructor failed: {:?}", err)) + >::from_elf( + &contents, + None, + config, + syscall_registry, + ) + .map_err(|err| format!("Executable constructor failed: {:?}", err)) } else { assemble::( std::str::from_utf8(contents.as_slice()).unwrap(), None, config, + syscall_registry, ) } .unwrap(); @@ -201,7 +208,6 @@ native machine code before execting it in the virtual machine.", let (_, elf_bytes) = executable.get_text_bytes().unwrap(); check(elf_bytes).unwrap(); } - executable.set_syscall_registry(register_syscalls(&mut invoke_context).unwrap()); executable.jit_compile().unwrap(); let analysis = Analysis::from_executable(executable.as_ref());