diff --git a/programs/bpf_loader/src/syscalls/logging.rs b/programs/bpf_loader/src/syscalls/logging.rs index 8351a7ee64..b741f49a94 100644 --- a/programs/bpf_loader/src/syscalls/logging.rs +++ b/programs/bpf_loader/src/syscalls/logging.rs @@ -24,6 +24,9 @@ declare_syscall!( len, invoke_context.get_check_aligned(), invoke_context.get_check_size(), + invoke_context + .feature_set + .is_active(&stop_truncating_strings_in_syscalls::id()), &mut |string: &str| { stable_log::program_log(&invoke_context.get_log_collector(), string); Ok(0) diff --git a/programs/bpf_loader/src/syscalls/mod.rs b/programs/bpf_loader/src/syscalls/mod.rs index bdeef057c3..7cc6b162a3 100644 --- a/programs/bpf_loader/src/syscalls/mod.rs +++ b/programs/bpf_loader/src/syscalls/mod.rs @@ -40,7 +40,8 @@ use { enable_early_verification_of_account_modifications, error_on_syscall_bpf_function_hash_collisions, libsecp256k1_0_5_upgrade_enabled, limit_secp256k1_recovery_id, reject_callx_r10, - stop_sibling_instruction_search_at_parent, switch_to_new_elf_parser, + stop_sibling_instruction_search_at_parent, stop_truncating_strings_in_syscalls, + switch_to_new_elf_parser, }, hash::{Hasher, HASH_BYTES}, instruction::{ @@ -428,14 +429,19 @@ fn translate_string_and_do( len: u64, check_aligned: bool, check_size: bool, + stop_truncating_strings_in_syscalls: bool, work: &mut dyn FnMut(&str) -> Result, ) -> Result { let buf = translate_slice::(memory_mapping, addr, len, check_aligned, check_size)?; - let i = match buf.iter().position(|byte| *byte == 0) { - Some(i) => i, - None => len as usize, + let msg = if stop_truncating_strings_in_syscalls { + buf + } else { + let i = match buf.iter().position(|byte| *byte == 0) { + Some(i) => i, + None => len as usize, + }; + buf.get(..i).ok_or(SyscallError::InvalidLength)? }; - let msg = buf.get(..i).ok_or(SyscallError::InvalidLength)?; match from_utf8(msg) { Ok(message) => work(message), Err(err) => Err(SyscallError::InvalidString(err, msg.to_vec()).into()), @@ -508,6 +514,9 @@ declare_syscall!( len, invoke_context.get_check_aligned(), invoke_context.get_check_size(), + invoke_context + .feature_set + .is_active(&stop_truncating_strings_in_syscalls::id()), &mut |string: &str| Err(SyscallError::Panic(string.to_string(), line, column).into()), ) } @@ -2046,6 +2055,7 @@ mod tests { string.len() as u64, true, true, + true, &mut |string: &str| { assert_eq!(string, "Gaggablaghblagh!"); Ok(42) diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index 3fb86fd2f7..5437320dc1 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -641,10 +641,15 @@ pub mod include_loaded_accounts_data_size_in_fee_calculation { pub mod native_programs_consume_cu { solana_sdk::declare_id!("8pgXCMNXC8qyEFypuwpXyRxLXZdpM4Qo72gJ6k87A6wL"); } + pub mod simplify_writable_program_account_check { solana_sdk::declare_id!("5ZCcFAzJ1zsFKe1KSZa9K92jhx7gkcKj97ci2DBo1vwj"); } +pub mod stop_truncating_strings_in_syscalls { + solana_sdk::declare_id!("16FMCmgLzCNNz6eTwGanbyN2ZxvTBSLuQ6DZhgeMshg"); +} + lazy_static! { /// Map of feature identifiers to user-visible description pub static ref FEATURE_NAMES: HashMap = [ @@ -801,6 +806,7 @@ lazy_static! { (include_loaded_accounts_data_size_in_fee_calculation::id(), "include transaction loaded accounts data size in base fee calculation #30657"), (native_programs_consume_cu::id(), "Native program should consume compute units #30620"), (simplify_writable_program_account_check::id(), "Simplify checks performed for writable upgradeable program accounts #30559"), + (stop_truncating_strings_in_syscalls::id(), "Stop truncating strings in syscalls #31029"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter()