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: Invalid program ELFs fail silently #4191

Open
acheroncrypto opened this issue Dec 20, 2024 · 0 comments · May be fixed by #4192
Open

test-validator: Invalid program ELFs fail silently #4191

acheroncrypto opened this issue Dec 20, 2024 · 0 comments · May be fixed by #4192

Comments

@acheroncrypto
Copy link

Problem

solana-test-validator doesn't verify program ELFs when creating its genesis configuration.

For example, if an ELf contains a restricted functionality, e.g. mutable static data (as mentioned in coral-xyz/anchor#3403), the validator starts without any indication of an error.

Reproduction

Program lib.rs:

use solana_program::{
    account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, pubkey::Pubkey,
};

entrypoint!(process);

static INVALID: std::sync::OnceLock<bool> = std::sync::OnceLock::new();

pub fn process(_program_id: &Pubkey, _accounts: &[AccountInfo], _data: &[u8]) -> ProgramResult {
    INVALID.get_or_init(|| false);
    Ok(())
}

Run:

cargo build-sbf
solana-test-validator --bpf-program invaLidELF111111111111111111111111111111111 target/deploy/program.so

Details

Instead of getting an error during the start of the test-validator, loading an invalid program ELF results in a seemingly unrelated error during runtime when trying to invoke the program:

ic_logger_msg!(log_collector, "Program is not deployed");
let instruction_error = if invoke_context
.get_feature_set()
.is_active(&remove_accounts_executable_flag_checks::id())
{
InstructionError::UnsupportedProgramId
} else {
InstructionError::InvalidAccountData
};
Err(Box::new(instruction_error) as Box<dyn std::error::Error>)

Example transaction logs:

Program invaLidELF111111111111111111111111111111111 invoke [1]
Program is not deployed
Program invaLidELF111111111111111111111111111111111 failed: Unsupported program id

This behavior differs from solana program deploy, which verifies the ELFs before deploying them. Trying to deploy an invalid ELF fails with EbpfError::ElfError and outputs something similar to the following:

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

Solution

Verify program ELFs before adding them to the genesis configuration.

@acheroncrypto acheroncrypto linked a pull request Dec 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant