Bumps solana_rbpf to v0.2.14 (#18869)

* Bumps solana_rbpf to v0.2.14

* Feature gate for verify_mul64_imm_nonzero as discussed in #17520.
This commit is contained in:
Alexander Meißner 2021-08-04 09:50:28 +02:00 committed by GitHub
parent 9912b73f9f
commit 0a63f65c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 274 additions and 207 deletions

4
Cargo.lock generated
View File

@ -5931,9 +5931,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",

View File

@ -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" }

View File

@ -1824,9 +1824,10 @@ fn read_and_verify_elf(program_location: &str) -> Result<Vec<u8>, Box<dyn std::e
// Verify the program
<dyn Executable<BpfError, ThisInstructionMeter>>::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(),

View File

@ -3364,9 +3364,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",

View File

@ -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" }

View File

@ -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]

View File

@ -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},
@ -31,7 +30,7 @@ use solana_sdk::{
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Clock,
entrypoint::{HEAP_LENGTH, SUCCESS},
feature_set::add_missing_program_error_mappings,
feature_set::{add_missing_program_error_mappings, stop_verify_mul64_imm_nonzero},
ic_logger_msg, ic_msg,
instruction::InstructionError,
keyed_account::{from_keyed_account, keyed_account_at_index},
@ -83,6 +82,8 @@ 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: !invoke_context
.is_feature_active(&stop_verify_mul64_imm_nonzero::id()), // TODO: Feature gate and then remove me
..Config::default()
};
let mut executable = {
@ -98,10 +99,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 +149,9 @@ pub fn create_vm<'a>(
invoke_context: &'a mut dyn InvokeContext,
) -> Result<EbpfVm<'a, BpfError, ThisInstructionMeter>, EbpfError<BpfError>> {
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)
}
@ -909,7 +907,8 @@ mod tests {
)
.unwrap();
let mut vm =
EbpfVm::<BpfError, TestInstructionMeter>::new(program.as_ref(), input, &[]).unwrap();
EbpfVm::<BpfError, TestInstructionMeter>::new(program.as_ref(), &mut [], input)
.unwrap();
let mut instruction_meter = TestInstructionMeter { remaining: 10 };
vm.execute_program_interpreted(&mut instruction_meter)
.unwrap();
@ -921,7 +920,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]

View File

@ -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,
@ -403,7 +403,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,
)?;
@ -2467,7 +2467,9 @@ 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!(),
}
};
@ -2475,13 +2477,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::<UserError>(
vec![MemoryRegion::new_from_slice(&data, START, 0, false)],
vec![
MemoryRegion::default(),
MemoryRegion::new_from_slice(&data, START, 0, false),
],
&config,
)
.unwrap();
@ -2521,18 +2526,22 @@ mod tests {
let addr = &pubkey as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
vm_addr: 100,
len: std::mem::size_of::<Pubkey>() as u64,
vm_gap_shift: 63,
is_writable: false,
}],
vec![
MemoryRegion::default(),
MemoryRegion {
host_addr: addr,
vm_addr: 0x100000000,
len: std::mem::size_of::<Pubkey>() as u64,
vm_gap_shift: 63,
is_writable: false,
},
],
&config,
)
.unwrap();
let translated_pubkey =
translate_type::<Pubkey>(&memory_mapping, 100, &bpf_loader::id(), true).unwrap();
translate_type::<Pubkey>(&memory_mapping, 0x100000000, &bpf_loader::id(), true)
.unwrap();
assert_eq!(pubkey, *translated_pubkey);
// Instruction
@ -2543,23 +2552,31 @@ mod tests {
);
let addr = &instruction as *const _ as u64;
let mut memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: addr,
vm_addr: 96,
len: std::mem::size_of::<Instruction>() as u64,
vm_gap_shift: 63,
is_writable: false,
}],
vec![
MemoryRegion::default(),
MemoryRegion {
host_addr: addr,
vm_addr: 0x100000000,
len: std::mem::size_of::<Instruction>() as u64,
vm_gap_shift: 63,
is_writable: false,
},
],
&config,
)
.unwrap();
let translated_instruction =
translate_type::<Instruction>(&memory_mapping, 96, &bpf_loader::id(), true).unwrap();
translate_type::<Instruction>(&memory_mapping, 0x100000000, &bpf_loader::id(), true)
.unwrap();
assert_eq!(instruction, *translated_instruction);
memory_mapping.resize_region::<BpfError>(0, 1).unwrap();
assert!(
translate_type::<Instruction>(&memory_mapping, 100, &bpf_loader::id(), true).is_err()
);
memory_mapping.resize_region::<BpfError>(1, 1).unwrap();
assert!(translate_type::<Instruction>(
&memory_mapping,
0x100000000,
&bpf_loader::id(),
true
)
.is_err());
}
#[test]
@ -2571,13 +2588,16 @@ mod tests {
let addr = good_data.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
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();
@ -2596,19 +2616,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::<UserError>(
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::<u8>(
&memory_mapping,
100,
0x100000000,
data.len() as u64,
&bpf_loader::id(),
true,
@ -2628,7 +2651,7 @@ mod tests {
assert!(translate_slice::<u8>(
&memory_mapping,
100 - 1,
0x100000000 - 1,
data.len() as u64,
&bpf_loader::id(),
true,
@ -2639,19 +2662,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::<UserError>(
vec![MemoryRegion {
host_addr: addr,
vm_addr: 96,
len: (data.len() * size_of::<u64>()) as u64,
vm_gap_shift: 63,
is_writable: false,
}],
vec![
MemoryRegion::default(),
MemoryRegion {
host_addr: addr,
vm_addr: 0x100000000,
len: (data.len() * size_of::<u64>()) as u64,
vm_gap_shift: 63,
is_writable: false,
},
],
&config,
)
.unwrap();
let translated_data = translate_slice::<u64>(
&memory_mapping,
96,
0x100000000,
data.len() as u64,
&bpf_loader::id(),
true,
@ -2660,28 +2686,35 @@ mod tests {
assert_eq!(data, translated_data);
data[0] = 10;
assert_eq!(data, translated_data);
assert!(
translate_slice::<u64>(&memory_mapping, 96, u64::MAX, &bpf_loader::id(), true,)
.is_err()
);
assert!(translate_slice::<u64>(
&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::<UserError>(
vec![MemoryRegion {
host_addr: addr,
vm_addr: 100,
len: (data.len() * std::mem::size_of::<Pubkey>()) 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::<Pubkey>()) as u64,
vm_gap_shift: 63,
is_writable: false,
},
],
&config,
)
.unwrap();
let translated_data = translate_slice::<Pubkey>(
&memory_mapping,
100,
0x100000000,
data.len() as u64,
&bpf_loader::id(),
true,
@ -2698,13 +2731,16 @@ mod tests {
let addr = string.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
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();
@ -2712,7 +2748,7 @@ mod tests {
42,
translate_string_and_do(
&memory_mapping,
100,
0x100000000,
string.len() as u64,
&bpf_loader::id(),
true,
@ -2752,13 +2788,16 @@ mod tests {
let addr = string.as_ptr() as *const _ as u64;
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
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();
@ -2774,7 +2813,7 @@ mod tests {
};
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_panic.call(
100,
0x100000000,
string.len() as u64,
42,
84,
@ -2800,7 +2839,7 @@ mod tests {
};
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_panic.call(
100,
0x100000000,
string.len() as u64,
42,
84,
@ -2829,20 +2868,23 @@ mod tests {
};
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
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<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log.call(
100,
0x100000000,
string.len() as u64,
0,
0,
@ -2856,7 +2898,7 @@ mod tests {
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log.call(
101, // AccessViolation
0x100000001, // AccessViolation
string.len() as u64,
0,
0,
@ -2864,10 +2906,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<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log.call(
100,
0x100000000,
string.len() as u64 * 2, // AccessViolation
0,
0,
@ -2875,10 +2917,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<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log.call(
100,
0x100000000,
string.len() as u64,
0,
0,
@ -2900,7 +2942,7 @@ mod tests {
};
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log.call(
100,
0x100000000,
string.len() as u64,
0,
0,
@ -2911,7 +2953,7 @@ mod tests {
result.unwrap();
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_log.call(
100,
0x100000000,
string.len() as u64,
0,
0,
@ -2971,19 +3013,22 @@ mod tests {
};
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
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<u64, EbpfError<BpfError>> = 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!(
@ -2992,7 +3037,7 @@ mod tests {
);
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_pubkey.call(
101, // AccessViolation
0x100000001, // AccessViolation
32,
0,
0,
@ -3000,7 +3045,7 @@ mod tests {
&memory_mapping,
&mut result,
);
assert_access_violation!(result, 101, 32);
assert_access_violation!(result, 0x100000001, 32);
let mut result: Result<u64, EbpfError<BpfError>> = Ok(0);
syscall_sol_pubkey.call(100, 32, 0, 0, 0, &memory_mapping, &mut result);
assert_eq!(
@ -3018,18 +3063,19 @@ mod tests {
{
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
let memory_mapping = MemoryMapping::new::<UserError>(
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<u64, EbpfError<BpfError>> = Ok(0);
syscall.call(100, 0, 0, 0, 0, &memory_mapping, &mut result);
@ -3045,18 +3091,19 @@ mod tests {
{
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
let memory_mapping = MemoryMapping::new::<UserError>(
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<u64, EbpfError<BpfError>> = Ok(0);
@ -3071,18 +3118,19 @@ mod tests {
{
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
let memory_mapping = MemoryMapping::new::<UserError>(
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<u64, EbpfError<BpfError>> = Ok(0);
@ -3099,18 +3147,19 @@ mod tests {
let heap = AlignedMemory::new_with_size(100, HOST_ALIGN);
let config = Config::default();
let memory_mapping = MemoryMapping::new::<UserError>(
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<u64, EbpfError<BpfError>> = Ok(0);
syscall.call(
@ -3144,38 +3193,25 @@ 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::<UserError>(
vec![
MemoryRegion {
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: bytes2.as_ptr() as *const _ as u64,
vm_addr: 8192,
len: bytes2.len() as u64,
vm_gap_shift: 63,
is_writable: false,
},
MemoryRegion::default(),
MemoryRegion {
host_addr: bytes_to_hash.as_ptr() as *const _ as u64,
vm_addr: 96,
vm_addr: ro_va,
len: 32,
vm_gap_shift: 63,
is_writable: false,
@ -3187,6 +3223,20 @@ mod tests {
vm_gap_shift: 63,
is_writable: true,
},
MemoryRegion {
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: 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: false,
},
],
&config,
)
@ -3219,7 +3269,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<u64, EbpfError<BpfError>> = Ok(0);
syscall.call(
ro_va,
@ -3230,7 +3280,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<u64, EbpfError<BpfError>> = Ok(0);
syscall.call(
ro_va,
@ -3258,16 +3308,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::<UserError>(
vec![MemoryRegion {
host_addr: &got_clock as *const _ as u64,
vm_addr: got_clock_va,
len: size_of::<Clock>() 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::<Clock>() as u64,
vm_gap_shift: 63,
is_writable: true,
},
],
&config,
)
.unwrap();
@ -3300,16 +3353,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::<UserError>(
vec![MemoryRegion {
host_addr: &got_epochschedule as *const _ as u64,
vm_addr: got_epochschedule_va,
len: size_of::<EpochSchedule>() 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::<EpochSchedule>() as u64,
vm_gap_shift: 63,
is_writable: true,
},
],
&config,
)
.unwrap();
@ -3351,16 +3407,19 @@ mod tests {
#[allow(deprecated)]
{
let got_fees = Fees::default();
let got_fees_va = 2048;
let got_fees_va = 0x100000000;
let memory_mapping = MemoryMapping::new::<UserError>(
vec![MemoryRegion {
host_addr: &got_fees as *const _ as u64,
vm_addr: got_fees_va,
len: size_of::<Fees>() 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::<Fees>() as u64,
vm_gap_shift: 63,
is_writable: true,
},
],
&config,
)
.unwrap();
@ -3391,16 +3450,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::<UserError>(
vec![MemoryRegion {
host_addr: &got_rent as *const _ as u64,
vm_addr: got_rent_va,
len: size_of::<Rent>() 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::<Rent>() as u64,
vm_gap_shift: 63,
is_writable: true,
},
],
&config,
)
.unwrap();

View File

@ -15,5 +15,5 @@ serde_json = "1.0.66"
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.3.0"

View File

@ -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());

View File

@ -175,6 +175,10 @@ pub mod spl_token_v2_set_authority_fix {
solana_sdk::declare_id!("FToKNBYyiF4ky9s8WsmLBXHCht17Ek7RXaLZGHzzQhJ1");
}
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");
}
@ -221,6 +225,7 @@ lazy_static! {
(libsecp256k1_0_5_upgrade_enabled::id(), "upgrade libsecp256k1 to v0.5.0"),
(tx_wide_compute_cap::id(), "Transaction wide compute cap"),
(spl_token_v2_set_authority_fix::id(), "spl-token set_authority fix"),
(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"),
(disable_fees_sysvar::id(), "disable fees sysvar"),
/*************** ADD NEW FEATURES HERE ***************/