From efd77f321acbaf55bfeb8a2959dfef304ff3caf6 Mon Sep 17 00:00:00 2001 From: Sean Young Date: Tue, 5 Dec 2023 14:25:41 +0000 Subject: [PATCH] do not serialize executable accounts --- programs/bpf_loader/src/serialization.rs | 25 ++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/programs/bpf_loader/src/serialization.rs b/programs/bpf_loader/src/serialization.rs index f9cbc2e752c54d..af1360d1d4febe 100644 --- a/programs/bpf_loader/src/serialization.rs +++ b/programs/bpf_loader/src/serialization.rs @@ -335,8 +335,13 @@ fn serialize_parameters_unaligned( s.write::(account.is_writable() as u8); let vm_key_addr = s.write_all(account.get_key().as_ref()); let vm_lamports_addr = s.write::(account.get_lamports().to_le()); - s.write::((account.get_data().len() as u64).to_le()); - let vm_data_addr = s.write_account(&mut account)?; + let vm_data_addr = if account.is_executable() { + s.write::(0u64.to_le()); + 0 + } else { + s.write::((account.get_data().len() as u64).to_le()); + s.write_account(&mut account)? + }; let vm_owner_addr = s.write_all(account.get_owner().as_ref()); s.write::(account.is_executable() as u8); s.write::((account.get_rent_epoch()).to_le()); @@ -389,7 +394,7 @@ pub fn deserialize_parameters_unaligned>( } start += size_of::() // lamports + size_of::(); // data length - if copy_account_data { + if copy_account_data && !borrowed_account.is_executable() { let data = buffer .get(start..start + pre_len) .ok_or(InstructionError::InvalidArgument)?; @@ -471,8 +476,13 @@ fn serialize_parameters_aligned( let vm_key_addr = s.write_all(borrowed_account.get_key().as_ref()); let vm_owner_addr = s.write_all(borrowed_account.get_owner().as_ref()); let vm_lamports_addr = s.write::(borrowed_account.get_lamports().to_le()); - s.write::((borrowed_account.get_data().len() as u64).to_le()); - let vm_data_addr = s.write_account(&mut borrowed_account)?; + let vm_data_addr = if borrowed_account.is_executable() { + s.write::(0u64.to_le()); + 0 + } else { + s.write::((borrowed_account.get_data().len() as u64).to_le()); + s.write_account(&mut borrowed_account)? + }; s.write::((borrowed_account.get_rent_epoch()).to_le()); accounts_metadata.push(SerializedAccountMetadata { original_data_len: borrowed_account.get_data().len(), @@ -535,11 +545,14 @@ pub fn deserialize_parameters_aligned>( borrowed_account.set_lamports(lamports)?; } start += size_of::(); // lamports - let post_len = LittleEndian::read_u64( + let mut post_len = LittleEndian::read_u64( buffer .get(start..) .ok_or(InstructionError::InvalidArgument)?, ) as usize; + if borrowed_account.is_executable() { + post_len = pre_len; + } start += size_of::(); // data length if post_len.saturating_sub(pre_len) > MAX_PERMITTED_DATA_INCREASE || post_len > MAX_PERMITTED_DATA_LENGTH as usize