Skip to content

Commit

Permalink
Cleanup - Feature gate of check_slice_translation_size (solana-labs…
Browse files Browse the repository at this point in the history
…#34084)

Cleans up feature gate of check_slice_translation_size.
  • Loading branch information
Lichtso authored Nov 15, 2023
1 parent d58db6e commit b168cad
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 114 deletions.
8 changes: 1 addition & 7 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use {
solana_sdk::{
account::AccountSharedData,
bpf_loader_deprecated,
feature_set::{check_slice_translation_size, native_programs_consume_cu, FeatureSet},
feature_set::{native_programs_consume_cu, FeatureSet},
hash::Hash,
instruction::{AccountMeta, InstructionError},
native_loader,
Expand Down Expand Up @@ -599,12 +599,6 @@ impl<'a> InvokeContext<'a> {
.unwrap_or(true)
}

// Set should type size be checked during user pointer translation
pub fn get_check_size(&self) -> bool {
self.feature_set
.is_active(&check_slice_translation_size::id())
}

// Set this instruction syscall context
pub fn set_syscall_context(
&mut self,
Expand Down
32 changes: 3 additions & 29 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ impl<'a, 'b> CallerAccount<'a, 'b> {
vm_data_addr,
data.len() as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
};
(
Expand Down Expand Up @@ -344,7 +343,6 @@ impl<'a, 'b> CallerAccount<'a, 'b> {
account_info.data_addr,
account_info.data_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
};

Expand Down Expand Up @@ -498,7 +496,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
ix.accounts.as_ptr() as u64,
ix.accounts.len() as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
let accounts = if invoke_context
.feature_set
Expand Down Expand Up @@ -542,7 +539,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
ix.data.as_ptr() as u64,
ix_data_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
.to_vec();

Expand Down Expand Up @@ -597,7 +593,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
signers_seeds_addr,
signers_seeds_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
if signers_seeds.len() > MAX_SIGNERS {
return Err(Box::new(SyscallError::TooManySigners));
Expand All @@ -608,7 +603,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
signer_seeds.as_ptr() as *const _ as u64,
signer_seeds.len() as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
if untranslated_seeds.len() > MAX_SEEDS {
return Err(Box::new(InstructionError::MaxSeedLengthExceeded));
Expand All @@ -621,7 +615,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedRust {
untranslated_seed.as_ptr() as *const _ as u64,
untranslated_seed.len() as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)
})
.collect::<Result<Vec<_>, Error>>()?;
Expand Down Expand Up @@ -740,7 +733,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
ix_c.accounts_addr,
ix_c.accounts_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;

let ix_data_len = ix_c.data_len;
Expand All @@ -761,7 +753,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
ix_c.data_addr,
ix_data_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
.to_vec();

Expand Down Expand Up @@ -862,7 +853,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
signers_seeds_addr,
signers_seeds_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
if signers_seeds.len() > MAX_SIGNERS {
return Err(Box::new(SyscallError::TooManySigners));
Expand All @@ -875,7 +865,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
signer_seeds.addr,
signer_seeds.len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
if seeds.len() > MAX_SEEDS {
return Err(Box::new(InstructionError::MaxSeedLengthExceeded) as Error);
Expand All @@ -888,7 +877,6 @@ impl SyscallInvokeSigned for SyscallInvokeSignedC {
seed.addr,
seed.len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)
})
.collect::<Result<Vec<_>, Error>>()?;
Expand Down Expand Up @@ -917,7 +905,6 @@ where
account_infos_addr,
account_infos_len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
check_account_infos(account_infos.len(), invoke_context)?;
let account_info_keys = if invoke_context
Expand Down Expand Up @@ -1336,7 +1323,6 @@ fn update_callee_account(
.saturating_add(caller_account.original_data_len as u64),
realloc_bytes_used as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
callee_account
.get_data_mut()?
Expand Down Expand Up @@ -1581,7 +1567,6 @@ fn update_caller_account(
.saturating_add(dirty_realloc_start as u64),
dirty_realloc_len as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
serialized_data.fill(0);
}
Expand All @@ -1602,7 +1587,6 @@ fn update_caller_account(
caller_account.vm_data_addr,
post_len as u64,
false, // Don't care since it is byte aligned
invoke_context.get_check_size(),
)?;
}
// this is the len field in the AccountInfo::data slice
Expand Down Expand Up @@ -1666,7 +1650,6 @@ fn update_caller_account(
.saturating_add(caller_account.original_data_len as u64),
realloc_bytes_used as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
};
let from_slice = callee_account
Expand Down Expand Up @@ -2182,15 +2165,9 @@ mod tests {

// check that the caller account data pointer always matches the callee account data pointer
assert_eq!(
translate_slice::<u8>(
&memory_mapping,
caller_account.vm_data_addr,
1,
true,
true
)
.unwrap()
.as_ptr(),
translate_slice::<u8>(&memory_mapping, caller_account.vm_data_addr, 1, true,)
.unwrap()
.as_ptr(),
callee_account.get_data().as_ptr()
);

Expand All @@ -2210,7 +2187,6 @@ mod tests {
.saturating_add(caller_account.original_data_len as u64),
MAX_PERMITTED_DATA_INCREASE as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)
.unwrap();

Expand Down Expand Up @@ -2360,7 +2336,6 @@ mod tests {
caller_account.vm_data_addr,
callee_account.get_data().len() as u64,
true,
true,
)
.unwrap();
assert_eq!(data, callee_account.get_data());
Expand Down Expand Up @@ -2632,7 +2607,6 @@ mod tests {
.saturating_add(caller_account.original_data_len as u64),
3,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)
.unwrap();
serialized_data.copy_from_slice(b"baz");
Expand Down
3 changes: 0 additions & 3 deletions programs/bpf_loader/src/syscalls/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ declare_builtin_function!(
addr,
len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
invoke_context
.feature_set
.is_active(&stop_truncating_strings_in_syscalls::id()),
Expand Down Expand Up @@ -129,7 +128,6 @@ declare_builtin_function!(
addr,
len,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;

consume_compute_meter(
Expand All @@ -153,7 +151,6 @@ declare_builtin_function!(
untranslated_field.as_ptr() as *const _ as u64,
untranslated_field.len() as u64,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?);
}

Expand Down
5 changes: 0 additions & 5 deletions programs/bpf_loader/src/syscalls/mem_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ declare_builtin_function!(
s1_addr,
n,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
let s2 = translate_slice::<u8>(
memory_mapping,
s2_addr,
n,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
let cmp_result = translate_type_mut::<i32>(
memory_mapping,
Expand Down Expand Up @@ -137,7 +135,6 @@ declare_builtin_function!(
dst_addr,
n,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?;
s.fill(c as u8);
Ok(0)
Expand All @@ -163,15 +160,13 @@ fn memmove(
dst_addr,
n,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
.as_mut_ptr();
let src_ptr = translate_slice::<u8>(
memory_mapping,
src_addr,
n,
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
.as_ptr();

Expand Down
Loading

0 comments on commit b168cad

Please sign in to comment.