Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-validator: Verify program ELFs #4192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

acheroncrypto
Copy link

Problem

solana-test-validator doesn't check whether program ELFs are valid before appending their data to the program data accounts:

let data = solana_program_test::read_file(&upgradeable_program.program_path);
let (programdata_address, _) = Pubkey::find_program_address(
&[upgradeable_program.program_id.as_ref()],
&upgradeable_program.loader,
);
let mut program_data = bincode::serialize(&UpgradeableLoaderState::ProgramData {
slot: 0,
upgrade_authority_address: Some(upgradeable_program.upgrade_authority),
})
.unwrap();
program_data.extend_from_slice(&data);

Summary of changes

Verify program ELFs before adding program data accounts to the genesis configuration.

With this change, the behavior with an invalid program ELF is the same as the solana program deploy command. An example output of trying to load an invalid ELF (with mutable static data):

Error: failed to start validator: ELF error: ELF error: Failed to parse ELF file: Section or symbol name `.bss._ZN6native7` is longer than `16` bytes

Fixes #4191

@mergify mergify bot requested a review from a team December 20, 2024 21:07
@acheroncrypto acheroncrypto marked this pull request as ready for review December 20, 2024 21:40
Comment on lines +796 to +799
let mut feature_set = FeatureSet::all_enabled();
for feature in &config.deactivate_feature_set {
feature_set.deactivate(feature);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates a similar logic below:

// Only activate features which are not explicitly deactivated.
let mut feature_set = FeatureSet::default().inactive;
for feature in &config.deactivate_feature_set {
if feature_set.remove(feature) {
info!("Feature for {:?} deactivated", feature)
} else {
warn!(
"Feature {:?} set for deactivation is not a known Feature public key",
feature,
)
}
}

I wanted to avoid making changes to the existing code to make it easier to review. Would it be better to refactor this to avoid duplicating the logic, or should I keep it as is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test-validator: Invalid program ELFs fail silently
1 participant